Spans

Span creation, sampling, filtering, buffering, and wire format for the span-first tracing model.

Statusstable
Version1.2.0(changelog)

Spans are the primary telemetry type for Sentry's performance monitoring. A span measures the duration of an operation and carries attributes, links, and status information. This spec covers the span-first ("span streaming") model where spans are sent individually in batched envelopes rather than grouped into transaction events.

The APIs specified in this document MUST be implemented by all SDKs that don't use OpenTelemetry as their underlying tracing implementation. SDKs using OTel SHOULD follow their own already established span APIs but MAY orient themselves on this document if applicable.

Related specs:


Span: A timed operation with a name, attributes, status, and parent relationship. Spans form trees within a trace.

Root Span: The topmost span in a distributed span tree. It has no parent span. Groups its children with a representative name such as GET /.

Segment Span: The topmost span within a service boundary. Has a parent_span_id pointing to a remote span from the upstream service. A segment span on the originating service is also the root span of the entire tree.

Noop Span: A span implementing the full Span Interface that records no data and has no influence on the trace hierarchy. Returned when a span should not be recorded.

Active Span: A span attached to the current scope. Child spans started while an active span exists become its children.

Span-First / Span Streaming: The traceLifecycle: 'stream' mode where spans are captured individually via captureSpan, buffered, and sent in batched envelopes — as opposed to the legacy transaction model (traceLifecycle: 'static').

SDKs MUST NOT expose names like "segment span" to users and SHOULD NOT expose "root span" if avoidable.


Stablespecified since 1.0.0

SDKs that support both transaction-based tracing and span streaming MUST expose a top-level traceLifecycle (or trace_lifecycle) init option controlling whether traces are sent as transactions or as spans (v2).

  • Allowed values MUST be 'static' and 'stream'.
  • When span-first is introduced in a minor version, the SDK MUST default to 'static' (transaction-based) and span-first MUST be an opt-in feature.
  • Span-first behavior MUST only apply when traceLifecycle is set to 'stream'.
  • This option can be removed once support for transactions is removed from the SDK.
Stablespecified since 1.0.0

SDKs MUST expose at least one API to start a span. SDKs MAY expose additional APIs or variants of startSpan, depending on the platform, language conventions, and requirements (e.g. decorators, annotations, or closure- or callback-based APIs).

  • Spans MUST be started as active by default. Any span started while another span is active MUST become a child of the active span.
  • If active: false, the span MUST be started as inactive — spans started while it is running MUST NOT become its children, but siblings.
  • If a Span is passed via parentSpan, it MUST take precedence over the currently active span.
  • If null is passed via parentSpan, the new span MUST be started as a segment span.
  • SDKs MUST NOT end spans automatically from the default startSpan API. SDKs MAY provide additional APIs that auto-end spans (e.g. callback-based, context managers). Additional APIs MAY also adjust the span status based on errors thrown.
  • startSpan MUST always return a span instance, even if the trace is negatively sampled. See Noop Span for details.

The span-first API MUST NOT expose old transaction properties or concepts (e.g. op, description, tags).

SDKs MUST NOT expose APIs like Span::startChild. The parentSpan option serves this purpose.

Copied
function startSpan(options: StartSpanOptions): Span;

interface StartSpanOptions {
  name: string;
  attributes?: Record<string, SpanAttributeValue>;
  parentSpan?: Span | null;
  active?: boolean;
  links?: SpanLink[];
}
OptionRequiredDescription
nameYesSpan name. MUST be set by users.
attributesNoInitial attributes. See Attributes at Span Start.
parentSpanNoParent span. See three-state behavior.
activeNoWhether the span should be active (default: true).
linksNoInitial span links.

The parentSpan parameter has three states: undefined, null, and a span instance.

For languages without an undefined state, SDKs SHOULD model this using platform-appropriate mechanisms that preserve the semantic distinction between undefined and null, such as:

  • Method/constructor overloading (e.g. an overload without parentSpan, and another accepting parentSpan: Span?)
  • A default sentinel value/object representing undefined
  • Other idiomatic platform mechanisms (e.g. enum types)

If parentSpan references a span that has already ended, the SDK SHOULD still create the new span and send it as a child of parentSpan. Handling and presentation of these relationships is deferred to downstream processing and the UI.

Instrumentations MUST pass attributes whose values are already available at span start via the attributes option, rather than setting them afterward with setAttribute or setAttributes. This ensures these attributes are available when evaluating ignoreSpans and, where applicable, tracesSampler.

Attributes whose values only become available later MAY be set after span start.

Stablespecified since 1.0.0

It MUST be possible to attach a span to a scope. In SDKs implementing the three-scope model, the span SHOULD be set on the current scope.

When a span is attached to a scope, a reference to the previous span MUST be stored. The previous span MUST be re-attached when the currently active span ends.

