sourcegraph
sourcegraph copied to clipboard
internal/tracer: only start OTEL spans if ShouldTrace is true
Currently we rely on implementors to explicitly check ShouldTrace
. This works implicitly through internal/trace/ot
which guards against ShouldTrace
and returns no-op OpenTracing tracers, which worked until we started moving code over to use OpenTelemetry libraries directly, where a similar guard was not implemented.
This wraps all tracers provided from the global switchable oteltrace.TracerProvider
to only start spans when ShouldTrace
evaluates to true without the caller having to do anything explicitly. Also updates ShouldTrace
to respect global trace-all without requiring the context set.
Test plan
sg start
and see all the no-op logs coming through with observability.tracing: { debug: true }
with sampling: selective
or sampling: none
Codenotify: Notifying subscribers in CODENOTIFY files for diff 9eef7919deb7edef6d0689bdddc2d91dc8ad2b06...c65902d4e9b1cc2965520d785f7c18ba7e990283.
Notify | File(s) |
---|---|
@keegancsmith | internal/trace/policy/policy.go internal/tracer/should_trace.go internal/tracer/switchable_otel.go internal/tracer/watch_test.go |
@sourcegraph/dev-experience | internal/trace/policy/policy.go internal/tracer/should_trace.go internal/tracer/switchable_otel.go internal/tracer/watch_test.go |