Interface FlowTrace
FlowTracer when the request head
arrives: its trace and span ids, which FlowContext.trace(), access logs (
%TRACE_ID%, %SPAN_ID%) and scripts (ctx.trace_id) show, and the calls through
which the proxy reports each attempt to reach the server and asks for the headers that carry the
trace to it.
The proxy calls the attempt methods on the exchange's thread, in this order for each attempt:
attemptStarted(java.lang.String, org.microproxy.ChainedProxy, boolean) when it begins to connect to the server or a chained proxy (or to send
the request on a connection at hand), upstreamRequest(boolean, org.microproxy.http.HttpVersion) once the exchange's request is
about to go on the connection, injectUpstream(org.microproxy.http.HttpHeaders, boolean) right before a request head (the
exchange's, or a CONNECT to a chained proxy) is written, and attemptEnded(int, java.lang.String). A
failed connection to one chained proxy, the next one tried, and a request sent again after a
stale keep-alive connection are attempts of their own. Every method has a no-op default; NONE is the trace of an exchange nobody traces.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA spanstartSpan(java.lang.String)started, used by one thread at a time. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault voidAdds an event, at the current time, to the exchange's span; ignored when it is not sampled.default voidattemptEnded(int status, String errorType) The current attempt is over.default voidattemptStarted(String hostAndPort, ChainedProxy chainedProxy, boolean tls) An attempt to reach the server begins: a connection to it or to a chained proxy, or a request on a connection at hand.default voidinjectUpstream(HttpHeaders headers, boolean tracingHeadersStripped) A request head is about to be written upstream for the current attempt, after the proxy removed the headers it strips (HttpProxyServerBootstrap.withStrippedRequestHeaders(java.lang.String...)): the trace may put its propagation headers on it.default booleanReturns whether the trace is sampled: its spans are recorded and exported.default StringThe exchange's request id (X-Request-Id), which access logs show as%UNIQUE_ID%too, ornullto leaveFlowRecord.uniqueId()random.default voidsetAttribute(String key, Object value) Adds an attribute to the exchange's span; ignored when it is not sampled.default StringspanId()Returns the id of the proxy's span for the exchange, 16 lower-case hex digits, ornull.default FlowTrace.SpanStarts a span of the proxy's own work for the exchange, such as a script's hook call: an INTERNAL span, a child of the exchange's span (of the tunnel's or flow's, for the hooks of a tunnel or a flow), which ends whenFlowTrace.Span.end(java.lang.String)is called.default StringtraceId()Returns the trace id, 32 lower-case hex digits, ornullfor no trace.default voidupstreamRequest(boolean tls, HttpVersion version) The exchange's request is about to go to the server on the current attempt's connection, as that connection really is.
-
Field Details
-
NONE
No trace: ids arenulland every call does nothing.
-
-
Method Details
-
traceId
Returns the trace id, 32 lower-case hex digits, ornullfor no trace.- Returns:
- the trace id, 32 lower-case hex digits, or
nullfor no trace
-
spanId
Returns the id of the proxy's span for the exchange, 16 lower-case hex digits, ornull.- Returns:
- the id of the proxy's span for the exchange, 16 lower-case hex digits, or
null
-
isSampled
default boolean isSampled()Returns whether the trace is sampled: its spans are recorded and exported.- Returns:
- whether the trace is sampled: its spans are recorded and exported
-
requestId
The exchange's request id (X-Request-Id), which access logs show as%UNIQUE_ID%too, ornullto leaveFlowRecord.uniqueId()random.- Returns:
- the request id, or
null
-
setAttribute
Adds an attribute to the exchange's span; ignored when it is not sampled.- Parameters:
key- the attribute's namevalue- aString,Boolean, integer, floating-point number, or a list of those; other values are recorded as theirtoString()
-
addEvent
Adds an event, at the current time, to the exchange's span; ignored when it is not sampled.- Parameters:
name- the event's nameattributes- the event's attributes (values as forsetAttribute(java.lang.String, java.lang.Object)), possibly empty
-
startSpan
Starts a span of the proxy's own work for the exchange, such as a script's hook call: an INTERNAL span, a child of the exchange's span (of the tunnel's or flow's, for the hooks of a tunnel or a flow), which ends whenFlowTrace.Span.end(java.lang.String)is called. A trace that is not sampled returnsFlowTrace.Span.NONE, so callers that only start spans whenisSampled()pay nothing otherwise.- Parameters:
name- the span's name, such asstarlark on_request- Returns:
- the span, or
FlowTrace.Span.NONE
-
attemptStarted
An attempt to reach the server begins: a connection to it or to a chained proxy, or a request on a connection at hand.- Parameters:
hostAndPort- the server'shost:portchainedProxy- the chained proxy the attempt goes through, ornullfor a direct connectiontls- whether the proxy speaks TLS to the server itself (to anhttpsorigin, an intercepted session's server or a reverse proxy'shttps://upstream), whatever the connection to a chained proxy is
-
upstreamRequest
The exchange's request is about to go to the server on the current attempt's connection, as that connection really is.- Parameters:
tls- whether the proxy speaks TLS to the server on it (HTTP/2 and HTTP/3 always do)version- the protocol of the connection:HttpVersion.HTTP_1_1,HttpVersion.HTTP_2_0(a stream of a shared HTTP/2 connection) orHttpVersion.HTTP_3_0
-
injectUpstream
A request head is about to be written upstream for the current attempt, after the proxy removed the headers it strips (HttpProxyServerBootstrap.withStrippedRequestHeaders(java.lang.String...)): the trace may put its propagation headers on it.- Parameters:
headers- the request's headers, to change in placetracingHeadersStripped- whether the proxy strips the tracing headers (traceparentamong them) from requests sent upstream
-
attemptEnded
The current attempt is over.- Parameters:
status- the status of the server's response, or 0 when none cameerrorType- why the attempt failed, as a short low-cardinality name (connect_failed,server_timeout,stale_connection, ...), ornullwhen it did not
-