If a span is started with active: true, it MUST be attached to the scope. If active: false, it SHOULD NOT be attached to the scope.

If a Noop span would be a segment (no currently active span, or parentSpan: null), it MAY be set on the scope so children inherit its negative sampling decision.

Stablespecified since 1.0.0

A Noop span implements the full Span Interface but records no data and has no influence on the trace hierarchy.

startSpan MUST always return a valid Span instance. If a span should not be recorded, the SDK MUST return a Noop span instead. This allows callers to use the span without null checks.

startSpan MUST return a Noop span in the following scenarios:

  • The span's trace is negatively sampled.
  • The span matches an ignoreSpans pattern.

  • All mutating methods (setAttribute, setAttributes, removeAttribute, setStatus, setName, addLink, addLinks, end) MUST be no-ops — they MUST NOT record or store data.
  • Getter methods (getName, getAttributes) SHOULD return empty/default values.
  • A Noop span MUST NOT be sent to Sentry.
  • If a Noop span is active, its dummy properties MUST NOT populate outgoing trace headers. Headers MUST be populated from the propagation context instead. Custom APIs like getTraceparent and getBaggage MUST also use the propagation context.
  • A Noop span MUST NOT become the parent of another non-Noop span. Spans that would otherwise be its children MUST use the Noop span's nearest non-Noop ancestor as their parent. If there is no such ancestor (the Noop span is a segment), those spans MUST also be Noop spans, inheriting its sampling or filtering decision.

For platforms with non-nullable span properties:

PropertyDefault Value
traceId00000000000000000000000000000000 or random uuid (32 zero hex chars)
spanId0000000000000000 or random uuid (16 zero hex chars)
nameEmpty string ""
attributesEmpty map {}
linksEmpty array []
statusok

SDKs SHOULD use these default values even on platforms that support nullable types, so callers don't need null checks. In particular, name, attributes, links, and status SHOULD NOT be nullable.

Stablespecified since 1.0.0

Sampling MUST only apply to segment spans. The APIs MUST be optimized for trace completeness and conclusive sampling decisions. SDKs MUST follow the sampling decision hierarchy.

The SDK MUST default tracesSampleRate to null. When users set tracesSampleRate to a value in [0.0, 1.0] and starting a segment span, the tracesSampleRate is compared against a random number in [0.0, 1.0).

If configured, tracesSampler MUST replace tracesSampleRate. The callback MUST receive sufficient arguments for users to define custom rules (e.g. span attributes, HTTP headers). The return value MUST be a float in [0.0, 1.0].

If no tracesSampler is configured, a propagated sampling decision via the traceparent takes precedence over tracesSampleRate. Defining a tracesSampler MAY disable this behavior.

Stablespecified since 1.0.0

The SDK MUST implement a mechanism for users to filter spans. The result MUST be binary (true or false). Any filtering APIs MUST be optimized for trace completeness and conclusive sampling decisions.

The ignoreSpans option MUST accept a string and either RegExp or glob pattern (whichever the platform supports) matched against the span name.

Furthermore, ignoreSpans SHOULD accept objects with patterns matching the span name and/or span attributes:

Copied
type IgnoreSpanNamePattern = string | RegExp | GlobPattern;

type AttributeValueTypes = string | boolean | number | Array<string> | Array<boolean> | Array<number>;
type EnhancedAttributeValueTypes = AttributeValueTypes | RegExp | GlobPattern | Array<RegExp | GlobPattern>;

type IgnoreSpanFilter = {
  name: IgnoreSpanNamePattern;
  attributes?: Record<string, EnhancedAttributeValueTypes>;
} | {
  name?: IgnoreSpanNamePattern;
  attributes?: Record<string, EnhancedAttributeValueTypes>;
}

type IgnoreSpans = Array<IgnoreSpanNamePattern | IgnoreSpanFilter>

(GlobPattern is used as an illustrative type for platforms that support matching glob patterns. It is not a valid TypeScript type.)

If an SDK accepts IgnoreSpanFilter objects, string attribute values MUST be matched the same way as span names (contains for strings, match for patterns). Other attribute value types MUST strictly equal the provided value. This includes attributes whose values are arrays.

The integrations option MAY perform in similar fashion as the ignoreSpans option, or make explicit opt-out possible via a boolean flag.

Copied
Sentry.init({
  integrations: [
    Sentry.fsIntegration({
      ignoreSpans: ['fs.read'],
      readSpans: true,
      writeSpans: false,
    }),
  ],
});

If both options mentioned above are not feasible to be implemented in certain SDKs, other approaches MUST be explored that have the same outcome.

  1. ignoreSpans patterns MUST be evaluated before the span is started.
  2. Patterns MUST apply to all spans, including segment spans.
    • If a pattern matches a segment span, the span and all its children MUST be ignored.
    • If a pattern matches a child span, the child MUST be ignored but its children MUST be attempted to be reparented to the ignored span's parent.
  3. If a span is ignored, the SDK MUST record a client report with the ignored discard reason and span category.
    • For each ignored child span, emit one outcome per span.
    • For each ignored segment span, emit one outcome for the segment and one per child span.
