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
24 changes: 12 additions & 12 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = [
path: 'packages/browser/build/npm/esm/prod/index.js',
import: createImport('init'),
gzip: true,
limit: '26 KB',
limit: '27 KB',
},
{
name: '@sentry/browser - with treeshaking flags',
Expand Down Expand Up @@ -38,7 +38,7 @@ module.exports = [
path: 'packages/browser/build/npm/esm/prod/index.js',
import: createImport('init', 'browserTracingIntegration'),
gzip: true,
limit: '44 KB',
limit: '45 KB',
},
{
name: '@sentry/browser (incl. Tracing + Span Streaming)',
Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports = [
path: 'packages/browser/build/npm/esm/prod/index.js',
import: createImport('init', 'feedbackAsyncIntegration'),
gzip: true,
limit: '36 KB',
limit: '37 KB',
},
{
name: '@sentry/browser (incl. Metrics)',
Expand Down Expand Up @@ -178,7 +178,7 @@ module.exports = [
path: 'packages/svelte/build/esm/index.js',
import: createImport('init'),
gzip: true,
limit: '26 KB',
limit: '27 KB',
},
// Browser CDN bundles
{
Expand Down Expand Up @@ -227,7 +227,7 @@ module.exports = [
name: 'CDN Bundle (incl. Tracing, Replay, Feedback)',
path: createCDNPath('bundle.tracing.replay.feedback.min.js'),
gzip: true,
limit: '89 KB',
limit: '90 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)',
Expand All @@ -241,14 +241,14 @@ module.exports = [
path: createCDNPath('bundle.min.js'),
gzip: false,
brotli: false,
limit: '84 KB',
limit: '85 KB',
},
{
name: 'CDN Bundle (incl. Tracing) - uncompressed',
path: createCDNPath('bundle.tracing.min.js'),
gzip: false,
brotli: false,
limit: '138 KB',
limit: '139 KB',
},
{
name: 'CDN Bundle (incl. Logs, Metrics) - uncompressed',
Expand All @@ -262,35 +262,35 @@ module.exports = [
path: createCDNPath('bundle.tracing.logs.metrics.min.js'),
gzip: false,
brotli: false,
limit: '141.5 KB',
limit: '142 KB',
},
{
name: 'CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed',
path: createCDNPath('bundle.replay.logs.metrics.min.js'),
gzip: false,
brotli: false,
limit: '212 KB',
limit: '213 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay) - uncompressed',
path: createCDNPath('bundle.tracing.replay.min.js'),
gzip: false,
brotli: false,
limit: '255.5 KB',
limit: '256 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed',
path: createCDNPath('bundle.tracing.replay.logs.metrics.min.js'),
gzip: false,
brotli: false,
limit: '259 KB',
limit: '260 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed',
path: createCDNPath('bundle.tracing.replay.feedback.min.js'),
gzip: false,
brotli: false,
limit: '269 KB',
limit: '270 KB',
},
{
name: 'CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.spanStreamingIntegration()],
ignoreSpans: [{ attributes: { 'http.status_code': 200 } }],
tracesSampleRate: 1,
debug: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This segment span matches ignoreSpans via attributes — segment + child should be dropped
Sentry.startSpan({ name: 'health-check', attributes: { 'http.status_code': 200 } }, () => {
Sentry.startSpan({ name: 'child-of-ignored' }, () => {});
});

setTimeout(() => {
// This segment span does NOT match — segment + child should be sent
Sentry.startSpan({ name: 'normal-segment', attributes: { 'http.status_code': 500 } }, () => {
Sentry.startSpan({ name: 'child-span' }, () => {});
});
}, 1000);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect } from '@playwright/test';
import type { ClientReport } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import {
envelopeRequestParser,
hidePage,
shouldSkipTracingTest,
waitForClientReportRequest,
} from '../../../../utils/helpers';
import { observeStreamedSpan, waitForStreamedSpans } from '../../../../utils/spanUtils';

sentryTest('attribute-matching ignoreSpans drops the trace', async ({ getLocalTestUrl, page }) => {
sentryTest.skip(shouldSkipTracingTest());

const url = await getLocalTestUrl({ testDir: __dirname });

observeStreamedSpan(page, span => {
if (span.name === 'health-check' || span.name === 'child-of-ignored') {
throw new Error('Ignored span found');
}
return false;
});

const spansPromise = waitForStreamedSpans(page, spans => !!spans?.find(s => s.name === 'normal-segment'));
const clientReportPromise = waitForClientReportRequest(page);

await page.goto(url);

expect((await spansPromise)?.length).toBe(2);

await hidePage(page);

const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise);
expect(clientReport.discarded_events).toEqual([{ category: 'span', quantity: 2, reason: 'ignored' }]);
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// This segment span matches ignoreSpans — should NOT produce a transaction
// This segment span matches ignoreSpans — segment + child should be dropped
Sentry.startSpan({ name: 'ignore-segment' }, () => {
Sentry.startSpan({ name: 'child-of-ignored-segment' }, () => {});
});

setTimeout(() => {
// This segment span does NOT match — should produce a transaction
// This segment span does NOT match — segment + child should be sent
Sentry.startSpan({ name: 'normal-segment' }, () => {
Sentry.startSpan({ name: 'child-span' }, () => {});
});
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,13 @@ function processBeforeSend(
const rootSpanJson = convertTransactionEventToSpanJson(processedEvent);

// 1.1 If the root span should be ignored, drop the whole transaction
if (ignoreSpans?.length && shouldIgnoreSpan(rootSpanJson, ignoreSpans)) {
if (
ignoreSpans?.length &&
shouldIgnoreSpan(
{ description: rootSpanJson.description, op: rootSpanJson.op, attributes: rootSpanJson.data },
ignoreSpans,
)
) {
// dropping the whole transaction!
return null;
}
Expand All @@ -1624,7 +1630,10 @@ function processBeforeSend(

for (const span of initialSpans) {
// 2.a If the child span should be ignored, reparent it to the root span
if (ignoreSpans?.length && shouldIgnoreSpan(span, ignoreSpans)) {
if (
ignoreSpans?.length &&
shouldIgnoreSpan({ description: span.description, op: span.op, attributes: span.data }, ignoreSpans)
) {
reparentChildSpans(initialSpans, span);
continue;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ export function createSpanEnvelope(spans: [SentrySpan, ...SentrySpan[]], client?
const { beforeSendSpan, ignoreSpans } = client?.getOptions() || {};

const filteredSpans = ignoreSpans?.length
? spans.filter(span => !shouldIgnoreSpan(spanToJSON(span), ignoreSpans))
? spans.filter(span => {
const json = spanToJSON(span);
return !shouldIgnoreSpan({ description: json.description, op: json.op, attributes: json.data }, ignoreSpans);
})
: spans;
const droppedSpans = spans.length - filteredSpans.length;

Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/tracing/idleSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
// Ignored spans will get dropped later (in the client) but since we already adjust
// the idle span end timestamp here, we can already take to-be-ignored spans out of
// the calculation here.
if (ignoreSpans && shouldIgnoreSpan(currentSpanJson, ignoreSpans)) {
if (
ignoreSpans &&
shouldIgnoreSpan(
{ description: currentSpanJson.description, op: currentSpanJson.op, attributes: currentSpanJson.data },
ignoreSpans,
)
) {
return acc;
}
return acc ? Math.max(acc, currentSpanJson.timestamp) : currentSpanJson.timestamp;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tracing/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ function _shouldIgnoreStreamedSpan(client: Client | undefined, spanArguments: Se
{
description: spanArguments.name || '',
op: spanArguments.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP] || spanArguments.op,
attributes: spanArguments.attributes,
},
ignoreSpans,
);
Expand Down
41 changes: 39 additions & 2 deletions packages/core/src/types-hoist/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ export interface ServerRuntimeOptions {
onFatalError?(this: void, error: Error): void;
}

/**
* Allowed attribute value matchers in `ignoreSpans` filters.
* String span attributes use pattern matching (substring or RegExp).
* Non-string attribute values match by strict equality (arrays element-wise).
*/
export type IgnoreSpanAttributeValue = string | boolean | number | string[] | boolean[] | number[] | RegExp;

/**
* A filter object for ignoring spans.
* At least one of the properties (`op` or `name`) must be set.
* At least one of the properties (`name`, `op`, or `attributes`) must be set.
* If multiple are set, all must match for the span to be ignored.
*/
type IgnoreSpanFilter =
| {
Expand All @@ -114,6 +122,12 @@ type IgnoreSpanFilter =
* Spans with an op matching this pattern will be ignored.
*/
op?: string | RegExp;
/**
* Spans whose attributes ALL match the corresponding entries will be ignored.
* String attribute values are matched as patterns (substring or RegExp).
* Non-string values match by strict equality (arrays element-wise).
*/
attributes?: Record<string, IgnoreSpanAttributeValue>;
}
| {
/**
Expand All @@ -124,6 +138,28 @@ type IgnoreSpanFilter =
* Spans with an op matching this pattern will be ignored.
*/
op: string | RegExp;
/**
* Spans whose attributes ALL match the corresponding entries will be ignored.
* String attribute values are matched as patterns (substring or RegExp).
* Non-string values match by strict equality (arrays element-wise).
*/
attributes?: Record<string, IgnoreSpanAttributeValue>;
}
| {
/**
* Spans with a name matching this pattern will be ignored.
*/
name?: string | RegExp;
/**
* Spans with an op matching this pattern will be ignored.
*/
op?: string | RegExp;
/**
* Spans whose attributes ALL match the corresponding entries will be ignored.
* String attribute values are matched as patterns (substring or RegExp).
* Non-string values match by strict equality (arrays element-wise).
*/
attributes: Record<string, IgnoreSpanAttributeValue>;
};

export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOptions> {
Expand Down Expand Up @@ -326,7 +362,8 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
* A list of span names or patterns to ignore.
*
* If you specify a pattern {@link IgnoreSpanFilter}, at least one
* of the properties (`op` or `name`) must be set.
* of the properties (`name`, `op`, or `attributes`) must be set.
* When multiple properties are set, all must match for the span to be ignored.
*
* @default []
*/
Expand Down
38 changes: 28 additions & 10 deletions packages/core/src/utils/should-ignore-span.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DEBUG_BUILD } from '../debug-build';
import type { ClientOptions } from '../types-hoist/options';
import type { ClientOptions, IgnoreSpanAttributeValue } from '../types-hoist/options';
import type { SpanJSON } from '../types-hoist/span';
import { debug } from './debug-logger';
import { isMatchingPattern } from './string';
Expand All @@ -12,34 +12,39 @@ function logIgnoredSpan(droppedSpan: Pick<SpanJSON, 'description' | 'op'>): void
* Check if a span should be ignored based on the ignoreSpans configuration.
*/
export function shouldIgnoreSpan(
span: Pick<SpanJSON, 'description' | 'op'>,
span: Pick<SpanJSON, 'description' | 'op'> & { attributes?: Record<string, unknown> },
ignoreSpans: Required<ClientOptions>['ignoreSpans'],
): boolean {
if (!ignoreSpans?.length || !span.description) {
if (!ignoreSpans?.length) {
return false;
}

for (const pattern of ignoreSpans) {
if (isStringOrRegExp(pattern)) {
if (isMatchingPattern(span.description, pattern)) {
if (span.description && isMatchingPattern(span.description, pattern)) {
DEBUG_BUILD && logIgnoredSpan(span);
return true;
}
continue;
}

if (!pattern.name && !pattern.op) {
if (!pattern.name && !pattern.op && !pattern.attributes) {
continue;
}

const nameMatches = pattern.name ? isMatchingPattern(span.description, pattern.name) : true;
const nameMatches = pattern.name ? span.description && isMatchingPattern(span.description, pattern.name) : true;
const opMatches = pattern.op ? span.op && isMatchingPattern(span.op, pattern.op) : true;
const attrsMatch = pattern.attributes
? Object.entries(pattern.attributes).every(([key, valuePattern]) =>
_matchesAttributeValue(span.attributes?.[key], valuePattern),
)
: true;

// This check here is only correct because we can guarantee that we ran `isMatchingPattern`
// for at least one of `nameMatches` and `opMatches`. So in contrary to how this looks,
// not both op and name actually have to match. This is the most efficient way to check
// for all combinations of name and op patterns.
if (nameMatches && opMatches) {
// for at least one of `nameMatches`, `opMatches`, or `attrsMatch`. So in contrary to how this looks,
// not all of op, name, and attributes actually have to match. This is the most efficient way to check
// for all combinations of name, op, and attribute patterns.
if (nameMatches && opMatches && attrsMatch) {
DEBUG_BUILD && logIgnoredSpan(span);
return true;
}
Expand All @@ -48,6 +53,19 @@ export function shouldIgnoreSpan(
return false;
}

function _matchesAttributeValue(actual: unknown, pat: IgnoreSpanAttributeValue): boolean {
// String values support pattern matching
if (typeof actual === 'string' && (typeof pat === 'string' || pat instanceof RegExp)) {
return isMatchingPattern(actual, pat);
}
// Arrays: element-wise strict equality
if (Array.isArray(actual) && Array.isArray(pat)) {
return actual.length === pat.length && actual.every((v, i) => v === pat[i]);
}
// Primitives: strict equality
return actual === pat;
}

/**
* Takes a list of spans, and a span that was dropped, and re-parents the child spans of the dropped span to the parent of the dropped span, if possible.
* This mutates the spans array in place!
Expand Down
Loading
Loading