Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 21 additions & 7 deletions docs/platforms/javascript/common/configuration/apis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ Sentry.withScope((scope) => {
});
```

<Expandable title='What is the difference to `beforeSend` / `beforeSendTransaction`?'>
`beforeSend` and `beforeSendTransaction` are guaranteed to be run last, after all other event processors, (which means they get the final version of the event right before it's sent, hence the name). Event processors added with `addEventProcessor` are run in an undetermined order, which means changes to the event may still be made after the event processor runs.
<Expandable title='What is the difference to `beforeSend`, `beforeSendTransaction`, and `beforeSendSpan`?'>
`beforeSend`, `beforeSendTransaction`, and `beforeSendSpan` are guaranteed to be run last, after all other event processors, (which means they get the final version of the event right before it's sent, hence the name). Event processors added with `addEventProcessor` are run in an undetermined order, which means changes to the event may still be made after the event processor runs.

There can only be a single `beforeSend` / `beforeSendTransaction` processor, but you can add multiple event processors via `addEventProcessor()`.
There can only be a single `beforeSend` / `beforeSendTransaction` / `beforeSendSpan` processor, but you can add multiple event processors via `addEventProcessor()`.

</Expandable>
</SdkApi>
Expand Down Expand Up @@ -507,6 +507,12 @@ Sentry.setContext("character", {

## Tracing

<Alert>

If you're using <PlatformLink to="/tracing/new-spans/">stream mode</PlatformLink>, the Tracing APIs work the same way unless noted otherwise.

</Alert>

<SdkApi
name="startSpan"
signature="function startSpan<T>(options: StartSpanOptions, callback: (span: Span) => T): T"
Expand All @@ -521,7 +527,7 @@ parameters={[
{ name: 'attributes', type: 'Record<string, string | number | boolean | null | undefined>', description: 'Attributes to add to the span.' },
{ name: 'startTime', type: 'number', description: 'The timestamp to use for the span start. If not provided, the current time will be used.' },
{ name: 'op', type: 'string', description: 'The operation name for the span. This is used to group spans in the UI' },
{ name: 'forceTransaction', type: 'boolean', description: 'If true, the span will be forced to be sent as a transaction, even if it is not the root span.' },
{ name: 'forceTransaction', type: 'boolean', description: 'If true, the span will be forced to be sent as a transaction, even if it is not the root span. \n// Not available in stream mode. Use `parentSpan: null` instead to make this span show up as service span.' },
Copy link
Copy Markdown
Collaborator Author

@inventarSarah inventarSarah May 26, 2026

Choose a reason for hiding this comment

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

Adding "\n" like this works, but I am not sure if it's "allowed" ;)

        { ... description: 'If true,... \n// Not available in stream mode. Use `parentSpan: null` instead to make this span show up as service span.' },

{ name: 'parentSpan', type: 'Span | null', description: 'The parent span for the new span. If not provided, the current span will be used.' },
{ name: 'onlyIfParent', type: 'boolean', description: 'If true, the span will only be created if there is an active span.' },
]
Expand Down Expand Up @@ -570,7 +576,7 @@ See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</Platfo
{ name: 'attributes', type: 'Record<string, string | number | boolean | null | undefined>', description: 'Attributes to add to the span.' },
{ name: 'startTime', type: 'number', description: 'The timestamp to use for the span start. If not provided, the current time will be used.' },
{ name: 'op', type: 'string', description: 'The operation name for the span. This is used to group spans in the UI' },
{ name: 'forceTransaction', type: 'boolean', description: 'If true, the span will be forced to be sent as a transaction, even if it is not the root span.' },
{ name: 'forceTransaction', type: 'boolean', description: 'If true, the span will be forced to be sent as a transaction, even if it is not the root span. \n// Not available in stream mode. Use `parentSpan: null` instead to make this span show up as service span.' },
{ name: 'parentSpan', type: 'Span | null', description: 'The parent span for the new span. If not provided, the current span will be used.' },
{ name: 'onlyIfParent', type: 'boolean', description: 'If true, the span will only be created if there is an active span.' },
]
Expand Down Expand Up @@ -607,7 +613,7 @@ See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</Platfo
{ name: 'attributes', type: 'Record<string, string | number | boolean | null | undefined>', description: 'Attributes to add to the span.' },
{ name: 'startTime', type: 'number', description: 'The timestamp to use for the span start. If not provided, the current time will be used.' },
{ name: 'op', type: 'string', description: 'The operation name for the span. This is used to group spans in the UI' },
{ name: 'forceTransaction', type: 'boolean', description: 'If true, the span will be forced to be sent as a transaction, even if it is not the root span.' },
{ name: 'forceTransaction', type: 'boolean', description: 'If true, the span will be forced to be sent as a transaction, even if it is not the root span. \n// Not available in stream mode. Use `parentSpan: null` instead to make this span show up as service span.' },
{ name: 'parentSpan', type: 'Span | null', description: 'The parent span for the new span. If not provided, the current span will be used.' },
{ name: 'onlyIfParent', type: 'boolean', description: 'If true, the span will only be created if there is an active span.' },
]
Expand Down Expand Up @@ -787,8 +793,16 @@ Sentry.reportPageLoaded();

These utilities can be used for more advanced tracing use cases.

<SdkApi name="spanToJSON" signature="function spanToJSON(span: Span): SpanJSON">
<SdkApi name="spanToJSON" signature="function spanToJSON(span: Span): SpanJSON | StreamedSpanJSON">
Convert a span to a JSON object.

The shape of the returned object depends on your tracing mode:

- In transaction mode (default), `spanToJSON` returns a `SpanJSON` object.
- In <PlatformLink to="/tracing/new-spans">stream mode</PlatformLink>, it returns a `StreamedSpanJSON` object.

See <PlatformLink to="/configuration/options/#beforeSendSpan">`beforeSendSpan`</PlatformLink> for more information about these objects.

</SdkApi>

<SdkApi
Expand Down
43 changes: 40 additions & 3 deletions docs/platforms/javascript/common/configuration/filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ This is the case because the Sentry Loader Script and CDN Bundles are detected a

## Filtering Transaction Events

<Alert>
The options in this section are only available in transaction mode. If you're
using <PlatformLink to="/tracing/new-spans/">stream mode</PlatformLink>, go to
[Filtering Spans](#filtering-spans).
</Alert>

To prevent certain transactions from being reported to Sentry, use the <PlatformIdentifier name="traces-sampler" /> or <PlatformIdentifier name="before-send-transaction" /> configuration option, which allows you to provide a function to evaluate the current transaction and drop it if it's not one you want.

### Using <PlatformIdentifier name="ignore-transactions" />
Expand All @@ -137,14 +143,45 @@ See <PlatformLink to="/configuration/options/#beforeSendTransaction">beforeSendT

## Filtering Spans

Use the <PlatformIdentifier name="before-send-span" /> configuration option which allows you to provide a function to modify a span.
This function is called for the root span and all child spans. If you want to drop the root span, including its child spans, use [`beforeSendTransaction`](#using-beforesendtransaction) instead.
Please note that you cannot use `beforeSendSpan` to drop a span, you can only modify it and filter data on it.
### Using <PlatformIdentifier name="before-send-span" />

Use the <PlatformIdentifier name="before-send-span" /> configuration option, which lets you provide a function to modify a span.
This function is called for the transaction (service span in stream mode) and all child spans.
If you want to drop the transaction/service span, including its child spans:

- Use [`beforeSendTransaction`](#using-beforesendtransaction) in transaction mode.
- Use [`ignoreSpans`](#using-ignore-spans) in stream mode and wrap it with `Sentry.withStreamedSpan()`.

Please note that you cannot use `beforeSendSpan` to drop a span; you can only modify it and filter data on it.

<PlatformContent includePath="configuration/before-send-span" />

See <PlatformLink to="/configuration/options/#beforeSendSpan">beforeSendSpan</PlatformLink> for details.

### Using <PlatformIdentifier name="ignore-spans" />

You can use the <PlatformIdentifier name="ignore-spans" /> option to filter out spans that match a certain pattern by providing a list of strings or regular expressions. When using strings, partial matches will be filtered out, so if you need to filter by exact match, use regex patterns instead.

You can also provide an object with `name`, `op`, and `attributes` properties to match on multiple conditions. At least one property must be provided.

```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
ignoreSpans: [
"partial/match",
/^Exact Transaction Name$/,
{
name: /^GET \//,
attributes: {
"http.route": "/api/status",
},
},
],
});
```

See <PlatformLink to="/configuration/options/#ignoreSpans">ignoreSpans</PlatformLink> for details.

## Filtering Breadcrumbs

You can filter breadcrumbs by using the `beforeBreadcrumb` configuration option:
Expand Down
82 changes: 73 additions & 9 deletions docs/platforms/javascript/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ For example, the Sentry Nuxt SDK does not attach an error handler as it's captur

## Tracing Options

<Alert>

If you're using <PlatformLink to="/tracing/new-spans/">stream mode</PlatformLink>, tracing options work the same way as described but apply to service spans instead of transactions.

</Alert>

<PlatformSection supported={["javascript.electron"]}>
**Note:** For Electron, tracing options apply to the process where these
options are set.
Expand Down Expand Up @@ -528,32 +534,69 @@ This is useful to prevent traces of unknown third-party services from being cont

This function is called with a transaction event object, and can return a modified transaction event object, or `null` to skip reporting the event. This can be used, for instance, for manual PII stripping before sending.

Not available in stream mode. Instead, use [`ignoreSpans`](#ignoreSpans) to drop spans, or [`beforeSendSpan`](#beforeSendSpan) to modify spans.

</SdkOption>

<SdkOption name="beforeSendSpan" type='(span: SpanJSON) => SpanJSON'>

This function is called with a serialized span object, and can return a modified span object. This might be useful for manually stripping PII from spans.
This function is called for root spans as well as for all child spans.
If you want to drop the root span, including all of its child spans, use [`beforeSendTransaction`](#beforeSendTransaction) instead.
This function is called with a serialized span object and can return a modified span object. Use it, for example, to manually strip PII from spans or filter data from spans before they're sent to Sentry. It runs for all spans, including transactions and their child spans.

Note that `beforeSendSpan` can only modify span data, meaning you cannot use it to drop spans. Use [`ignoreSpans`](#ignoreSpans) to drop spans, or [`beforeSendTransaction`](#beforeSendTransaction) to drop transactions.

The `span` you receive as an argument is a serialized object, not a `Span` class instance.

If you're using stream mode, wrap `beforeSendSpan` with `Sentry.withStreamedSpan()` — otherwise the SDK falls back to transaction mode.

<Expandable level="warning" title="Span object property names in stream mode">

Please note that the `span` you receive as an argument is a serialized object, not a `Span` class instance.
In stream mode, the span object is `StreamedSpanJSON` instead of `SpanJSON` and has different property names:

| Transaction Mode (`SpanJSON`) | Stream Mode (`StreamedSpanJSON`) |
| ---------------------------------- | ----------------------------------- |
| `span.description` | `span.name` |
| `span.data` (processed attributes) | `span.attributes` (raw attributes) |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add more about name and span.op here, like we do in filtering?

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.

I added an Expandable with the code examples from the Filtering page below -- or did you mean something different?

| `span.timestamp` (end time) | `span.end_timestamp` |
| `span.status` (optional string) | `span.status` (`'ok'` or `'error'`) |
| `span.op` | `span.attributes['sentry.op']` |

</Expandable>

<Expandable title="Examples">

<PlatformContent includePath="configuration/before-send-span" />

</Expandable>

</SdkOption>

<SdkOption name="ignoreTransactions" type='Array<string | RegExp>' defaultValue='[]'>

<Include name="platforms/configuration/options/ignore-transactions.mdx" />

</SdkOption>
Not available in stream mode. Use [`ignoreSpans`](#ignoreSpans) instead.

<SdkOption name="ignoreSpans" type='Array<string | RegExp | {name?: string | RegExp, op?: string | RegExp}>' defaultValue='[]' availableSince='10.2.0'>
</SdkOption>

A list of strings or regex patterns matching span names that shouldn't be sent to Sentry. When using strings, partial matches will be filtered out, so if you need to filter by exact match, use regex patterns instead. You can also provide an object with a `name` and `op` property to match both the span name and the operation name. Note that at least `name` or `op` must be provided.
<SdkOption name="ignoreSpans" type='Array<string | RegExp | {name?: string | RegExp, op?: string | RegExp, attributes?: Record<string, string | number | boolean | null | undefined>}>' defaultValue='[]' availableSince='10.2.0'>

If a root span matches any of the specified patterns, the entire local trace will be dropped. If a child span matches, its children will be reparented to the dropped span's parent span.
A list of strings or regex patterns matching spans that shouldn't be sent to Sentry. When using strings, partial matches will be filtered out, so if you need to filter by exact match, use regex patterns instead. You can also provide an object with `name`, `op`, and `attributes` properties to match on multiple conditions. At least one property must be provided.

If a matching span is a transaction or service span, the entire local trace will be dropped. If a child span matches, its children will be reparented to the dropped span's parent span.
By default, no spans are ignored.

In <PlatformLink to="/tracing/new-spans">stream mode</PlatformLink>, `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>

<Expandable title="Examples">

Here are some predefined matches for common spans to get you started:

```javascript
Expand All @@ -577,12 +620,24 @@ Sentry.init({
name: /.+\.(png|svg|jpe?g|gif|bmp|tiff?|webp|avif|heic?|ico).*$/,
},

// Drop spans whose name contains "healthcheck"
"healthcheck",

// Drop spans matching name and attribute conditions
{
name: /^GET \//,
attributes: {
"http.route": "/api/status",
},
},

// Measure spans
{ op: "measure" },
],
});
```

</Expandable>
</SdkOption>

<SdkOption name="propagateTraceparent" type='boolean' defaultValue='false' availableSince='10.10.0'>
Expand Down Expand Up @@ -610,6 +665,15 @@ Enable this option if you are using <PlatformLink to="/ai-agent-monitoring/">AI

</SdkOption>

<SdkOption name="traceLifecycle" type="'static' | 'stream'" defaultValue="'static'" availableSince='10.53.1'>

Controls how spans are sent to Sentry:

- In transaction mode (`'static'`, the default), all spans are collected in memory and sent to Sentry as a single transaction once the root span ends.
- In <PlatformLink to="/tracing/new-spans/">stream mode</PlatformLink> (`'stream'`), spans are sent in batches as they finish.

</SdkOption>

## Logs Options

<PlatformSection supported={["javascript.electron"]}>
Expand Down Expand Up @@ -662,7 +726,7 @@ A number between `0` and `1` that sets the percentage of how many sessions shoul
Determines how profiling sessions are controlled. It has two modes:

- `'manual'` (default): You control when profiling starts and stops using the `startProfiler()` and `stopProfiler()` functions. In this mode, profile sampling is only affected by `profileSessionSampleRate`.<PlatformSection notSupported={["javascript.bun", "javascript.cordova", "javascript.capacitor", "javascript.deno", "javascript.cloudflare"]}> Read more about these functions in the <PlatformLink to="/profiling">profiling API documentation</PlatformLink>.</PlatformSection>
- `'trace'`: Profiling starts and stops automatically with transactions, as long as tracing is enabled. The profiler runs as long as there is at least one sampled transaction. In this mode, profiling is affected by both `profileSessionSampleRate` and your tracing sample rate (`tracesSampleRate` or `tracesSampler`).
- `'trace'`: Profiling starts and stops automatically with transactions (or service spans if you're using <PlatformLink to="/tracing/new-spans">stream mode</PlatformLink>), as long as tracing is enabled. The profiler runs as long as there is at least one sampled transaction. In this mode, profiling is affected by both `profileSessionSampleRate` and your tracing sample rate (`tracesSampleRate` or `tracesSampler`).

</SdkOption>

Expand Down
19 changes: 18 additions & 1 deletion platform-includes/configuration/before-send-span/javascript.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```javascript
```javascript {tabTitle:Transaction Mode (Default)}
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSendSpan(span) {
Expand All @@ -14,3 +14,20 @@ Sentry.init({
},
});
```

```javascript {tabTitle:Stream Mode}
Sentry.init({
dsn: "___PUBLIC_DSN___",
beforeSendSpan: Sentry.withStreamedSpan((span) => {
if (span.name === "should be renamed") {
span.name = "renamed span";
span.attributes = {
...span.attributes,
myExtraAttribute: true,
};
}

return span;
}),
});
```
Loading