Stablespecified since 1.0.0

The beforeSendSpan callback MUST NOT allow removal of spans from the span tree. It receives a deep copy of a span:

Copied
{
  'name': 'GET /',
  'attributes': {
    'http.request.method': 'GET',
    'http.response.status_code': 200,
  }
}

Users MAY mutate any exposed properties to perform sanitization on sensitive data or PII. The return value MUST be merged with the original span prior to emission.

Stablespecified since 1.0.0

The SDK MUST expose a method to extract traceparent and baggage from incoming headers and apply them to the applicable scope. The method MUST NOT create a new segment span on its own. Newly created root spans SHOULD contain the extracted properties, such as trace_id and parent_span_id.

The function signature MAY require explicitly passing sentry-trace and baggage, or MAY accept a dictionary of headers or environment variables.

The SDK MUST expose methods to fetch the required information (traceparent, baggage) for downstream services to continue the trace.

The SDK MUST offer a method to clear trace propagation data, allowing spans to be created with a fresh new trace.

Stablespecified since 1.0.0

SDKs MUST implement a captureSpan API that takes a single span once it ends, processes it, and enqueues it into the span buffer. This SHOULD be a method on the Client. SDKs (e.g. JS Browser) MAY choose a different location if necessary.

Processing order:

  1. Accept any span that has ended (has an end_timestamp).
  2. Obtain current, isolation, and global scopes; merge scope data.
  3. Apply common span attributes from client and merged scope data to every span.
  4. Apply scope attributes to every span.
  5. Apply contexts and request data from merged scopes to the segment span only.
  6. Apply span processing hooks (event processor replacements).
  7. Apply beforeSendSpan.
  8. Enqueue the span into the span buffer.

The captureSpan pipeline MUST NOT:

  • Drop any span
  • Buffer spans before enqueuing
  • Modify span relationships

ignoreSpans is applied prior to span start, so captureSpan does not handle filtering. This means certain cases cannot be handled by the pipeline:

  • Filtering spans based on data that is unknown prior to child span start.
  • Filtering entire segments based on data that is unknown prior to segment start (e.g. http.server segments ending in a 404 response).

Streamed spans are no longer events (as opposed to transactions), so they don't go through SDK event processors, which are used extensively by SDK clients, integrations, and users. For user-facing migration, ignoreSpans covers filtering and beforeSendSpan covers data enrichment and scrubbing.

For SDK-internal processing, SDKs are free to implement further processing mechanisms. It's strongly recommended to implement client lifecycle hooks. SDKs with alternative established processing patterns MAY use those instead. The captureSpan pipeline emits a process_span message that any consumer (e.g. an integration) can subscribe to and apply its logic, similar to how it previously used event processors:

Copied
// in captureSpan:
processed_span = client.emit("process_span", captured_span)

// Somewhere in e.g. an integration:
client.on("process_span", (span) => {
   span.attributes["sentry.origin"] = "auto.http.server"
})

With a few exceptions, event processors for transactions do two things:

  1. Add and modify transaction and child span data.
  2. Drop transaction events or remove child spans.

Replace the mutation logic with span processing hooks. SDK-internally, configure the integration or call site that registers an event processor to also register a hook (e.g. a client lifecycle hook) that processes the span:

Copied
// someIntegration:

client.addEventProcessor(event => {
   event.transaction = parameterizedRouteName;
   event.context.trace.data["http.route"] = parameterizedRouteName;
   event.spans.foreach(s => {s.data["http.route"] = parameterizedRouteName});
})

// for span streaming, add:
client.on("process_span", (span) => {
   if (span.is_segment) {
      span.name = parameterizedRouteName;
   }
   span.attributes["http.route"] = parameterizedRouteName;
})

Ideally, replace retroactive filtering in event processors by configuring the integration to not emit these spans upfront. This should be the first approach when implementing span streaming.

If this doesn't apply to the use case, pre-configure the SDK's ignoreSpans option and leverage the existing span filtering logic to drop segments or child spans upfront:

Copied
// someIntegration:

client.addEventProcessor(event => {
   if (event.type === "transaction" && event.transaction === "unknown") {
      return null;
   }
   return event;
})

// for span streaming, add:
client.options.ignore_spans = [
   ...client.options.ignore_spans,
   /^unknown$/
];

If the SDK also implements ignoreSpans for transactions, this might allow removing the event processor entirely.

