Package org.microproxy.otel
Class Telemetry
java.lang.Object
org.microproxy.otel.Telemetry
- All Implemented Interfaces:
AutoCloseable,FlowTracer
OpenTelemetry for the proxy, with nothing but the JDK: context propagation (W3C Trace Context,
and B3 and Jaeger when configured), an
X-Request-Id per request, a SERVER span per
exchange (HTTP/1, HTTP/2 and HTTP/3) with a CLIENT span per attempt to reach the server, an
INTERNAL span per tunnel or flow (CONNECT, SOCKS, WebSocket, CONNECT-UDP, QUIC), and the
export over OTLP/HTTP, as protobuf or JSON, of those spans, of the proxy's stats as metrics, and of its access-log records as log records.
Telemetry otel = Telemetry.fromEnvironment() // OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME, ...
.serviceName("edge")
.sampler(Sampler.parentBased(Sampler.traceIdRatio(0.1)))
.build();
HttpProxyServer proxy = otel.install(MicroProxy.bootstrap().withPort(8080)).start();
Disabled (OTEL_SDK_DISABLED=true, enabled(false)),
install(org.microproxy.HttpProxyServerBootstrap) leaves the proxy untouched, so it does no work at all. Enabled, a request whose
trace is not sampled costs its ids and the headers written upstream; only sampled exchanges
allocate spans. Spans and log records wait in bounded queues and are exported in batches by a
virtual thread per signal; when a queue is full they are dropped and counted (
otel.spans_dropped, otel.logs_dropped), never waited for.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigures aTelemetry; every setting has OpenTelemetry's default.static enumHow OTLP is sent:http/protobuforhttp/json.static enumWhat happens to a request'sX-Request-Id.static enumWhat goes upstream when the proxy strips tracing headers (HttpProxyServerBootstrap.withoutTracingHeadersUpstream()). -
Field Summary
Fields inherited from interface org.microproxy.FlowTracer
NOOP -
Method Summary
Modifier and TypeMethodDescriptionReturns the access-log exporter, whichinstall(org.microproxy.HttpProxyServerBootstrap)adds as a tracker;nullwithout log export.static Telemetry.Builderbuilder()Returns a builder with the defaults: everything exported tohttp://localhost:4318.voidclose()Exports what is left, then stops the exporters; the proxy calls it once it has stopped.Returns what this telemetry exports, and where.voidflowEnded(FlowRecord record) Called once per finished exchange or flow, with the recordActivityTracker.flowEnded(org.microproxy.FlowRecord)gets:FlowRecord.trace()is the traceFlowTracer.startExchange(org.microproxy.FlowContext, org.microproxy.http.HttpRequest)made, orFlowTrace.NONEfor a flow that had no request of its own (a relayed transparent QUIC flow, a request a transport answered itself).booleanExports what is queued now (spans, log records) and the metrics, waiting up totimeoutfor each.static Telemetry.BuilderA builder configured from the process's environment (OTEL_*variables, seefromEnvironment(Map)).static Telemetry.BuilderfromEnvironment(Map<String, String> env) A builder configured fromenv, OpenTelemetry's environment variables:OTEL_SDK_DISABLED,OTEL_SERVICE_NAME,OTEL_RESOURCE_ATTRIBUTES,OTEL_EXPORTER_OTLP_ENDPOINTandOTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_ENDPOINT,OTEL_EXPORTER_OTLP_PROTOCOL,OTEL_EXPORTER_OTLP_HEADERS,OTEL_EXPORTER_OTLP_COMPRESSION,OTEL_EXPORTER_OTLP_TIMEOUT,OTEL_{TRACES,METRICS,LOGS}_EXPORTER(otlpornone),OTEL_TRACES_SAMPLERandOTEL_TRACES_SAMPLER_ARG,OTEL_PROPAGATORS,OTEL_METRIC_EXPORT_INTERVAL,OTEL_BSP_*andOTEL_BLRP_*(SCHEDULE_DELAY,MAX_QUEUE_SIZE,MAX_EXPORT_BATCH_SIZE), and the span limits (OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,OTEL_SPAN_EVENT_COUNT_LIMIT,OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT).install(HttpProxyServerBootstrap bootstrap) Wires this telemetry intobootstrap: its tracer (HttpProxyServerBootstrap.withTracer(org.microproxy.FlowTracer)), metrics turned on when they are exported, and the access-log exporter as anActivityTrackerwhen logs are.booleanReturns whether this telemetry does anything:falseonce the SDK is disabled.voidproxyStarted(HttpProxyServer server) Called once a proxy that uses this tracer has started, for instance to read itsstats.startExchange(FlowContext flow, HttpRequest request) Called when a request head arrives from the client, before trackers, authentication and filters see it, so that headers the tracer adds (anX-Request-Id) are seen by all of them and the access log.toString()
-
Method Details
-
builder
Returns a builder with the defaults: everything exported tohttp://localhost:4318.- Returns:
- a builder with the defaults: everything exported to
http://localhost:4318
-
fromEnvironment
A builder configured from the process's environment (OTEL_*variables, seefromEnvironment(Map)).- Returns:
- the builder
- Throws:
IllegalArgumentException- if a variable has a bad value
-
fromEnvironment
A builder configured fromenv, OpenTelemetry's environment variables:OTEL_SDK_DISABLED,OTEL_SERVICE_NAME,OTEL_RESOURCE_ATTRIBUTES,OTEL_EXPORTER_OTLP_ENDPOINTandOTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_ENDPOINT,OTEL_EXPORTER_OTLP_PROTOCOL,OTEL_EXPORTER_OTLP_HEADERS,OTEL_EXPORTER_OTLP_COMPRESSION,OTEL_EXPORTER_OTLP_TIMEOUT,OTEL_{TRACES,METRICS,LOGS}_EXPORTER(otlpornone),OTEL_TRACES_SAMPLERandOTEL_TRACES_SAMPLER_ARG,OTEL_PROPAGATORS,OTEL_METRIC_EXPORT_INTERVAL,OTEL_BSP_*andOTEL_BLRP_*(SCHEDULE_DELAY,MAX_QUEUE_SIZE,MAX_EXPORT_BATCH_SIZE), and the span limits (OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,OTEL_SPAN_EVENT_COUNT_LIMIT,OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT).- Parameters:
env- the environment- Returns:
- the builder
- Throws:
IllegalArgumentException- if a variable has a bad value
-
isEnabled
public boolean isEnabled()Returns whether this telemetry does anything:falseonce the SDK is disabled.- Returns:
- whether this telemetry does anything:
falseonce the SDK is disabled
-
install
Wires this telemetry intobootstrap: its tracer (HttpProxyServerBootstrap.withTracer(org.microproxy.FlowTracer)), metrics turned on when they are exported, and the access-log exporter as anActivityTrackerwhen logs are. Disabled, it changes nothing.- Parameters:
bootstrap- the proxy's configuration- Returns:
bootstrap
-
accessLogExporter
Returns the access-log exporter, whichinstall(org.microproxy.HttpProxyServerBootstrap)adds as a tracker;nullwithout log export.- Returns:
- the access-log exporter, which
install(org.microproxy.HttpProxyServerBootstrap)adds as a tracker;nullwithout log export
-
startExchange
Description copied from interface:FlowTracerCalled when a request head arrives from the client, before trackers, authentication and filters see it, so that headers the tracer adds (anX-Request-Id) are seen by all of them and the access log. The request may also be aCONNECT(real, or made up for a SOCKS client or a transparent connection), which opens a tunnel or a flow.- Specified by:
startExchangein interfaceFlowTracer- Parameters:
flow- the exchange's contextrequest- the request head, which may be changed in place- Returns:
- the exchange's trace, or
FlowTrace.NONEto trace nothing
-
flowEnded
Description copied from interface:FlowTracerCalled once per finished exchange or flow, with the recordActivityTracker.flowEnded(org.microproxy.FlowRecord)gets:FlowRecord.trace()is the traceFlowTracer.startExchange(org.microproxy.FlowContext, org.microproxy.http.HttpRequest)made, orFlowTrace.NONEfor a flow that had no request of its own (a relayed transparent QUIC flow, a request a transport answered itself).- Specified by:
flowEndedin interfaceFlowTracer- Parameters:
record- the finished exchange or flow
-
proxyStarted
Description copied from interface:FlowTracerCalled once a proxy that uses this tracer has started, for instance to read itsstats.- Specified by:
proxyStartedin interfaceFlowTracer- Parameters:
server- the running proxy
-
flush
Exports what is queued now (spans, log records) and the metrics, waiting up totimeoutfor each.- Parameters:
timeout- how long to wait for each signal- Returns:
- whether everything was sent in time
-
close
public void close()Exports what is left, then stops the exporters; the proxy calls it once it has stopped.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFlowTracer
-
toString
-
description
Returns what this telemetry exports, and where.- Returns:
- what this telemetry exports, and where
-