Skip to content

Conversation

@schickling
Copy link
Contributor

@schickling schickling commented Dec 10, 2025

Summary

Fix Tracer.currentOtelSpan to work with both OpenTelemetry SDK and OTLP module.

Problem

Tracer.currentOtelSpan did not work with the lightweight OTLP module (OtlpTracer.layer) because it checked for a special symbol marker (OtelSpanTypeId) that OTLP spans do not have. This caused it to always return NoSuchElementException when using OTLP.

See #5889 for details.

Solution

Make currentOtelSpan work with both approaches:

  • Official OpenTelemetry SDK: Returns the actual Otel.Span object (unchanged behavior)
  • OTLP module: Returns a read-only wrapper that:
    • Provides spanContext() with correct traceId, spanId, traceFlags
    • Has no-op implementations for mutating methods (setAttribute, addEvent, etc.)
    • Returns false from isRecording() to indicate it is not a recording span

Test plan

  • Added test for currentOtelSpan with OTLP module
  • All existing tests pass

Closes #5889

🤖 Generated with Claude Code

@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Dec 10, 2025
@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 840371a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/opentelemetry Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@schickling schickling force-pushed the schickling/otel-currentspan-bug branch from 57359d3 to 9b1f94c Compare December 10, 2025 16:32
Make `currentOtelSpan` work with both the official OpenTelemetry SDK and
the lightweight OTLP module. When using OTLP, it returns a read-only wrapper
that provides `spanContext()` with the correct traceId, spanId, and traceFlags.
The wrapper has no-op implementations for mutating methods since OTLP spans
are managed differently.

Closes #5889

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@schickling schickling force-pushed the schickling/otel-currentspan-bug branch from 9b1f94c to 9a19ff3 Compare December 10, 2025 20:03
@schickling schickling changed the title Add Tracer.currentSpanContext API for OTLP compatibility Fix Tracer.currentOtelSpan to work with OTLP module Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

OtelTracer.currentOtelSpan doesn't work with OTLP module

3 participants