The following use cases cannot be directly replaced with span streaming:

  • Filtering spans based on data added after span start (e.g. a span attribute that only gets added to the span after it was started).
  • Filtering entire segments based on data unknown at segment start (e.g. http.server segments ending in a 404 response).
  • Mutating or making decisions on multiple spans at once (e.g. calculating and setting the total token usage on parent spans of gen_ai spans). There's no guarantee that all spans are seen in time to safely aggregate their data. Previously, this was trivial by iterating over event.spans. Now, it would require a guarantee that child spans finish before their parent span, which often doesn't exist.
  • Scoped event processors — currently not supported; can be re-evaluated if a use case arises that can't be solved with client-wide processing hooks.

These limitations reflect the current span streaming strategy and might be reconsidered based on feedback and demand.

Spans no longer going through event processors is a behavior-breaking change. For users, ignoreSpans and beforeSendSpan are the way forward. Internally, SDKs MAY use further processing mechanisms.

Stablespecified since 1.0.0

The span buffer batches spans, constructs envelopes, and forwards them to the transport. Spans are captured via captureSpan and enqueued into the span buffer instead of being sent as transaction events.

These requirements intentionally specify less than the Telemetry Processor. SDKs MAY implement and extend the span buffer with platform-specific behavior, as long as the core requirements are met.

  1. The buffer MUST bucket spans by trace ID. When flushing, the buffer MUST create distinct envelopes for each trace ID.
  2. The buffer MUST NOT add more than 1000 spans per envelope. If more than 1000 spans are held for a trace, the buffer MUST batch into multiple envelopes.
  3. When the buffer drops spans, it MUST record a client report with the exact number of spans dropped.
  4. The buffer MAY ignore priority-based scheduling with other telemetry categories.
  5. The buffer MUST implement the following flushing behavior:
    • Flush on a regular interval, every 5 seconds (SDKs MAY adjust based on platform needs).
    • Flush a trace bucket when its segment span is finished.
    • Flush a trace bucket when it reaches the 1000 spans limit.
    • Flush when a trace bucket reaches 5MB (SDKs MAY adjust, but MUST NOT exceed 10MB).
    • Flush when Sentry.flush() is called.
    • Flush and stop on Sentry.close(). The buffer MUST stop accepting new spans to prevent unbounded memory use.

A recommended design is a map of trace ID → list of spans. SDKs MAY use other structures (e.g. a fixed ring buffer) as long as the requirements above are met.

Copied
spanBuffer = {
  "trace-a": [span1, span2, span3],
  "trace-b": [span4],
  "trace-c": [span5, span6]
}

When the span buffer adds a span, it MUST add it to the bucket for that span's trace ID. When no bucket exists, it MUST create one. After forwarding spans from a bucket, it MUST remove all spans and delete the bucket.

SDKs SHOULD materialize and freeze the DSC as late as possible:

  • The buffer SHOULD enqueue spans but only create the final envelope at flush time.
  • At flush time, the buffer SHOULD materialize and freeze the DSC on the segment span if not already done. That way, the trace envelope header (e.g. the transaction name in the DSC) reflects the latest data.
Candidatespecified since 1.1.0

SDKs MUST record a client report with the span data category in at least the following cases:

  • sample_rate: the span was not recorded because its trace was negatively sampled, so a Noop span was returned instead. SDKs SHOULD record one outcome per Noop span.
  • ignored: the span matched an ignoreSpans pattern. See the filtering implementation requirements for how to count ignored segments and their children.
  • no_parent_span: the span was not started because no parent span was present (for example, auto-instrumented spans that are only created within an active span).
  • buffer_overflow: the span buffer dropped the span.
  • ratelimit_backoff: the span was dropped because the span data category is rate limited.
  • send_error, internal_sdk_error, network_error: the envelope containing the span was discarded because sending it failed, as specified in Network Failure Recording.

The quantity MUST be the number of discarded spans, not the number of discarded envelopes or envelope items. For example, if a span envelope with 500 spans fails to send, the SDK records a span quantity of 500 (see Quantity of Discarded Envelopes).

Candidatespecified since 1.0.0

To associate an attachment with a span, submit a trace attachment item with an additional span_id item header. The trace attachment MUST be submitted in the same envelope as the span itself.

  • span_id identifies the owning span. Relay treats span_id as the owner of the attachment: the attachment is dropped with the span if the span is dropped by dynamic sampling, inbound filters, or rate limits.
  • The SDK MAY set span_id to explicit null, meaning "owned by spans" but not by a specific one — the attachment can be dropped if span quota is exceeded, but it will not be dropped with a specific span because of, for example, inbound filters.
Stablespecified since 1.0.0

Attributes outside the common attribute keys list MUST only be attached to the span they conceptually belong on, and MUST NOT be propagated to children. Attributes mirroring transaction context data SHOULD only be set on the segment span.

All attributes set on a streamed span MUST use keys defined in Sentry Conventions before introduction in an SDK.

Empty attributes MUST be omitted.

