Repository navigation
refactor(tracer): start the root span with OpenTelemetry - #858
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #858 +/- ##
==========================================
+ Coverage 80.67% 80.69% +0.01%
==========================================
Files 247 247
Lines 18834 18824 -10
==========================================
- Hits 15195 15190 -5
+ Misses 3639 3634 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧪 Thanks @mwbrooks! Moving main onto tracer.Start while the remaining OpenTracing spans still nest under it makes the last step of the migration a small one.
Left a few comments, nothing blocking 🙏
| // var isDevTarget = shared.NewClientFactory().AuthClient().UserDefaultAuthIsProd(ctx) // TODO - hack, remove shared.clients | ||
| var jaegerCloser, jaegerTracer = tracer.SetupTracer(false) // Always setup open tracing on prod | ||
| ctx = slackcontext.SetOpenTracingTracer(ctx, jaegerTracer) | ||
| var traceCloser, _ = tracer.SetupTracer(false) // Always setup tracing on prod |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): Nothing reads the opentracing.Tracer that SetupTracer returns anymore, and this is its only caller. Could SetupTracer return just the io.Closer, so the bridge stays inside the tracer package?
| var traceCloser, _ = tracer.SetupTracer(false) // Always setup tracing on prod | |
| traceCloser := tracer.SetupTracer(false) |
There was a problem hiding this comment.
Changed in commit d774ebb, thanks! SetupTracer now returns only the closer, so the bridge stays inside tracer 🙇
| // TODO(slackcontext) Consolidate storing SystemID to slackcontext | ||
| clients.Config.SystemID = systemID | ||
| // Used by OpenTracing | ||
| // Used by tracing |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): This comment restates the SetSystemID call under it. Could we drop it?
| // Used by tracing |
| // TODO(slackcontext) Consolidate storing ProjectID to slackcontext | ||
| clients.Config.ProjectID = projectID | ||
| // Used by OpenTracing | ||
| // Used by tracing |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): Same here, for SetProjectID.
| // Used by tracing |
| @@ -130,14 +130,3 @@ func Test_Start(t *testing.T) { | |||
| assert.Equal(t, spans["opentracing-parent"].SpanContext().SpanID(), spans["otel-child"].Parent().SpanID()) | |||
| assert.Equal(t, spans["otel-child"].SpanContext().SpanID(), spans["opentracing-grandchild"].Parent().SpanID()) | |||
| } | |||
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Test_Start always begins with an OpenTracing parent, but main now starts an OpenTelemetry root with no parent. Could we add that case, a Start root with an opentracing.StartSpanFromContext child, to pin the nesting the cmd/ spans rely on?
There was a problem hiding this comment.
Added in commit d774ebb, great catch! Test_Start now also starts an OpenTelemetry root with no parent and checks an opentracing.StartSpanFromContext child nests under it 🙇
# Conflicts: # internal/slackcontext/slackcontext.go # internal/slackcontext/slackcontext_test.go # main.go
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 Thanks @mwbrooks! Returning just the closer keeps the bridge inside the tracer package, and the new parentless-root case pins the nesting main now relies on.
One optional comment left, nothing blocking 🙏
| // var isDevTarget = shared.NewClientFactory().AuthClient().UserDefaultAuthIsProd(ctx) // TODO - hack, remove shared.clients | ||
| var jaegerCloser, jaegerTracer = tracer.SetupTracer(false) // Always setup open tracing on prod | ||
| ctx = slackcontext.SetOpenTracingTracer(ctx, jaegerTracer) | ||
| traceCloser := tracer.SetupTracer(false) // Always setup tracing on prod |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): Could a name say this instead of the trailing comment? The bare false is what needs explaining.
| traceCloser := tracer.SetupTracer(false) // Always setup tracing on prod | |
| isDevTarget := false | |
| traceCloser := tracer.SetupTracer(isDevTarget) |
| } | ||
| require.Len(t, spans, 2) | ||
| assert.False(t, spans["otel-root"].Parent().IsValid()) | ||
| assert.Equal(t, spans["otel-root"].SpanContext().SpanID(), spans["opentracing-child"].Parent().SpanID()) |
There was a problem hiding this comment.
💯 praise: Checking that an OpenTracing child of a parentless OpenTelemetry root still nests under it covers the riskiest part of this switch.
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 @mwbrooks thanks! Naming isDevTarget reads much better than the trailing comment, and it lines up with the commented-out line above it.
Every earlier comment is addressed and nothing else stands out 🚀
|
Thanks @WilliamBergamin for the review! 🙇 |
Changelog
N/A - internal refactor with no user-facing changes.
Summary
This pull request starts the CLI's root
mainspan with the OpenTelemetry API, so the last OpenTracing setup outside the call sites goes away. Spans still started through OpenTracing keep nesting undermain, because the bridge's wrapper tracer puts the OpenTelemetry span inctxthe OpenTracing way too.main.gostartsmainwithtracer.Startand sets the sameversion,slack_cli_sessionID,hashed_hostname,slack_cli_process, andai_agentattributesslackcontext.SetProjectIDandSetSystemIDsetproject_idandsystem_idwithtrace.SpanFromContextslackcontext.SetOpenTracingSpan,SetOpenTracingTracer, andtracer.TraceID, which nothing uses anymoretracer.SetupTracerreturns only its closer, so the OpenTracing bridge stays inside the tracer packageBuilds on #857.
Testing
go test ./internal/slackcontext/ ./internal/tracer/ ./cmd/, where theSetProjectIDandSetSystemIDtests now check the span attributeSetupTracerat a local OTLP server, run./bin/slack version, and confirm one trace whose spans all chain up tomainNotes
mainspan, no missing parents, and the debug log'sSlack-CLI-TraceIDmatched the exported trace IDRequirements