Repository navigation
refactor(iostreams): use OpenTelemetry spans in the printers - #864
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #864 +/- ##
==========================================
+ Coverage 80.72% 80.77% +0.05%
==========================================
Files 247 247
Lines 18855 18859 +4
==========================================
+ Hits 15220 15233 +13
+ Misses 3635 3626 -9 ☔ 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! Same span names and attribute keys as before, and it follows the tracer.Start + SetAttributes pattern from the earlier migrations, so the trace queries keep working.
Left one comment on tests, nothing blocking 🙏
| span, _ := opentracing.StartSpanFromContext(ctx, "printDebug", opentracing.Tag{Key: "debug_log", Value: message}) | ||
| defer span.Finish() | ||
| _, span := tracer.Start(ctx, "printDebug") | ||
| span.SetAttributes(attribute.String("debug_log", message)) |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could we add a tracetest.SpanRecorder test, like internal/pkg/create/create_test.go, that checks each printer's span name and log attribute? Nothing asserts them today, PrintError has no test, and PrintInfo never runs with shouldTrace true.
There was a problem hiding this comment.
Added in commit 81ac66b, great catch! Test_IOStreams_printSpans checks the span name and log attribute for each printer, including PrintError and PrintInfo with shouldTrace 🙇
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 @mwbrooks thanks for adding the span test, it pins every printer's span name and log attribute in one table.
Nothing else from me 🚀
| t.Run(name, func(t *testing.T) { | ||
| recorder := tracetest.NewSpanRecorder() | ||
| previous := otel.GetTracerProvider() | ||
| otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder))) |
There was a problem hiding this comment.
💯 praise: Swapping the global tracer provider with a cleanup keeps this test from leaking spans into the rest of the suite, same as the auth and api tests.
|
Thanks @WilliamBergamin for the review! 🙇 |
Changelog
N/A - internal refactor with no user-facing changes.
Summary
This pull request moves the
printDebug,printError,printWarning, andprintInfospans ininternal/iostreams/printer.gofrom OpenTracing to the OpenTelemetry API. These were the last call sites outsidenpm.go, which #834 covers.debug_log,error_log,warning_log, andprintInfotags carry over as string attributes with the same namesprintInfostill only starts a span whenshouldTraceis trueTesting
go test ./internal/iostreams/Requirements