Guidelines for specific attributes:

  • http.request.body.data: Attach on a best-effort basis, as long as it can be done without side effects like exhausting the body before the user/app can read it. Decide per SDK/integration whether this is feasible.

HTTP headers MUST be emitted following the http.request.header.<key> and http.response.header.<key> conventions:

  • <key> MUST be the lowercased, but otherwise unchanged, header name.
  • The value MUST be a string array, even if the header has a single value. Multiple values for the same header MUST be emitted as separate array elements.
  • Request and response headers MUST be collected according to the httpHeaders option. If collection is disabled for a direction, those headers MUST be omitted. Values of headers matching the sensitive denylist MUST be replaced with "[Filtered]" while the key is kept. The sensitive denylist applies in every collection mode, including when collection is fully enabled.

Cookie and Set-Cookie headers MUST be collected according to the cookies option instead of httpHeaders. They are emitted as http.request.header.cookie and http.<request|response>.header.set-cookie. If cookie collection is disabled, these attributes MUST be omitted, even if header collection is enabled.

The header value MUST be parsed into individual cookies:

  • A Cookie header MUST be split on ;. For a Set-Cookie header, only the part before the first ; MUST be used, so cookie attributes like HttpOnly or Path are dropped. Each Set-Cookie header value holds one cookie.
  • Name and value MUST be split on the first = only (jwt=eyJhbGc= has the value eyJhbGc=). Both MUST be trimmed.
  • Empty segments and segments consisting only of = MUST be skipped.
  • A segment without = is a nameless cookie whose whole segment is the value.

Each cookie MUST be emitted as its own name=value array element, in header order:

  • Values MUST NOT be decoded or unquoted.
  • If the cookie name matches the sensitive denylist, the value MUST be replaced: name=[Filtered]. SDKs SHOULD also match cookie names against additional cookie-specific terms for session and auth cookies whose names don't match the denylist, such as .sid, sessid, remember, oidc, pkce, nonce, __secure-, __host-, mfa, and 2fa.
  • A nameless cookie MUST be emitted as [Filtered], since no name-based denylist can match it.
  • If the header yields no cookies, the value MUST be ["[Filtered]"], since the header may still hold a token.

If the framework already provides parsed cookies, SDKs SHOULD use those pairs instead of serializing and re-parsing them. A decoded value can contain ; and would otherwise split into a second, differently named cookie that escapes the denylist.

Copied
{
  "http.request.header.accept": {
    "type": "array",
    "value": ["application/json"]
  },
  "http.request.header.authorization": {
    "type": "array",
    "value": ["[Filtered]"]
  },
  "http.request.header.cookie": {
    "type": "array",
    "value": [
      "user_session=[Filtered]",
      "connect.sid=[Filtered]",
      "theme=dark-mode"
    ]
  },
  "http.response.header.set-cookie": {
    "type": "array",
    "value": ["theme=light-mode"]
  }
}

The envelope header MUST contain the same properties as previously with transactions. There are no special requirements beyond those for standard envelopes.

Copied
{
  "sent_at": "2025-02-07T14:16:00Z",
  "dsn": "https://e12d836b15bb49d7bbf99e64295d995b@sentry.io/42",
  "sdk": {
    // ...
  },
  "trace": {
    // ...
  }
}

Unlike transactions, envelope headers for spans REQUIRE Dynamic Sampling Context. See also Envelope Headers.

To guarantee a DSC for every span envelope, SDKs implementing span streaming MUST follow version 1.4.0 or later of the DSC spec.

PropertyTypeRequiredDescription
typestringYesMUST be "span"
item_countintegerYesNumber of span items in the payload
content_typestringYesMUST be "application/vnd.sentry.items.span.v2+json"

The payload is a JSON object that MUST include an items array of span objects.

The items array MUST contain at least one and at most 1000 span objects. An envelope MUST only contain spans from one trace, as the trace envelope header is shared.

Candidatespecified since 1.0.0

The payload SHOULD include top-level version and ingest_settings fields to instruct Relay to infer IP address and user agent from the incoming request:

Copied
{
  "version": 2,
  "ingest_settings": {
    "infer_ip": "auto",
    "infer_user_agent": "auto"
  },
  "items": [{..span..}, {..span..}]
}

See the Ingest Settings spec for the full ingest_settings field reference.

PropertyTypeRequiredDescription
trace_idstringYes32-character lowercase hexadecimal string (a valid uuid4 without dashes)
span_idstringYes16-character lowercase hexadecimal string (a valid uuid4 without dashes)
parent_span_idstringNo16-character lowercase hexadecimal string (a valid uuid4 without dashes)
namestringYesLow-cardinality description (e.g. "GET /users")
statusstringYesEither "ok" or "error"
is_segmentbooleanYesWhether the span is a segment span
start_timestampnumberYesUnix timestamp with fractional microseconds
end_timestampnumberYesUnix timestamp with fractional microseconds
attributesobjectNoKey-value pairs of additional metadata
linksarrayNoArray of link objects connecting to other spans

