Replace OpenCensus with OpenTelemetry#2138
Merged
matt0x6F merged 5 commits intoJun 19, 2026
Merged
Conversation
OpenCensus is deprecated. Migrate pkg/observ to OpenTelemetry natively instead of using the bridge (gomods#1891). - Traces export over OTLP (gRPC). TraceExporter is now an otlp/empty toggle; the URL default moves from :14268 to :4317 and OTEL_EXPORTER_OTLP_* env vars are honored when it's empty. - Metrics go through an OTel MeterProvider with a Prometheus reader on the same /metrics route. The three custom metrics keep their names (proxy_ prefix included). HTTP metrics come from otelhttp now, so those names change to the semconv names. - ochttp.Handler/Transport become otelhttp; stasher.go's trace.NewContext becomes trace.ContextWithSpan. - jaeger/datadog/stackdriver are dropped. An unsupported exporter logs a message and Athens boots without it, same as before. - Drop go.opencensus.io and the contrib exporters; promote the OTel SDK from indirect to direct. Fixes gomods#1771
The observability FAQ still described the old Jaeger/Stackdriver/Datadog exporters and a walkthrough that won't capture traces now that Athens speaks OTLP. - Rewrite the FAQ section around OTLP and note metrics live on /metrics. - Point the dev compose service at the Jaeger OTLP endpoint and enable Jaeger's OTLP receiver (ports 4317/4318). - Drop the datadog agent service; it's unused now that the Datadog exporter is gone.
The non-dev sampler was ParentBased(AlwaysSample), so production sampled every root span — a behavior change from OpenCensus, which sampled a small fraction by default. Add a knob instead of hardcoding it. - New ATHENS_TRACE_SAMPLING_FRACTION (TraceSamplingFraction), 0.0 to 1.0, defaulting to 1.0. Outside development the root sampler is ParentBased(TraceIDRatioBased(fraction)); development still always samples. - Document it in config.dev.toml and the testdata fixture.
nrwiersma
approved these changes
Jun 18, 2026
matt0x6F
enabled auto-merge (squash)
June 19, 2026 02:30
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 is the problem I am trying to address?
#1771: replace OpenCensus with OpenTelemetry. OpenCensus is deprecated and was
sunset in 2023.
#1891 was a draft that took the OpenCensus bridge route — keep the OpenCensus API and
route its spans into an OTel provider. The bridge works but it leaves the deprecated
dependency in the tree and only defers the real migration. Since the instrumentation all
goes through
pkg/observrather than calling OpenCensus directly, going native isn't muchmore work than the bridge, so this does that instead and drops OpenCensus entirely.
How is the fix applied?
pkg/observis a facade — call sites useobserv.StartSpanandobserv.Record*, not theOpenCensus API. 45 of the 46 files that start spans only call
.End()on what they getback, so changing
StartSpanto return an OTel span leaves them untouched. The migrationis mostly contained to the facade.
RegisterExporterbuilds anotlptracegrpcexporter andan SDK
TracerProvider, sets it global, and returns aShutdownfor cleanup.TraceExporteris now a toggle:otlpor empty.TraceExporterURLis the collectorendpoint, and when it's empty the standard
OTEL_EXPORTER_OTLP_*env vars are honored.The default moves from
:14268(Jaeger) to:4317(OTLP).MeterProviderbacked by a Prometheus reader on the same/metricsroute. The three custom instruments (cache_lookup_total,upstream_fetch_total,upstream_fetch_duration_seconds) keep their names, including theproxy_prefix, so existing scrape configs and dashboards keep working. HTTP server andclient metrics now come from
otelhttp, which means those metric names change to the OTelsemconv names.
ochttp.Handler/ochttp.Transportbecomeotelhttp.NewHandler/otelhttp.NewTransport.stasher.gowas the one file reaching under the facade (trace.NewContext); it now usestrace.ContextWithSpan.jaeger,datadog, andstackdriverexporters are gone. Asking for one logs amessage telling you to use OTLP and carries on — like an unset or unknown exporter, it
doesn't stop Athens from booting, you just don't get traces.
mostly promotes it to direct and drops
go.opencensus.ioand the threecontrib.go.opencensus.io/exporter/*modules.Sampling is configurable.
developmentstill samples every trace. Outside it, the newATHENS_TRACE_SAMPLING_FRACTION(TraceSamplingFractionin the config file) sets thefraction of root traces sampled —
0.0to1.0, defaulting to1.0— viaParentBased(TraceIDRatioBased(...)), so child spans follow their parent's decision.What GitHub issue(s) does this PR fix or close?
Fixes #1771, #2026
Note: this drops direct
datadogandstackdriverexport. Athens still exposes metricson
/metricsfor Prometheus, and traces can reach either through an OTLP collector. Anyoneon
ATHENS_TRACE_EXPORTER=datadog/stackdriverneeds to point at a collector withATHENS_TRACE_EXPORTER=otlpinstead — an unsupported value isn't fatal, Athens logs amessage and boots without tracing. The three custom metric names are unchanged; the HTTP
metric names change to the OTel conventions.