You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(telemetry): address PR #3847 review follow-ups for trace correlation (#4058)
* fix(telemetry): address PR #3847 review follow-ups for trace correlation
Addresses unresolved review feedback from PR #3847:
- Respect OTEL_TRACES_SAMPLER env var when setting TraceFlags on the
synthetic session root, so custom samplers (e.g. traceidratio) are
not bypassed by forced SAMPLED flag
- Store current session ID in session-context.ts and use it as a
fallback in LogToSpanProcessor when the OTel Resource session.id
attribute is stale after /clear or /resume
- Wrap for-await loop body in runInSpan() so debug logs emitted
during stream iteration see the stream span as active
- Add autoOkOnSuccess option to withSpan, eliminating the need for
the load-bearing setStatus(UNSET) hack in cancellation paths
- Add defensive 5-minute timeout for stream spans to prevent leaks
from abandoned generators
🤖 Generated with [Qwen Code](https://github.com/QwenLM/qwen-code)
* fix(telemetry): address review issues in PR #4058
- Fix sdk.test.ts assertion to match new two-arg setSessionContext call
- Add spanEnded guard to prevent double span.end() when timeout fires
- Add .trim() to OTEL_TRACES_SAMPLER env var for robustness
- Pass sessionId in debugLogger.test.ts for signature completeness
- Clarify log-to-span-processor comment: fallback covers "missing" not "stale"
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(telemetry): adopt review feedback for sampler and idle timeout
- Fix shouldForceSampled to force SAMPLED for all parentbased_* samplers,
not just parentbased_always_on — parentbased samplers delegate to
localParentNotSampled (default AlwaysOff) when parent has NONE, which
silently drops all traces
- Convert stream span timeout from fixed wall-clock to idle timeout:
reset timer on each chunk so legitimately long streams are never
affected; timeout only fires when no chunks arrive for 5 minutes
- Add test for parentbased_traceidratio → TraceFlags.SAMPLED
* fix(telemetry): guard resetSpanTimeout against already-ended span
Prevent zombie timer accumulation when chunks arrive after idle timeout
has already ended the span.
* fix(telemetry): handle parentbased_always_off sampler and fill test gaps
- shouldForceSampled() now returns false for parentbased_always_off,
preventing silent over-sampling that contradicts user intent.
- Updated JSDoc to document the always_on exception for non-parentbased
samplers.
- Added test for parentbased_always_off → TraceFlags.NONE.
- Added test for success path resilience when safeSetStatus throws in
coreToolScheduler.
* fix(telemetry): harden span timeout ordering and session ID fallback
- Swap spanEnded/span.end() order so finally block can retry if end()
throws.
- Clear idle timeout immediately after for-await loop exits, before
post-loop processing.
- Use || instead of ?? for session.id fallback to handle empty strings.
* fix(telemetry): address review round 4 — docs, cleanup, and test gaps
- Expand shouldForceSampled JSDoc: document env-var assumption,
parentbased_traceidratio 100% sampling semantics.
- Remove unnecessary runInSpan wrapper around chunk field assignments.
- Add stream.timed_out span attribute when idle timeout fires.
- Deduplicate config.getSessionId() call in initializeTelemetry.
- Add tests for always_on and always_off sampler values.
* fix(telemetry): harden timeout callback ordering and add || comment
- Move safeSetStatus before setAttribute in timeout callback so ERROR
status is set even if setAttribute throws.
- Set spanEnded=true before span.end() so finally block never overwrites
ERROR with OK if end() throws.
- Add comment explaining || vs ?? choice for session.id fallback.
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
0 commit comments