Skip to content

WO-1582 Refactor tracing span implementations - #7093

Open
jmorrell-cloudflare wants to merge 1 commit into
mainfrom
jmorrell/refactor-spans
Open

WO-1582 Refactor tracing span implementations#7093
jmorrell-cloudflare wants to merge 1 commit into
mainfrom
jmorrell/refactor-spans

Conversation

@jmorrell-cloudflare

@jmorrell-cloudflare jmorrell-cloudflare commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Preparatory work for tracing.getActiveSpan

We've ended up with branching logic within SpanImpl. Mostly now it's whether the span is observed or not:

if (!builder.isObserved()) {
  return;
}

In the next PR I'll be introducing the Invocation span, which will have it's own set of logic. Most notably that we should ignore .end() as a no-op since that is owned by the platform. This will have more branching logic.

export default function fetch(...) {
  // get the root span for the invocation
  const span = ctx.tracing.getActiveSpan();

  // this is cool, and we want to encourage thsi
  span.setAttributes({ "user.id": 123 });

  // but if a user does this, we need to ignore it
  span.end(); 
}

And we're likely going to end up with a 4th case, which otel calls a NonRecordingSpan where a span is created representing the remote span that is also a no-op, but does allow children to be created.

const span = tracing.trace.wrapSpanContext({
  traceId: '0123456789abcdef0123456789abcdef',
  spanId: '2222222222222222',
  traceFlags: 1,
});

With that in mind, this moves SpanImpl into the SpanState interface, where we can provide multiple implementations. For now UserSpanState and NoopSpanState.

If this winds up being easier to review with the next change, I'm happy to combine them.

@ask-bonk

ask-bonk Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@jmorrell-cloudflare
jmorrell-cloudflare marked this pull request as ready for review August 24, 2026 23:59
@jmorrell-cloudflare
jmorrell-cloudflare requested review from a team as code owners August 24, 2026 23:59
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.

1 participant