Skip to content

Synchronous spans

Auto-instrumentation wraps every middleware function and many library calls in a span. Many of these spans start and end without waiting on anything, such as a CORS check, middleware that calls the next function directly, or a template helper. They add rows to every trace but say little about where the time went. Synchronous Span Handling drops them as they end, unless a keep rule matches.

A span is synchronous when it starts and ends with no await in between, so both happen in the same microtask. An await makes a span asynchronous, even if the awaited call resolves without doing any I/O.

SpanSlice decides a synchronous span as soon as it ends, not when its trace ends:

  • Its children move up to its parent, so the trace stays connected. Spans that start under it later attach to its nearest kept ancestor as well.
  • It leaves memory right away. It still counts toward Trace Span Count.
  • A span that a rule already removed with Drop Span or Collapse Span stays removed. A rule that only sets attributes doesn’t keep the span.
  • An errored span is held with its trace instead, so trace rules such as Drop Traces Without Errors can see the error. The span is dropped when the trace is sent, unless a keep rule matches it. For example, a keep rule can use Has Error is true.

A synchronous span is kept if any keep rule matches it. SpanSlice checks the service’s keep rules first, then the project’s. Keep rules can test what’s known once the span ends, without the rest of its trace:

Condition Operators
Span Name, Library Name, Span Attribute, Resource Attribute as in rules
Span Kind is, is not, in, not in
Span Duration =, >, >=, <, <=, between
Has Error is true, is false
Is Root Span, Is Child Span none: whether the span has a parent in this process
Has Child Spans none: whether a child of the span will still be sent

Has Child Spans is only available in keep rules. SpanSlice decides it when the span ends, from the children still sent by then:

  • A child dropped along with its own subtree doesn’t count.
  • A child dropped on its own counts through its kept children.

In the animation, render is dropped once escape, its only child, is dropped.

New projects start with two keep rules:

  • Is Root Span, so a trace’s root is never dropped and the trace isn’t split.
  • Has Child Spans, so a synchronous span that starts asynchronous work stays as that work’s parent.

The Drop Synchronous Spans switch on the Synchronous Span Handling page turns dropping off for a service in an environment. Every synchronous span is then kept, and it goes through your rules like any other span.