Skip to content

refactor(iostreams): use OpenTelemetry spans in the printers - #864

Merged
mwbrooks merged 4 commits into
mainfrom
mwbrooks-otel-iostreams
Nov 24, 2026
Merged

mwbrooks merged 4 commits into
mainfrom
mwbrooks-otel-iostreams

Conversation

@mwbrooks

Copy link
Copy Markdown
Member

Changelog

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

Summary

This pull request moves the printDebug, printError, printWarning, and printInfo spans in internal/iostreams/printer.go from OpenTracing to the OpenTelemetry API. These were the last call sites outside npm.go, which #834 covers.

  • Span names stay the same
  • The debug_log, error_log, warning_log, and printInfo tags carry over as string attributes with the same names
  • printInfo still only starts a span when shouldTrace is true

Testing

  1. Run go test ./internal/iostreams/

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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.77%. Comparing base (ae3686b) to head (8b31394).

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.
📢 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 19:19
@mwbrooks
mwbrooks requested a review from a team as a code owner November 24, 2026 19:19

@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! 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))

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 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.

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 81ac66b, great catch! Test_IOStreams_printSpans checks the span name and log attribute for each printer, including PrintError and PrintInfo with shouldTrace 🙇

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

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: 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.

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the review! 🙇

@mwbrooks
mwbrooks merged commit 8cc2a23 into main Nov 24, 2026
14 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-otel-iostreams branch November 24, 2026 19:54
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