Skip to content

telemetry: root span ends early for generators #952

@sentry-junior

Description

@sentry-junior

Root span ends before command completes for generator-based commands.

What happens

The CLI wraps command execution in a Sentry.startSpanManual root span (cli.command op) in src/lib/telemetry.ts:208. For commands using the async *func generator pattern (like plan and explain), the root span appears to end before the generator is fully consumed — resulting in traces with only a single span and sub-millisecond duration despite the command running for much longer.

Evidence

Trace for a sentry issue plan invocation that showed progress spinners and polled for a solution:

  • Trace: b7f06e739b304d96afd6fe58801d3c26
  • Project: sentry/cli (project id 4510776311808000)
  • Event: 168087f80b3e438794a36cd4067f8b7f
  • Observed: 1 span, 2.457ms duration, no child spans (HTTP calls, polling)
  • Expected: full command lifecycle including getAutofixState, triggerSolutionPlanning, and polling loop

Impact

  • CLI command performance data is unreliable — traces don't capture actual duration or child operations
  • Debugging Seer/autofix integration issues from Sentry is impossible without accurate traces

Likely cause

The cli.command root span wraps the callback return in startSpanManual, but the generator-based command pattern (async *func + yield CommandOutput) may resolve the callback promise before the generator is fully drained. The span's finally block calls span.end() at that point.

References

  • src/lib/telemetry.ts:208startSpanManual root span
  • src/commands/issue/plan.tsasync *func generator pattern
  • src/lib/command.ts — command runner that consumes the generator

Action taken on behalf of Burak Yigit Kaya.

Metadata

Metadata

Labels

No labels
No labels
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions