OpenTelemetry traces, metrics and logs; trace IDs in logs #38

Merged
mikluko merged 1 commit from feat/otel into main 2026-10-26 21:29:34 +00:00
Owner

Wires the OpenTelemetry SDK the way flakybin does: autoexport for traces, metrics and logs, the otelslog bridge, runtime metrics, and W3C propagation. Everything follows the standard OTEL_* variables, so by default it exports over OTLP to localhost. OTEL_SDK_DISABLED=true installs nothing.

Export errors are logged locally only, at warn when an OTEL_EXPORTER_OTLP_*ENDPOINT is set and at debug otherwise. A smoke run of the binary with no environment and no collector prints only its start and stop lines; with a dead explicit endpoint it warns.

Proxied requests and MITM-intercepted requests are server spans. Upstream requests are client spans: the upstream sees the proxy's span in traceparent, continuing the client's trace. Local log records carry trace_id and span_id through log.TraceHandler. SIGINT and SIGTERM stop the command and flush telemetry.

An end-to-end test runs against a fake OTLP/HTTP collector. It checks that all three signals arrive, that the access log carries the client's trace ID, and that the upstream sees the proxy's span. Other command tests run with OTEL_SDK_DISABLED=true.

The Go OTLP exporters default to https://localhost:4318, where the spec says http://. That is the SDK's behaviour, untouched here.

Wires the OpenTelemetry SDK the way flakybin does: autoexport for traces, metrics and logs, the otelslog bridge, runtime metrics, and W3C propagation. Everything follows the standard `OTEL_*` variables, so by default it exports over OTLP to localhost. `OTEL_SDK_DISABLED=true` installs nothing. Export errors are logged locally only, at warn when an `OTEL_EXPORTER_OTLP_*ENDPOINT` is set and at debug otherwise. A smoke run of the binary with no environment and no collector prints only its start and stop lines; with a dead explicit endpoint it warns. Proxied requests and MITM-intercepted requests are server spans. Upstream requests are client spans: the upstream sees the proxy's span in `traceparent`, continuing the client's trace. Local log records carry `trace_id` and `span_id` through `log.TraceHandler`. SIGINT and SIGTERM stop the command and flush telemetry. An end-to-end test runs against a fake OTLP/HTTP collector. It checks that all three signals arrive, that the access log carries the client's trace ID, and that the upstream sees the proxy's span. Other command tests run with `OTEL_SDK_DISABLED=true`. The Go OTLP exporters default to `https://localhost:4318`, where the spec says `http://`. That is the SDK's behaviour, untouched here.
OpenTelemetry traces, metrics and logs; trace IDs in logs
All checks were successful
CI / changelog (pull_request) Successful in 7s
CI / test (pull_request) Successful in 2m34s
5d8cd4863c
The SDK follows the standard OTEL_* variables, exporting over OTLP to
localhost by default, as flakybin does. Export errors log at warn where an
OTLP endpoint is set and at debug otherwise, so a default run without a
collector stays quiet. Proxied and MITM-intercepted requests are server
spans; upstream requests are client spans. Local log records carry trace_id
and span_id. SIGINT and SIGTERM stop the command and flush telemetry.
mikluko deleted branch feat/otel 2026-10-26 21:29:35 +00:00
Sign in to join this conversation.
No description provided.