From d11de3dc931cd3be5ec7b650e518b57919efd79a Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Tue, 24 Nov 2026 10:09:05 -0700 Subject: [PATCH 1/5] refactor: rename the slackcontext trace ID helpers to TraceID and SetTraceID --- internal/iostreams/logfile.go | 2 +- internal/slackcontext/slackcontext.go | 40 +++++----- internal/slackcontext/slackcontext_mock.go | 2 +- internal/slackcontext/slackcontext_test.go | 86 +++++++++++----------- main.go | 2 +- 5 files changed, 66 insertions(+), 66 deletions(-) diff --git a/internal/iostreams/logfile.go b/internal/iostreams/logfile.go index 1510f391..c93393e5 100644 --- a/internal/iostreams/logfile.go +++ b/internal/iostreams/logfile.go @@ -63,7 +63,7 @@ func (io *IOStreams) InitLogFile(ctx context.Context) error { // Added line break for each session logger.Println("------------------------------------") - traceID, err := slackcontext.OpenTracingTraceID(ctx) + traceID, err := slackcontext.TraceID(ctx) if err != nil { return err } diff --git a/internal/slackcontext/slackcontext.go b/internal/slackcontext/slackcontext.go index 7e2f56b0..cdec4069 100644 --- a/internal/slackcontext/slackcontext.go +++ b/internal/slackcontext/slackcontext.go @@ -39,11 +39,11 @@ import ( type contextKey int const ( - contextKeyOpenTracingTraceID contextKey = iota - contextKeyOpenTracingTracer + contextKeyOpenTracingTracer contextKey = iota contextKeyProjectID contextKeySessionID contextKeySystemID + contextKeyTraceID contextKeyVersion ) @@ -54,24 +54,6 @@ func SetOpenTracingSpan(ctx context.Context, span opentracing.Span) context.Cont return ctx } -// OpenTracingTraceID returns the trace ID associated with `ctx`, or -// `""` and `slackerror.ErrContextValueNotFound` if no trace ID could be found. -func OpenTracingTraceID(ctx context.Context) (string, error) { - traceID, ok := ctx.Value(contextKeyOpenTracingTraceID).(string) - if !ok || traceID == "" { - return "", slackerror.New(slackerror.ErrContextValueNotFound). - WithMessage("The value for OpenTracing Trace ID could not be found") - } - return traceID, nil -} - -// SetOpenTracingTraceID returns a new `context.Context` that holds a reference to -// the `traceID`. -func SetOpenTracingTraceID(ctx context.Context, traceID string) context.Context { - ctx = context.WithValue(ctx, contextKeyOpenTracingTraceID, traceID) - return ctx -} - // SetOpenTracingSpan returns a new `context.Context` that holds a reference to // the `opentracing.Tracer`. If tracer is nil, a new context without a tracer returned. func SetOpenTracingTracer(ctx context.Context, tracer opentracing.Tracer) context.Context { @@ -127,6 +109,24 @@ func SetSystemID(ctx context.Context, systemID string) context.Context { return ctx } +// TraceID returns the trace ID associated with `ctx`, or +// `""` and `slackerror.ErrContextValueNotFound` if no trace ID could be found. +func TraceID(ctx context.Context) (string, error) { + traceID, ok := ctx.Value(contextKeyTraceID).(string) + if !ok || traceID == "" { + return "", slackerror.New(slackerror.ErrContextValueNotFound). + WithMessage("The value for Trace ID could not be found") + } + return traceID, nil +} + +// SetTraceID returns a new `context.Context` that holds a reference to +// the `traceID`. +func SetTraceID(ctx context.Context, traceID string) context.Context { + ctx = context.WithValue(ctx, contextKeyTraceID, traceID) + return ctx +} + // Version returns the CLI version associated with `ctx`. If the version is not // found in the context, it falls back to version.Raw() and returns an error to // signal that the context was not properly initialized. diff --git a/internal/slackcontext/slackcontext_mock.go b/internal/slackcontext/slackcontext_mock.go index b4679a1c..f5454306 100644 --- a/internal/slackcontext/slackcontext_mock.go +++ b/internal/slackcontext/slackcontext_mock.go @@ -27,7 +27,7 @@ const ( // MockContext sets values in the context that are guaranteed to exist before // the Cobra root command is executed. func MockContext(ctx context.Context) context.Context { - ctx = SetOpenTracingTraceID(ctx, uuid.New().String()) + ctx = SetTraceID(ctx, uuid.New().String()) ctx = SetSessionID(ctx, uuid.New().String()) ctx = SetVersion(ctx, mockCLIVersion) return ctx diff --git a/internal/slackcontext/slackcontext_test.go b/internal/slackcontext/slackcontext_test.go index 3da284a8..27d3c213 100644 --- a/internal/slackcontext/slackcontext_test.go +++ b/internal/slackcontext/slackcontext_test.go @@ -44,49 +44,6 @@ func Test_SlackContext_SetOpenTracingSpan(t *testing.T) { } } -func Test_SlackContext_OpenTracingTraceID(t *testing.T) { - tests := map[string]struct { - expectedTraceID string - expectedError error - }{ - "returns Trace ID when it exists": { - expectedTraceID: uuid.New().String(), - expectedError: nil, - }, - "returns error when Trace ID not found": { - expectedTraceID: "", - expectedError: slackerror.New(slackerror.ErrContextValueNotFound).WithMessage("The value for OpenTracing Trace ID could not be found"), - }, - } - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - ctx := t.Context() - ctx = context.WithValue(ctx, contextKeyOpenTracingTraceID, tc.expectedTraceID) - actualTraceID, actualError := OpenTracingTraceID(ctx) - require.Equal(t, tc.expectedTraceID, actualTraceID) - require.Equal(t, tc.expectedError, actualError) - }) - } -} - -func Test_SlackContext_SetOpenTracingTraceID(t *testing.T) { - tests := map[string]struct { - expectedTraceID string - }{ - "sets the Trace ID in the context": { - expectedTraceID: uuid.New().String(), - }, - } - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - ctx := t.Context() - ctx = SetOpenTracingTraceID(ctx, tc.expectedTraceID) - actualTraceID := ctx.Value(contextKeyOpenTracingTraceID).(string) - require.Equal(t, tc.expectedTraceID, actualTraceID) - }) - } -} - func Test_SlackContext_SetOpenTracingTracer(t *testing.T) { _, _tracer := tracer.SetupTracer(true) @@ -186,6 +143,49 @@ func Test_SlackContext_SetSystemID(t *testing.T) { } } +func Test_SlackContext_TraceID(t *testing.T) { + tests := map[string]struct { + expectedTraceID string + expectedError error + }{ + "returns Trace ID when it exists": { + expectedTraceID: uuid.New().String(), + expectedError: nil, + }, + "returns error when Trace ID not found": { + expectedTraceID: "", + expectedError: slackerror.New(slackerror.ErrContextValueNotFound).WithMessage("The value for Trace ID could not be found"), + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + ctx := t.Context() + ctx = context.WithValue(ctx, contextKeyTraceID, tc.expectedTraceID) + actualTraceID, actualError := TraceID(ctx) + require.Equal(t, tc.expectedTraceID, actualTraceID) + require.Equal(t, tc.expectedError, actualError) + }) + } +} + +func Test_SlackContext_SetTraceID(t *testing.T) { + tests := map[string]struct { + expectedTraceID string + }{ + "sets the Trace ID in the context": { + expectedTraceID: uuid.New().String(), + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + ctx := t.Context() + ctx = SetTraceID(ctx, tc.expectedTraceID) + actualTraceID := ctx.Value(contextKeyTraceID).(string) + require.Equal(t, tc.expectedTraceID, actualTraceID) + }) + } +} + func Test_SlackContext_Version(t *testing.T) { t.Run("returns Version when it exists", func(t *testing.T) { ctx := t.Context() diff --git a/main.go b/main.go index b9b2b3b2..76ffb3c3 100644 --- a/main.go +++ b/main.go @@ -66,7 +66,7 @@ func main() { // project_id is set in root.go initConfig() if traceID := tracer.TraceID(span); traceID != "" { - ctx = slackcontext.SetOpenTracingTraceID(ctx, traceID) + ctx = slackcontext.SetTraceID(ctx, traceID) } // Flush on return here, and before each exit in cmd/root.go, which skips these defers From 1e077aa40b625df18d987b3e75760ced263c3b75 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Tue, 24 Nov 2026 10:13:04 -0700 Subject: [PATCH 2/5] refactor: start the root span with OpenTelemetry and drop the OpenTracing context helpers --- cmd/root.go | 4 +- internal/slackcontext/slackcontext.go | 36 +++------------ internal/slackcontext/slackcontext_test.go | 53 +++++----------------- internal/tracer/tracer.go | 9 ---- internal/tracer/tracer_test.go | 11 ----- main.go | 29 ++++++------ 6 files changed, 34 insertions(+), 108 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index d55af1c0..e35d3ddc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -305,7 +305,7 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob // Used by Logstash // TODO(slackcontext) Consolidate storing SystemID to slackcontext clients.Config.SystemID = systemID - // Used by OpenTracing + // Used by tracing ctx = slackcontext.SetSystemID(ctx, systemID) rootCmd.SetContext(ctx) // Debug logging @@ -318,7 +318,7 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob // Used by Logstash // TODO(slackcontext) Consolidate storing ProjectID to slackcontext clients.Config.ProjectID = projectID - // Used by OpenTracing + // Used by tracing ctx = slackcontext.SetProjectID(ctx, projectID) rootCmd.SetContext(ctx) // Debug logging diff --git a/internal/slackcontext/slackcontext.go b/internal/slackcontext/slackcontext.go index cdec4069..a02e2c3a 100644 --- a/internal/slackcontext/slackcontext.go +++ b/internal/slackcontext/slackcontext.go @@ -29,9 +29,10 @@ package slackcontext import ( "context" - "github.com/opentracing/opentracing-go" "github.com/slackapi/slack-cli/internal/slackerror" "github.com/slackapi/slack-cli/internal/version" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" ) // contextKey is an unexported type to avoid context key collisions. @@ -39,39 +40,20 @@ import ( type contextKey int const ( - contextKeyOpenTracingTracer contextKey = iota - contextKeyProjectID + contextKeyProjectID contextKey = iota contextKeySessionID contextKeySystemID contextKeyTraceID contextKeyVersion ) -// SetOpenTracingSpan returns a new `context.Context` that holds a reference to -// the span. If span is nil, a new context without an active span is returned. -func SetOpenTracingSpan(ctx context.Context, span opentracing.Span) context.Context { - ctx = opentracing.ContextWithSpan(ctx, span) - return ctx -} - -// SetOpenTracingSpan returns a new `context.Context` that holds a reference to -// the `opentracing.Tracer`. If tracer is nil, a new context without a tracer returned. -func SetOpenTracingTracer(ctx context.Context, tracer opentracing.Tracer) context.Context { - ctx = context.WithValue(ctx, contextKeyOpenTracingTracer, tracer) - return ctx -} - // SetProjectID returns a new `context.Context` that holds a reference to -// the `projectID` and updates the `opentracing.Span` tag with the `projectID`. +// the `projectID` and sets the `project_id` attribute on the span in `ctx`. func SetProjectID(ctx context.Context, projectID string) context.Context { // Set projectID in the context ctx = context.WithValue(ctx, contextKeyProjectID, projectID) - // Set projectID in OpenTracing by extracting the span and updating the tag - if span := opentracing.SpanFromContext(ctx); span != nil { - span.SetTag("project_id", projectID) - ctx = opentracing.ContextWithSpan(ctx, span) - } + trace.SpanFromContext(ctx).SetAttributes(attribute.String("project_id", projectID)) return ctx } @@ -95,16 +77,12 @@ func SetSessionID(ctx context.Context, sessionID string) context.Context { } // SetSystemID returns a new `context.Context` that holds a reference to -// the `systemID` and updates the `opentracing.Span` tag with the `systemID`. +// the `systemID` and sets the `system_id` attribute on the span in `ctx`. func SetSystemID(ctx context.Context, systemID string) context.Context { // Set systemID in the context ctx = context.WithValue(ctx, contextKeySystemID, systemID) - // Set projectID in OpenTracing by extracting the span and updating the tag - if span := opentracing.SpanFromContext(ctx); span != nil { - span.SetTag("system_id", systemID) - ctx = opentracing.ContextWithSpan(ctx, span) - } + trace.SpanFromContext(ctx).SetAttributes(attribute.String("system_id", systemID)) return ctx } diff --git a/internal/slackcontext/slackcontext_test.go b/internal/slackcontext/slackcontext_test.go index 27d3c213..7759d7a9 100644 --- a/internal/slackcontext/slackcontext_test.go +++ b/internal/slackcontext/slackcontext_test.go @@ -19,51 +19,14 @@ import ( "testing" "github.com/google/uuid" - "github.com/opentracing/opentracing-go" "github.com/slackapi/slack-cli/internal/slackerror" - "github.com/slackapi/slack-cli/internal/tracer" "github.com/slackapi/slack-cli/internal/version" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/sdk/trace/tracetest" ) -func Test_SlackContext_SetOpenTracingSpan(t *testing.T) { - tests := map[string]struct { - expectedSpan opentracing.Span - }{ - "sets the span in the context": { - expectedSpan: opentracing.StartSpan("test.span"), - }, - } - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - ctx := t.Context() - ctx = SetOpenTracingSpan(ctx, tc.expectedSpan) - actualSpan := opentracing.SpanFromContext(ctx) - require.Equal(t, tc.expectedSpan, actualSpan) - }) - } -} - -func Test_SlackContext_SetOpenTracingTracer(t *testing.T) { - _, _tracer := tracer.SetupTracer(true) - - tests := map[string]struct { - expectedTracer opentracing.Tracer - }{ - "sets the Tracer in the context": { - expectedTracer: _tracer, - }, - } - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - ctx := t.Context() - ctx = SetOpenTracingTracer(ctx, tc.expectedTracer) - actualTracer := ctx.Value(contextKeyOpenTracingTracer).(opentracing.Tracer) - require.Equal(t, tc.expectedTracer, actualTracer) - }) - } -} - func Test_SlackContext_SetProjectID(t *testing.T) { tests := map[string]struct { expectedProjectID string @@ -74,8 +37,11 @@ func Test_SlackContext_SetProjectID(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx := t.Context() + recorder := tracetest.NewSpanRecorder() + ctx, span := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder)).Tracer("test").Start(t.Context(), "span") ctx = SetProjectID(ctx, tc.expectedProjectID) + span.End() + require.Contains(t, recorder.Ended()[0].Attributes(), attribute.String("project_id", tc.expectedProjectID)) actualProjectID := ctx.Value(contextKeyProjectID).(string) require.Equal(t, tc.expectedProjectID, actualProjectID) }) @@ -135,8 +101,11 @@ func Test_SlackContext_SetSystemID(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx := t.Context() + recorder := tracetest.NewSpanRecorder() + ctx, span := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder)).Tracer("test").Start(t.Context(), "span") ctx = SetSystemID(ctx, tc.expectedSystemID) + span.End() + require.Contains(t, recorder.Ended()[0].Attributes(), attribute.String("system_id", tc.expectedSystemID)) actualSystemID := ctx.Value(contextKeySystemID).(string) require.Equal(t, tc.expectedSystemID, actualSystemID) }) diff --git a/internal/tracer/tracer.go b/internal/tracer/tracer.go index 15048ee3..776d452b 100644 --- a/internal/tracer/tracer.go +++ b/internal/tracer/tracer.go @@ -155,15 +155,6 @@ func SetTraceHeaders(ctx context.Context, header http.Header) { header.Set("x-b3-sampled", "0") } -// TraceID returns the trace ID of span, or "" if span has no trace ID. -func TraceID(span opentracing.Span) string { - carrier := opentracing.HTTPHeadersCarrier(http.Header{}) - if err := span.Tracer().Inject(span.Context(), opentracing.HTTPHeaders, carrier); err != nil { - return "" - } - return http.Header(carrier).Get("x-b3-traceid") -} - var ( flushMu sync.Mutex flushFunc func() diff --git a/internal/tracer/tracer_test.go b/internal/tracer/tracer_test.go index f813e0a4..b31458eb 100644 --- a/internal/tracer/tracer_test.go +++ b/internal/tracer/tracer_test.go @@ -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()) } - -func Test_TraceID(t *testing.T) { - recorder := tracetest.NewSpanRecorder() - tracer := newBridgeTracer(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder))) - span := tracer.StartSpan("span") - traceID := TraceID(span) - span.Finish() - assert.Len(t, traceID, 32) - assert.Equal(t, recorder.Ended()[0].SpanContext().TraceID().String(), traceID) - assert.Empty(t, TraceID(opentracing.NoopTracer{}.StartSpan("noop"))) -} diff --git a/main.go b/main.go index 76ffb3c3..f74dcda4 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,6 @@ import ( "strings" "github.com/google/uuid" - "github.com/opentracing/opentracing-go" "github.com/slackapi/slack-cli/cmd" "github.com/slackapi/slack-cli/internal/goutils" "github.com/slackapi/slack-cli/internal/iostreams" @@ -31,6 +30,7 @@ import ( "github.com/slackapi/slack-cli/internal/tracer" "github.com/slackapi/slack-cli/internal/useragent" "github.com/slackapi/slack-cli/internal/version" + "go.opentelemetry.io/otel/attribute" ) func main() { @@ -43,8 +43,7 @@ func main() { // - This would allow us to choose the correct API host based on flags // - Uncomment `isDevTarget` if we refactor to cmd/root.go and update to call `ResolveAPIHost` // 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 // Set context values sessionID := uuid.New().String() @@ -55,30 +54,30 @@ func main() { osStr := os.Args[0:] processName := goutils.RedactPII(strings.Join(osStr, " ")) - var span = jaegerTracer.StartSpan("main", opentracing.Tag{Key: "version", Value: cliVersion}) - span.SetTag("slack_cli_sessionID", sessionID) - span.SetTag("hashed_hostname", ioutils.GetHostname()) - span.SetTag("slack_cli_process", processName) + ctx, span := tracer.Start(ctx, "main") + span.SetAttributes( + attribute.String("version", cliVersion), + attribute.String("slack_cli_sessionID", sessionID), + attribute.String("hashed_hostname", ioutils.GetHostname()), + attribute.String("slack_cli_process", processName), + ) if aiAgentName := useragent.GetAIAgentName(); aiAgentName != "" { - span.SetTag("ai_agent", aiAgentName) + span.SetAttributes(attribute.String("ai_agent", aiAgentName)) } // system_id is set in root.go initConfig() // project_id is set in root.go initConfig() - if traceID := tracer.TraceID(span); traceID != "" { - ctx = slackcontext.SetTraceID(ctx, traceID) + if spanContext := span.SpanContext(); spanContext.IsValid() { + ctx = slackcontext.SetTraceID(ctx, spanContext.TraceID().String()) } // Flush on return here, and before each exit in cmd/root.go, which skips these defers tracer.SetFlush(func() { - span.Finish() - _ = jaegerCloser.Close() + span.End() + _ = traceCloser.Close() }) defer tracer.Flush() - // add root span to context - ctx = slackcontext.SetOpenTracingSpan(ctx, span) - rootCmd, clients := cmd.Init(ctx) cmd.ExecuteContext(ctx, rootCmd, clients) } From 682023dacf30261d44294f767be37a3ad85ecbd0 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Tue, 24 Nov 2026 10:28:41 -0700 Subject: [PATCH 3/5] docs: drop the doc comments on TraceID and SetTraceID --- internal/slackcontext/slackcontext.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/slackcontext/slackcontext.go b/internal/slackcontext/slackcontext.go index cdec4069..1ebd1d9e 100644 --- a/internal/slackcontext/slackcontext.go +++ b/internal/slackcontext/slackcontext.go @@ -109,8 +109,6 @@ func SetSystemID(ctx context.Context, systemID string) context.Context { return ctx } -// TraceID returns the trace ID associated with `ctx`, or -// `""` and `slackerror.ErrContextValueNotFound` if no trace ID could be found. func TraceID(ctx context.Context) (string, error) { traceID, ok := ctx.Value(contextKeyTraceID).(string) if !ok || traceID == "" { @@ -120,8 +118,6 @@ func TraceID(ctx context.Context) (string, error) { return traceID, nil } -// SetTraceID returns a new `context.Context` that holds a reference to -// the `traceID`. func SetTraceID(ctx context.Context, traceID string) context.Context { ctx = context.WithValue(ctx, contextKeyTraceID, traceID) return ctx From d774ebb0f9540eada57f64688879436c4edb4866 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Tue, 24 Nov 2026 10:38:44 -0700 Subject: [PATCH 4/5] refactor: return only the closer from SetupTracer and pin root span nesting --- cmd/root.go | 2 -- internal/tracer/tracer.go | 4 ++-- internal/tracer/tracer_test.go | 15 +++++++++++++++ main.go | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index e35d3ddc..00049f20 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -305,7 +305,6 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob // Used by Logstash // TODO(slackcontext) Consolidate storing SystemID to slackcontext clients.Config.SystemID = systemID - // Used by tracing ctx = slackcontext.SetSystemID(ctx, systemID) rootCmd.SetContext(ctx) // Debug logging @@ -318,7 +317,6 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob // Used by Logstash // TODO(slackcontext) Consolidate storing ProjectID to slackcontext clients.Config.ProjectID = projectID - // Used by tracing ctx = slackcontext.SetProjectID(ctx, projectID) rootCmd.SetContext(ctx) // Debug logging diff --git a/internal/tracer/tracer.go b/internal/tracer/tracer.go index 776d452b..9dcffe1a 100644 --- a/internal/tracer/tracer.go +++ b/internal/tracer/tracer.go @@ -37,7 +37,7 @@ import ( ) // SetupTracer sets up the tracer to send data to honeycomb with OpenTelemetry -func SetupTracer(isDev bool) (io.Closer, opentracing.Tracer) { +func SetupTracer(isDev bool) io.Closer { var collectorEndpoint = "https://slackb.com/traces/v1/otlp" if isDev { collectorEndpoint = "https://dev.slackb.com/traces/v1/otlp" @@ -57,7 +57,7 @@ func SetupTracer(isDev bool) (io.Closer, opentracing.Tracer) { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() return provider.Shutdown(ctx) - }), bridge + }) } // exporterOptions sets every value that OTEL_EXPORTER_OTLP_* environment diff --git a/internal/tracer/tracer_test.go b/internal/tracer/tracer_test.go index b31458eb..0919ba6a 100644 --- a/internal/tracer/tracer_test.go +++ b/internal/tracer/tracer_test.go @@ -129,4 +129,19 @@ func Test_Start(t *testing.T) { require.Len(t, spans, 3) 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()) + + recorder = tracetest.NewSpanRecorder() + tracer = newBridgeTracer(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder))) + opentracing.SetGlobalTracer(tracer) + ctx, root := Start(context.Background(), "otel-root") + child2, _ := opentracing.StartSpanFromContext(ctx, "opentracing-child") + child2.Finish() + root.End() + spans = map[string]sdktrace.ReadOnlySpan{} + for _, span := range recorder.Ended() { + spans[span.Name()] = span + } + 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()) } diff --git a/main.go b/main.go index f74dcda4..6cf129b8 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,7 @@ func main() { // - This would allow us to choose the correct API host based on flags // - Uncomment `isDevTarget` if we refactor to cmd/root.go and update to call `ResolveAPIHost` // var isDevTarget = shared.NewClientFactory().AuthClient().UserDefaultAuthIsProd(ctx) // TODO - hack, remove shared.clients - var traceCloser, _ = tracer.SetupTracer(false) // Always setup tracing on prod + traceCloser := tracer.SetupTracer(false) // Always setup tracing on prod // Set context values sessionID := uuid.New().String() From 588e1f7de8c4d63a6fc43c6c963692b13bf85e33 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Tue, 24 Nov 2026 11:42:39 -0700 Subject: [PATCH 5/5] refactor: name the dev target flag passed to SetupTracer --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6cf129b8..8078ef23 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,8 @@ func main() { // - This would allow us to choose the correct API host based on flags // - Uncomment `isDevTarget` if we refactor to cmd/root.go and update to call `ResolveAPIHost` // var isDevTarget = shared.NewClientFactory().AuthClient().UserDefaultAuthIsProd(ctx) // TODO - hack, remove shared.clients - traceCloser := tracer.SetupTracer(false) // Always setup tracing on prod + isDevTarget := false + traceCloser := tracer.SetupTracer(isDevTarget) // Set context values sessionID := uuid.New().String()