Skip to content

docs(trace): clarify that startActiveSpan requires manual span.end()#6633

Merged
david-luna merged 1 commit into
open-telemetry:mainfrom
raphaeltorquat0:fix/issue-5905-startActiveSpan-docs
May 19, 2026
Merged

docs(trace): clarify that startActiveSpan requires manual span.end()#6633
david-luna merged 1 commit into
open-telemetry:mainfrom
raphaeltorquat0:fix/issue-5905-startActiveSpan-docs

Conversation

@raphaeltorquat0
Copy link
Copy Markdown
Contributor

Which problem is this PR solving?

The JSDoc for startActiveSpan does not make it clear that the callback function is responsible for calling span.end(). Users coming from other OpenTelemetry implementations (like Go) where spans are automatically ended may silently lose spans when using the JavaScript SDK.

This PR adds explicit documentation warning that:

  1. The callback is responsible for calling span.end()
  2. The span is NOT automatically ended when the callback returns
  3. If span.end() is not called, the span will never be exported

Fixes #5905

Short description of the changes

Added an "Important" note to the JSDoc for startActiveSpan in both:

  • api/src/trace/tracer.ts (the interface)
  • packages/opentelemetry-sdk-trace-base/src/Tracer.ts (the implementation)

The note explicitly states that span.end() must be called by the callback function, otherwise the span is silently lost.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Note: parts of this implementation were developed with AI assistance.


CLA Status: I have signed the Contributor License Agreement for this project.

@raphaeltorquat0 raphaeltorquat0 requested review from a team as code owners April 26, 2026 14:51
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 26, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: raphaeltorquat0 / name: Raphael Torquato (f73f7b0)

Add explicit documentation noting that the callback function is
responsible for calling span.end() to finish the span. Unlike some
other OpenTelemetry implementations, the span is NOT automatically
ended when the callback returns. If span.end() is not called, the
span will never be exported and will be silently lost.

Fixes open-telemetry#5905
@raphaeltorquat0 raphaeltorquat0 force-pushed the fix/issue-5905-startActiveSpan-docs branch from cb33c1a to f73f7b0 Compare April 26, 2026 14:54
Copy link
Copy Markdown
Member

@raphael-theriault-swi raphael-theriault-swi left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.70%. Comparing base (4c0f3f1) to head (f73f7b0).
⚠️ Report is 58 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6633   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files         375      375           
  Lines       12921    12921           
  Branches     3090     3090           
=======================================
  Hits        12366    12366           
  Misses        555      555           
Files with missing lines Coverage Δ
...ackages/opentelemetry-sdk-trace-base/src/Tracer.ts 98.71% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@david-luna david-luna added this pull request to the merge queue May 19, 2026
Merged via the queue into open-telemetry:main with commit c990aff May 19, 2026
28 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented May 19, 2026

Thank you for your contribution @raphaeltorquat0! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

# startActiveSpan silently fails when callback returns void - causing spans to be lost

3 participants