Skip to content

refactor(tracer): start the root span with OpenTelemetry - #858

Merged
mwbrooks merged 8 commits into
mainfrom
mwbrooks-otel-root-span
Nov 24, 2026
Merged

mwbrooks merged 8 commits into
mainfrom
mwbrooks-otel-root-span

Conversation

@mwbrooks

@mwbrooks mwbrooks commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Changelog

N/A - internal refactor with no user-facing changes.

Summary

This pull request starts the CLI's root main span with the OpenTelemetry API, so the last OpenTracing setup outside the call sites goes away. Spans still started through OpenTracing keep nesting under main, because the bridge's wrapper tracer puts the OpenTelemetry span in ctx the OpenTracing way too.

  • main.go starts main with tracer.Start and sets the same version, slack_cli_sessionID, hashed_hostname, slack_cli_process, and ai_agent attributes
  • The trace ID for the debug log comes from the span's own context
  • slackcontext.SetProjectID and SetSystemID set project_id and system_id with trace.SpanFromContext
  • Removes slackcontext.SetOpenTracingSpan, SetOpenTracingTracer, and tracer.TraceID, which nothing uses anymore
  • tracer.SetupTracer returns only its closer, so the OpenTracing bridge stays inside the tracer package

Builds on #857.

Testing

  1. Run go test ./internal/slackcontext/ ./internal/tracer/ ./cmd/, where the SetProjectID and SetSystemID tests now check the span attribute
  2. Point SetupTracer at a local OTLP server, run ./bin/slack version, and confirm one trace whose spans all chain up to main

Notes

  • Ran step 2 with a decoder for the OTLP payload: one trace, one root main span, no missing parents, and the debug log's Slack-CLI-TraceID matched the exported trace ID

Requirements

@mwbrooks mwbrooks added this to the Next Release milestone Nov 24, 2026
@mwbrooks mwbrooks added code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment labels Nov 24, 2026
@mwbrooks mwbrooks self-assigned this Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.50000% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.69%. Comparing base (ef90f9a) to head (90fee30).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
main.go 0.00% 14 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mwbrooks
mwbrooks marked this pull request as ready for review November 24, 2026 17:26
@mwbrooks
mwbrooks requested a review from a team as a code owner November 24, 2026 17:26

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 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 🙏

Comment thread main.go Outdated
// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 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?

Suggested change
var traceCloser, _ = tracer.SetupTracer(false) // Always setup tracing on prod
traceCloser := tracer.SetupTracer(false)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in commit d774ebb, thanks! SetupTracer now returns only the closer, so the bridge stays inside tracer 🙇

Comment thread cmd/root.go Outdated
// TODO(slackcontext) Consolidate storing SystemID to slackcontext
clients.Config.SystemID = systemID
// Used by OpenTracing
// Used by tracing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 suggestion (non-blocking): This comment restates the SetSystemID call under it. Could we drop it?

Suggested change
// Used by tracing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in commit d774ebb, thanks! 🙇

Comment thread cmd/root.go Outdated
// TODO(slackcontext) Consolidate storing ProjectID to slackcontext
clients.Config.ProjectID = projectID
// Used by OpenTracing
// Used by tracing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 suggestion (non-blocking): Same here, for SetProjectID.

Suggested change
// Used by tracing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in commit d774ebb, thanks! 🙇

@@ -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())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙇

Base automatically changed from mwbrooks-otel-slackcontext to main November 24, 2026 17:55
# Conflicts:
#	internal/slackcontext/slackcontext.go
#	internal/slackcontext/slackcontext_test.go
#	main.go

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 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 🙏

Comment thread main.go Outdated
// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪓 suggestion (non-blocking): Could a name say this instead of the trailing comment? The bare false is what needs explaining.

Suggested change
traceCloser := tracer.SetupTracer(false) // Always setup tracing on prod
isDevTarget := false
traceCloser := tracer.SetupTracer(isDevTarget)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed in commit 588e1f7, thanks! 🙇

}
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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 praise: Checking that an OpenTracing child of a parentless OpenTelemetry root still nests under it covers the riskiest part of this switch.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 @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 🚀

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the review! 🙇

@mwbrooks
mwbrooks merged commit 1b757c7 into main Nov 24, 2026
14 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-otel-root-span branch November 24, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants