Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fac1de3
docs(js): add Node stream spans guide
cleptric May 5, 2026
d67f9cd
Merge branch 'master' into span-first-js
cleptric May 11, 2026
4461c9c
Add srubbing and filtering
cleptric May 11, 2026
29765bb
clean up platform include files created for split layout update
inventarSarah May 12, 2026
497dc78
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah May 12, 2026
c84d25e
finalize split layout include file cleanup
inventarSarah May 12, 2026
93fed8f
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah May 19, 2026
6f89d79
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/sp…
inventarSarah May 20, 2026
2d06907
Merge branch 'span-first-js' of github.com:getsentry/sentry-docs into…
inventarSarah May 20, 2026
f0e25a6
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/sp…
inventarSarah May 21, 2026
9b703d3
create New Spans guide for JS SDKs
inventarSarah May 21, 2026
4865de9
update sdk snippets
inventarSarah May 21, 2026
31c975c
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/sp…
inventarSarah May 21, 2026
2f89f55
update missing info and fix some snippets
inventarSarah May 21, 2026
04a40f8
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/sp…
inventarSarah May 21, 2026
1688a5a
Merge branch 'master' into smi/span-first/js
inventarSarah May 21, 2026
653aa8f
fix remix snippet
inventarSarah May 21, 2026
e3d3699
Merge branch 'smi/span-first/js' of github.com:getsentry/sentry-docs …
inventarSarah May 21, 2026
034a6cb
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/sp…
inventarSarah May 22, 2026
0b511d5
describe service spans
inventarSarah May 22, 2026
b8d6819
add effect and elysia
inventarSarah May 22, 2026
0120dc6
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/sp…
inventarSarah May 22, 2026
bd5bdf0
minor fixes
inventarSarah May 22, 2026
95337d2
update span names in Drop Spans section
inventarSarah May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
370 changes: 370 additions & 0 deletions docs/platforms/javascript/common/tracing/new-spans/index.mdx
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we mix "service span" and "root span" in this doc. A couple of thoughts:

  • I really like the "service span" name (as opposed to "segment span" how we call it in SDK code). I've probably been quite out of the loop here: Is this the public name we ended up choosing for it? Just want to confirm.
  • It's probably fine to use "root span" when we talk about how things used to be with transactions but further below, we explain the ignoreSpans behaviour differences for child vs. root spans. Should we adjust to "child vs. service spans" there?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • "service span" is a naming recommendation provided by Shannon -- I've collected the full list here
  • I would really like to get use all the different span correctly -- it would be great if you (reviewers) leave a comment when the guide uses the wrong (or not best fitting) name

Original file line number Diff line number Diff line change
@@ -0,0 +1,370 @@
---
title: New Spans
description: "Learn how to use stream mode to send spans to Sentry as they finish, removing the 1,000-span limit and making trace data visible sooner."
sidebar_order: 35
new: true
notSupported:
- javascript.cordova
---

<AvailableSince version="10.53.1" />

By default, the Sentry JavaScript SDKs collect all spans in memory and send them to Sentry as a single transaction once the root span ends. This is called transaction mode.
Stream mode changes this by sending spans to Sentry in batches as they finish. Service spans, which represent a service's entry point, replace transactions as the main grouping for each service.

<Expandable title="Why use stream mode?">

- **No 1,000-span limit.** In transaction mode, transactions are capped at 1,000 spans. Stream mode has no upper limit since spans are sent in batches.
- **Lower memory usage.** Spans are flushed periodically and don't need to be held in memory until the root span ends. This is especially useful for long-running processes like queue consumers or cron jobs.
- **Faster visibility.** Span data arrives in Sentry as your application runs, instead of only after the entire operation completes.
- **No data loss from crashes.** If your process terminates unexpectedly, spans that were already flushed are preserved. In transaction mode, a crash before the root span ends means all span data is lost.

</Expandable>

## Prerequisites

You need:

- <PlatformLink to="/tracing/#configure">Tracing configured</PlatformLink> in
your app
- Sentry SDK `>=10.53.1`

## Migrate from Transaction Mode

For most users, switching to stream mode requires no code changes beyond the initial opt-in. If you use `beforeSendSpan` or `beforeSendTransaction`, follow these steps:

1. [Enable stream mode](#enable-stream-mode)
2. [Wrap `beforeSendSpan` with `Sentry.withStreamedSpan()` to filter spans](#filter-spans)
3. [Replace `beforeSendTransaction` with `ignoreSpans` to drop spans](#drop-spans)
4. [Verify the migration](#verify-your-setup)

## Enable Stream Mode

<PlatformContent includePath="performance/enable-stream-mode" />

<PlatformSection notSupported={["javascript.nextjs", "javascript.nuxt", "javascript.sveltekit", "javascript.astro", "javascript.solidstart", "javascript.capacitor", "javascript.tanstackstart-react", "javascript.remix", "javascript.react-router", "javascript.effect"]}>

<Alert level="success" title="Mixing tracing modes in distributed tracing">

Tracing modes are scoped per SDK, which means you can use, for example, stream mode in your frontend, and transaction mode in your backend, or vice versa.

</Alert>

</PlatformSection>

<Expandable title="How does span flushing work?">

When stream mode is enabled, the SDK maintains an internal buffer that groups spans by trace ID.

Spans are flushed:

- On a regular interval (every 5 seconds by default).
- When a trace's buffer reaches 1,000 spans.
- When you call `Sentry.flush()` or `Sentry.close()`.

Each flush sends only the spans accumulated since the last flush, grouped into envelopes by trace ID.

</Expandable>

## Manual Instrumentation (Optional)

### Start a Span

<SplitLayout>
<SplitSection>
<SplitSectionText>

Use `Sentry.startSpan()` to create a span that is automatically ended when the callback completes:

</SplitSectionText>
<SplitSectionCode>

```javascript
const result = await Sentry.startSpan(
{ name: "my-operation", attributes: { "my.attribute": "value" } },
async () => {
// Your code here
return await doWork();
}
);
```

</SplitSectionCode>
</SplitSection>

<SplitSection>
<SplitSectionText>

Child spans created inside the callback are automatically associated with the parent:

</SplitSectionText>
<SplitSectionCode>

```javascript
await Sentry.startSpan({ name: "parent-operation" }, async () => {
await Sentry.startSpan({ name: "child-step-1" }, async () => {
await stepOne();
});

await Sentry.startSpan({ name: "child-step-2" }, async () => {
await stepTwo();
});
});
```

</SplitSectionCode>
</SplitSection>
</SplitLayout>

For more details on span creation APIs, such as `startSpan`, `startSpanManual`, or `startInactiveSpan`, see <PlatformLink to="/tracing/instrumentation/">Instrumentation</PlatformLink>.

### Add Span Attributes

Attach structured metadata to spans using <PlatformLink to="/configuration/apis/#startSpan">`attributes`</PlatformLink>, which can be `string`, `number`, or `boolean`, as well as arrays of these types.

<SplitLayout>
<SplitSection>
<SplitSectionText>

You can set attributes when starting a span:

</SplitSectionText>
<SplitSectionCode>

```javascript
Sentry.startSpan(
{
name: "process-order",
op: "queue.process",
attributes: {
"order.id": "abc-123",
"order.item_count": 5,
"order.priority": true,
},
},
() => {
// Process the order
}
);
```

</SplitSectionCode>
</SplitSection>

<SplitSection>
<SplitSectionText>

Or add them to an already running span:

</SplitSectionText>
<SplitSectionCode>

```javascript
Sentry.startSpan({ name: "handle-request" }, (span) => {
// Set a single attribute
span.setAttribute("http.response.status_code", 200);

// Set multiple attributes at once
span.setAttributes({
"http.route": "/api/users",
"user.id": "user-42",
});
});
```

</SplitSectionCode>
</SplitSection>

Find more examples in our <PlatformLink to="/tracing/span-metrics/">Sending Span Metrics</PlatformLink> documentation.

</SplitLayout>

## Distributed Tracing (Optional)

Distributed tracing works out of the box when tracing is enabled and works the same way in stream mode. If you need to manually propagate trace context, for example,
when the SDK can't instrument automatically, see <PlatformLink to="/tracing/distributed-tracing/custom-instrumentation/">Custom Trace Propagation</PlatformLink>.

## Extended Configuration (Optional)

### Filter Spans

<SplitLayout>
<SplitSection>
<SplitSectionText>

To modify or redact span data before it's sent, use <PlatformLink to="/configuration/options/#beforeSendSpan">`beforeSendSpan`</PlatformLink>. In stream mode, wrap it with `Sentry.withStreamedSpan()` so the SDK applies it to spans as they are flushed rather than only at transaction time.

<Alert>
`beforeSendSpan` can only modify span data, and you cannot use it to drop
spans. Use [`ignoreSpans`](#drop-spans) instead.
</Alert>

</SplitSectionText>
<SplitSectionCode>

<PlatformCategorySection supported={["server", "serverless"]}>

```JavaScript
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
traceLifecycle: "stream",
beforeSendSpan: Sentry.withStreamedSpan((span) => {
// In stream mode, 'op' is accessed via attributes
if (span.attributes?.["sentry.op"] === "db.query") {
// In stream mode, 'description' is now renamed to 'name'
span.name = "[filtered]";
}
return span;
}),
});
```

</PlatformCategorySection>

<PlatformCategorySection supported={["browser"]}>

<PlatformSection notSupported={["javascript.nextjs", "javascript.nuxt", "javascript.sveltekit", "javascript.astro", "javascript.solidstart", "javascript.capacitor", "javascript.tanstackstart-react", "javascript.remix", "javascript.react-router", "javascript.effect"]}>

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
integrations: [
// other integrations
Sentry.spanStreamingIntegration(),
],
beforeSendSpan: Sentry.withStreamedSpan((span) => {
// In stream mode, 'op' is accessed via attributes
if (span.attributes?.["sentry.op"] === "db.query") {
// In stream mode, 'description' is now renamed to 'name'
span.name = "[filtered]";
}
return span;
}),
});
```

</PlatformSection>
</PlatformCategorySection>

</SplitSectionCode>
</SplitSection>
</SplitLayout>

<Alert level="warning" title="Migrating from transaction mode?">

If you're using `beforeSendSpan`, wrap it with `Sentry.withStreamedSpan()` as shown above, otherwise the SDK falls back to transaction mode.
The callback signature and properties of the span object are also shaped differently. See <PlatformLink to="/configuration/options/#beforesendspan">`beforeSendSpan`</PlatformLink> for the full reference.

If you're using `beforeSendTransaction` to drop spans, use [`ignoreSpans`](#drop-spans) instead, since `beforeSendTransaction` is not available in stream mode.

</Alert>

### Drop Spans

<SplitLayout>
<SplitSection>
<SplitSectionText>

To prevent specific spans from being created, use the <PlatformLink to="/configuration/options/#ignoreSpans">`ignoreSpans`</PlatformLink> option:

</SplitSectionText>
<SplitSectionCode>

<PlatformCategorySection supported={["server", "serverless"]}>

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
traceLifecycle: "stream",
ignoreSpans: [
// Drop spans whose name contains "healthcheck"
"healthcheck",
// Drop spans whose name matches a pattern
/^GET \/api\/v1\/internal/,
// Drop spans matching name and attribute conditions
{
name: /^GET \//,
attributes: {
"http.route": "/api/status",
},
},
],
});
```

</PlatformCategorySection>

<PlatformCategorySection supported={["browser"]}>

<PlatformSection notSupported={["javascript.nextjs", "javascript.nuxt", "javascript.sveltekit", "javascript.astro", "javascript.solidstart", "javascript.capacitor", "javascript.tanstackstart-react", "javascript.remix", "javascript.react-router", "javascript.effect"]}>

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
integrations: [
// other integrations
Sentry.spanStreamingIntegration(),
],
ignoreSpans: [
// Drop spans whose name contains "healthcheck"
"healthcheck",
// Drop spans whose name matches a pattern
/^GET \/api\/v1\/internal/,
// Drop spans matching name and attribute conditions
{
name: /^GET \//,
attributes: {
"http.response.status_code": 200,
"http.route": "/api/status",
},
},
],
});
```

</PlatformSection>

</PlatformCategorySection>

</SplitSectionCode>
</SplitSection>
</SplitLayout>

If a matching span is a service span, all of its child spans are dropped as well. If a child span matches, only that span is dropped and its children are reparented to the nearest ancestor.

In stream mode, `ignoreSpans` is evaluated at span start, so only the span name and attributes available at that point are taken into account. Any name updates or additional attributes added while the span is active won't influence whether the span is dropped.

<Alert level="warning" title="Migrating from transaction mode?">

In transaction mode, `ignoreSpans` is evaluated at transaction end rather than at span start. Review your existing rules to make sure the attributes you're matching on are passed when the span is created.

If you're auto-instrumenting and don't know what the initial name of a span is when it starts, enable SDK debug logging during development by setting <PlatformLink to="/configuration/options/#debug">`debug: true`</PlatformLink> when initializing the SDK.

</Alert>

## Verify Your Setup

To make sure you've enabled stream mode successfully:

<PlatformCategorySection supported={["server", "serverless"]}>

<PlatformSection notSupported={["javascript.nextjs", "javascript.nuxt", "javascript.sveltekit", "javascript.astro", "javascript.solidstart", "javascript.capacitor", "javascript.tanstackstart-react", "javascript.remix", "javascript.react-router", "javascript.effect"]}>

- **Check the Sentry dashboard**: Spans should appear in the Traces view shortly after they complete. Traces look the same as in transaction mode, but without transactions.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traces look the same as in transaction mode, but without transactions

This is true but unless I missed something, there are very few visual indications that actually point out that a span is a (new) span and not a transaction 😬 The only thing that comes to mind is that it's not showing a JSON button anymore. I don't think there's harm in leaving in this sentence but users might get confused at what they should be looking in the product.

This is of course not a primary docs issue but rather a product/UI issue. We might want to think about some kind of indicator (and, separate topic, please bring back JSON for streamed spans lol). That is assuming, I didn't miss any obvious indication 😅 Will ask product folks about this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I will update this to something like
"Traces look almost the same as in transaction mode. The main difference is that they have no transactions and only consist of spans."

- **Check for fallback warnings in your logs**: If the SDK logs warnings about falling back to transaction mode, your `beforeSendSpan` callback is likely missing the `Sentry.withStreamedSpan()` wrapper.

</PlatformSection>

</PlatformCategorySection>

<PlatformCategorySection supported={["browser"]}>

- **Check the Sentry dashboard**: Spans should appear in the Traces view shortly after they complete. Traces look the same as in transaction mode, but without transactions.
- **Check for fallback warnings in your logs**: If the SDK logs warnings about falling back to transaction mode, your `beforeSendSpan` callback is likely missing the `Sentry.withStreamedSpan()` wrapper.
- **Check the network tab in your browser's DevTools**: Span envelopes should appear as individual requests with content type `application/vnd.sentry.items.span.v2+json`

</PlatformCategorySection>
Loading
Loading