Strictly Required and Required attributes MUST be attached to every span emitted from the SDK. Conditional attributes MUST be attached to every span when their condition is met.

Attribute KeyTypeRequiredDescription
sentry.segment.namestringStrictly RequiredSegment name (e.g. "GET /users")
sentry.segment.idstringStrictly RequiredSegment span ID
sentry.trace_lifecyclestringRequiredThe trace lifecycle mode. MUST be set to "stream".
sentry.sdk.namestringRequiredSentry SDK name
sentry.sdk.versionstringRequiredSentry SDK version
sentry.originstringRequiredTrace origin
sentry.platformstringRequiredPlatform identifier
user_agent.originalstringRequiredFull, unmodified user agent string of the client that made the request, e.g. the User-Agent header of an incoming request to a web backend (e.g. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...")
sentry.opstringConditionalThe span op (e.g. "http.client", "db.query"). MUST be set on spans from auto instrumentation, MAY be set by manually started spans.
sentry.segment.name.sourcestringConditionalSource of the segment name. MUST be set on segment spans, and MUST NOT be set on any other span. See Sentry Conventions for all supported sources and Transaction Annotations for more information.
sentry.releasestringConditionalApplication release version. Set if the SDK has a release value set or auto-detected.
sentry.environmentstringConditionalEnvironment name (e.g. "production", "staging"). Set if the SDK has an environment value set or uses a default.
sentry.is_localhostbooleanConditionalWhether the SDK determined the application is running on localhost. Used to enable the localhost inbound filter. The definition of "localhost" is platform-specific. Set by browser and backend SDKs.
sentry.profiler_idstringConditionalID of the running continuous profiler. Set while a continuous profiling session is running. MUST NOT be set otherwise.
sentry.replay_idstringConditionalID of the active replay. Set while a replay is active. MUST NOT be set otherwise.
os.namestringConditionalOperating system name. Set if available on the platform.
browser.namestringConditionalBrowser name. Set by browser SDKs if available.
user.idstringConditionalUser ID. Set if user data is available (see below).
user.emailstringConditionalUser email. Set if user data is available (see below).
user.ip_addressstringConditionalUser IP address. Set if user data is available (see below).
user.namestringConditionalUser username. Set if user data is available (see below).
thread.idintegerConditionalThread ID. Set on platforms that expose thread information.
thread.namestringConditionalThread name. Set on platforms that expose thread information.

Spans missing Strictly Required attributes MAY be rejected by Relay.

User attributes (user.*) MUST respect the userInfo option. User data populated automatically by the SDK MUST NOT be attached if userInfo is disabled. User data set explicitly by the user (e.g. via setUser) MUST be attached regardless of userInfo.

Empty attributes MUST be omitted.

See Sentry Conventions for a full list of supported attributes.

Each attribute value is an object with type, value, and optional unit:

Copied
{
  "sentry.release": {
    "type": "string",
    "value": "1.0.0"
  },
  "http.response.status_code": {
    "type": "integer",
    "value": 200
  },
  "session.duration": {
    "type": "integer",
    "value": 164,
    "unit": "second"
  }
}
PropertyTypeRequiredDescription
span_idstringYes16-character hexadecimal string (a valid uuid4 without dashes)
trace_idstringYes32-character hexadecimal string (a valid uuid4 without dashes)
sampledbooleanNoWhether the linked trace was sampled
attributesobjectNoMetadata about the link relationship

Timestamps use Unix time with fractional microseconds: 1742921669.158209

Trace ID: 32-character (128-bit) lowercase hexadecimal string (a valid uuid4 without dashes).

Span ID: 16-character (64-bit) lowercase hexadecimal string (a valid uuid4 without dashes).


SDKs MUST implement the following interface at minimum:

MethodParametersReturnsDescription
endendTimestamp?: SpanTimeInputvoidEnds the span. Records end timestamp.
setAttributekey: string, value: SpanAttributeValue | undefinedthisSets a single attribute.
setAttributesattributes: SpanAttributesthisSets multiple attributes.
removeAttributekey: stringthisRemoves an attribute.
setStatusstatus: 'ok' | 'error'thisSets the span status.
setNamename: stringthisSets the span name.
addLinklink: SpanLinkthisAdds a single link.
addLinkslinks: SpanLink[]thisAdds multiple links.
getName—stringReturns the span name.
getAttributes—RecordReturns all attributes.
Copied
interface Span {
  private _spanId: string;

  end(endTimestamp?: SpanTimeInput): void;

  setAttribute(key: string, value: SpanAttributeValue | undefined): this;
  setAttributes(attributes: SpanAttributes): this;
  removeAttribute(key: string): this;

  setStatus(status: 'ok' | 'error'): this;

  setName(name: string): this;

  addLink(link: SpanLink): this;
  addLinks(links: SpanLink[]): this;

  getName(): string;
  getAttributes(): Record<string, SpanAttributeValue>
}

SDKs MAY implement additional methods (e.g. getStatus(), spanContext()).

SDK implementers SHOULD disallow direct mutation of span properties without setters. SDK implementers MAY disallow direct read access.

See Starting Spans for the startSpan signature, options, and behavior.

APIDescription
continueTraceExtracts traceparent and baggage from incoming headers and applies to scope.
getTraceData / getTraceparent + getBaggageReturns trace data for outgoing requests.
startNewTrace / new_traceClears propagation data, starts a fresh trace.

OptionTypeDefaultDescription
traceLifecycle'static' | 'stream''static'Controls transaction vs span-first mode.
tracesSampleRatenumber0.0Float in [0.0, 1.0], sampling rate for segment spans.
tracesSamplerfunction—Callback returning per-trace sample rate.
ignoreSpansarray—Patterns to filter out spans.
beforeSendSpanfunction—Callback for data scrubbing.

SDKs MAY expose additional utility APIs:

  • Scope::getSpan()/get_current_span()/Sentry.getActiveSpan() — returns the currently active span.
  • Scope::_INTERNAL_getSegmentSpan() — returns the segment span (MUST NOT be documented for users).

The steps below document what SDKs have been doing so far when implementing span-first. They are guidelines, not a strict specification.

Implement span-first incrementally. A rough suggestion for iterations:

  1. Add the Span v2 envelope (type), serialization logic, and any utilities necessary to send the new envelope. See Wire Format.
  2. Add the traceLifecycle init option. Span-first MUST be an opt-in feature, and all span-first logic MUST only apply when traceLifecycle is set to 'stream'.
  3. As an initial PoC, leave the current transaction APIs in place and convert the transaction event to a v2 spans array sent in the new envelope.
    • At this point, spans can already be sent in batches (multiple envelopes) to send more than 1000 spans at once, respecting the per-envelope limits.
  4. If applicable, add the new span starting APIs.
    • Start with the simplest possible startSpan API that leaves much control to users. Follow up with optional, more convenient APIs later.
    • The new API MUST only be used in conjunction with traceLifecycle: 'stream' and therefore only emit spans (no transactions).
    • Some SDKs already have startSpan or similar APIs. Each SDK MAY decide whether to reuse its existing API or add a new one, depending on what is practical for the language and platform.
  5. Implement the captureSpan pipeline.
    • Either reuse existing heuristics (e.g. flush when the segment span ends) or build a simple span buffer (e.g. similar to the existing buffers for logs or metrics).
    • The more complex Telemetry Processor buffer and scheduler can be implemented at a later stage.
  6. Achieve data parity with the existing transaction events.
    • Ensure data added by SDK integrations, event processors, etc. to transaction events is also added to spans (see Replacing Event Processors).
    • Most additional data MUST only be added to the segment span. See Common Attribute Keys for attributes that MUST be added to every span.
    • Mental model: all data the SDK automatically adds to a transaction MUST also be added to the segment span.
  7. Implement the span buffer for proper, weighted span flushing.
  8. In the next major release, drop support for sending traces as transactions. From that point on, the SDK only sends spans (v2).

Span streaming SHOULD (can) be released in a minor version of the SDK, given the behaviour is additive and does not interfere with transaction-based tracing.

  • The feature is entirely opt-in via traceLifecycle: 'stream' and therefore doesn't introduce breaking changes for existing users.
  • Release notes and user-facing documentation SHOULD clearly describe:
    • The availability of span-first behind the opt-in flag
    • Highlight the benefits of span-first, like higher span size limits, less memory pressure
    • Any known limitations

Copied
const checkoutSpan = Sentry.startSpan({
  name: 'on-checkout-click',
  attributes: { 'user.id': '123' }
})

const validationSpan = Sentry.startSpan({ name: 'validate-shopping-cart' })
startFormValidation().then((result) => {
  validationSpan.setAttribute('valid-form-data', result.success);
  validationSpan.end();
})

const processSpan = Sentry.startSpan({
  name: 'process-order',
  parentSpan: checkoutSpan
});
processOrder().then((result) => {
  processSpan.setAttribute('order-processed', result.success);
  processSpan.end();
}).catch((error) => {
  processSpan.setStatus('error');
  processSpan.setAttribute('order-processed', 'error');
  processSpan.end();
});

const unrelatedSpan = Sentry.startSpan({
  name: 'log-order',
  parentSpan: null
});
logOrder()
unrelatedSpan.end();

on('checkout-finished', ({ timestamp }) => {
  checkoutSpan.end(timestamp);
})

Copied
// Continue an incoming trace
Sentry.continueTrace({
  sentryTrace: request.headers['sentry-trace'],
  baggage: request.headers['baggage'],
}, () => {
  Sentry.startSpan({ name: 'handle-request' }, () => {
    // ...
  });
})

// Propagate to downstream services
const traceData = Sentry.getTraceData()

// Start a fresh trace
Sentry.startNewTrace(() => {
  Sentry.startSpan({ name: 'new-operation' }, () => {});
})

Copied
Sentry.init({
  ignoreSpans: [
    // apply on span name
    'GET /about',
    'events.signal *',
    /api\/\d+/,
    // ignore health check GET requests
    {
      name: /healthz?/,
      attributes: {
        'http.method': 'GET',
      }
    },
    // ignore all GET requests to /api/
    // (i.e. span name doesn't matter)
    {
      attributes: {
        'http.method': /GET \/api\/.*/,
      }
    },
    // ignore all spans with name starting with /imprint-
    // if glob patterns are supported
    {
      name: '/imprint-*'
    }
  ]
})

// Note: The glob patterns used in the example serve an illustrative purpose.
// They are not supported in JavaScript.

Copied
{
  "version": 2,
  "ingest_settings": {
    "infer_ip": "auto",
    "infer_user_agent": "auto"
  },
  "items": [
    {
      "trace_id": "6cf173d587eb48568a9b2e12dcfbea52",
      "span_id": "438f40bd3b4a41ee",
      "name": "GET /users",
      "status": "ok",
      "is_segment": true,
      "start_timestamp": 1742921669.158209,
      "end_timestamp": 1742921669.180536,
      "attributes": {
        "sentry.segment.name": {
          "type": "string",
          "value": "GET /users"
        },
        "sentry.segment.id": {
          "type": "string",
          "value": "438f40bd3b4a41ee"
        },
        "sentry.op": {
          "type": "string",
          "value": "http.server"
        },
        "sentry.release": {
          "type": "string",
          "value": "1.0.0"
        },
        "sentry.environment": {
          "type": "string",
          "value": "local"
        },
        "sentry.segment.name.source": {
          "type": "string",
          "value": "route"
        },
        "sentry.trace_lifecycle": {
          "type": "string",
          "value": "stream"
        },
        "sentry.platform": {
          "type": "string",
          "value": "php"
        },
        "sentry.sdk.name": {
          "type": "string",
          "value": "sentry.php"
        },
        "sentry.sdk.version": {
          "type": "string",
          "value": "4.10.0"
        },
        "sentry.origin": {
          "type": "string",
          "value": "auto"
        },
        "sentry.is_localhost": {
          "type": "boolean",
          "value": true
        },
        "server.address": {
          "type": "string",
          "value": "127.0.0.1"
        },
        "http.response.status_code": {
          "type": "integer",
          "value": 200
        },
        "session.duration": {
          "type": "integer",
          "value": 164,
          "unit": "second"
        }
      },
      "links": [
        {
          "span_id": "6c71fc6b09b8b716",
          "trace_id": "627a2885119dcc8184fae7eef09438cb",
          "sampled": true,
          "attributes": {
            "sentry.link.type": {
              "type": "string",
              "value": "previous_trace"
            }
          }
        }
      ]
    },
    {
      "trace_id": "6cf173d587eb48568a9b2e12dcfbea52",
      "parent_span_id": "438f40bd3b4a41ee",
      "span_id": "f1196292f76e45c0",
      "name": "app.handle",
      "status": "ok",
      "is_segment": false,
      "start_timestamp": 1742921669.178306,
      "end_timestamp": 1742921669.180484,
      "attributes": {
        "sentry.segment.name": {
          "type": "string",
          "value": "GET /users"
        },
        "sentry.segment.id": {
          "type": "string",
          "value": "438f40bd3b4a41ee"
        },
        "sentry.op": {
          "type": "string",
          "value": "middleware"
        },
        "sentry.release": {
          "type": "string",
          "value": "1.0.0"
        },
        "sentry.environment": {
          "type": "string",
          "value": "local"
        },
        "sentry.sdk.name": {
          "type": "string",
          "value": "sentry.php"
        },
        "sentry.sdk.version": {
          "type": "string",
          "value": "4.10.0"
        },
        "sentry.trace_lifecycle": {
          "type": "string",
          "value": "stream"
        },
        "sentry.origin": {
          "type": "string",
          "value": "auto"
        },
        "sentry.is_localhost": {
          "type": "boolean",
          "value": true
        }
      }
    }
  ]
}

VersionDateSummary
1.2.02026-10-19Require DSC spec 1.4.0 so span envelopes always have a trace envelope header, even for incoming traces without baggage
1.1.02026-10-08Added client reports section listing discard reasons for spans and clarifying that the quantity is the number of discarded spans
1.0.02026-06-22Initial stable release
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").