feat: instrument whoami with OpenTelemetry traces, metrics, and logs#158
Open
zalbiraw wants to merge 3 commits into
Open
feat: instrument whoami with OpenTelemetry traces, metrics, and logs#158zalbiraw wants to merge 3 commits into
zalbiraw wants to merge 3 commits into
Conversation
Add OpenTelemetry instrumentation configured entirely through the standard OTEL_* environment variables, so whoami can ship traces, metrics, and logs (including per-request access logs) to any OTLP backend. - Traces: a server span per HTTP request (otelhttp) and per gRPC call (otelgrpc). - Metrics: HTTP server metrics (http.server.*), gRPC server metrics (rpc.server.*), and a custom whoami.requests counter by method/status. - Logs: application and structured access logs are emitted through the OpenTelemetry Logs SDK. Access logs run inside the request span, so each record carries the active trace and span IDs. Each signal is controlled independently by its standard exporter variable. Logs default to the console (stdout) exporter so whoami prints structured logs out of the box; traces and metrics are opt-in (OTEL_TRACES_EXPORTER / OTEL_METRICS_EXPORTER, e.g. set to "otlp"). Endpoint, protocol, service name, and resource attributes use the usual OTEL_EXPORTER_OTLP_* variables. Also replace the deprecated golang.org/x/net/http2/h2c with the native Go 1.24 HTTP/2 cleartext support, and drain in-flight requests on SIGINT/SIGTERM so batched telemetry is flushed on shutdown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Main job installs the latest stable Go (now 1.26), but the pinned
golangci-lint v2.1.2 is built with Go 1.24 and panics when type-checking a
newer stdlib ("file requires newer Go version go1.26"). Pin this job to Go
1.24 — the module's go directive — so the linter works. The Go matrix
workflow still builds and tests against stable and oldstable across all OSes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Restore whoami's original default-quiet behavior: per-request access logs are emitted only when the `verbose` flag is set, so stdout stays minimal by default and shows access logs just like the pre-OpenTelemetry verbose mode did. Access logs still flow through OpenTelemetry (stdout by default, or OTLP when configured) and carry the active trace and span IDs. The whoami.requests metric is unaffected and is still recorded for every request regardless of verbosity. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Instruments whoami with OpenTelemetry, configured entirely through the standard
OTEL_*environment variables. whoami can now emit traces, metrics, and logs (including per-request access logs) to any OTLP backend.How it's controlled
Each signal is controlled independently by its standard exporter variable:
OTEL_LOGS_EXPORTERconsoleconsoleprints to stdout,otlpships logs,nonedisablesOTEL_TRACES_EXPORTERnoneotlp(orconsole) to emit tracesOTEL_METRICS_EXPORTERnoneotlp(orconsole) to emit metricsLogs print to stdout out of the box; traces and metrics are opt-in. Endpoint, protocol, service name, and resource attributes use the usual
OTEL_EXPORTER_OTLP_*,OTEL_SERVICE_NAME, andOTEL_RESOURCE_ATTRIBUTESvariables (exporter selection viacontrib/exporters/autoexport).What gets emitted
otelhttp) and per gRPC call (otelgrpc).http.server.*), gRPC server metrics (rpc.server.*), and a customwhoami.requestscounter labelled by method and status.Other changes
golang.org/x/net/http2/h2cwith the native Go 1.24 HTTP/2 cleartext support (http.Server.Protocols+SetUnencryptedHTTP2), keeping the plaintext gRPC endpoint working.SIGINT/SIGTERMso batched telemetry is flushed on shutdown.go.modstays atgo 1.24; the existing CI workflow and.golangci.ymlare untouched. Dependencies are pinned to a coordinated, go-1.24-compatible OpenTelemetry release set, and gRPC stays at its current version.Verification
go build,go test,go vet, andgolangci-lint(the pinnedv2.1.2) all pass;go mod tidyis diff-free.http.server.*/rpc.server.*/whoami.requestsmetrics, and access-log records with non-zero trace IDs all arrive. With noOTEL_*vars set, structured logs (incl. access logs) print to stdout and nothing is shipped.