internal/tracer: add OpenTelemetry tracer
Created by: bobheadxi
This approach should "just work". We extend internal/tracer
to support a new tracer type, opentelemetry
, that sends everything in OpenTelemetry format (hopefully correctly) using the OpenTracing bridge, which means it looks like no code changes are necessary!
Took me a while a very long time to wrap my head around, but this is how our tracing implementation seems to work:
-
internal/tracer.Init()
-> sets aswitchableTracer
toopentracing.GlobalTracer()
- Everyone else uses
opentracing.GlobalTracer
->switchableTracer
- We hot-swap the
opentracing.Tracer
insideswitchableTracer
with whatever is in site config
The OTel collector host is configurable via OTEL_EXPORTER_OTLP_ENDPOINT
- a clunky name, but one that shows up in the wild frequently, and OTel export can be enabled by setting:
"observability.tracing": {
"sampling": "selective",
"type": "opentelemetry",
},
See below + test plan for more details.
Closes https://github.com/sourcegraph/sourcegraph/issues/27386
Incomplete but IMO should not be blocking, because this tracing implementation is not used in practice anywhere yet:
- Docs (intentional omission for now, until we've had more time to test this in practice). I have included some very minimal dev docs however
- Spans that cross to
zoekt-webserver
- I can see the individual spans, but they aren't linked properly in Jaeger, see below (left is before, right is after)
Before | After |
---|---|
I suspect this is because I haven't configured the propagator correctly to work with pure OpenTracing implementations like Zoekt, but after some digging I haven't been able to figure this out. Note that spans that go between Sourcegraph services work fine:
Filed the above as a follow-up in https://github.com/sourcegraph/sourcegraph/issues/38232
Test plan
- Set
dev-private
site config to useopentelemetry
-
sg start otel
-> runsotel-collector
andjaeger
sg start
- Run a complex query with
&trace=1
, e.g. https://sourcegraph.test:3443/search?q=context%3Aglobal+foobar%28...%29&patternType=structural&trace=1
Quick demo: https://www.loom.com/share/a8f86adfac984f6085a000f1dc6ba4c7