Skip to content
Merged
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',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bundle size increased across browser packages

Low Severity

Multiple browser bundle size limits were raised by ~1 KB gzipped (e.g., @sentry/browser 26→27 KB, tracing 44→45 KB, @sentry/svelte 26→27 KB, plus several CDN bundles). Per project rules, large bundle size increases in browser packages need to be flagged even when they may be unavoidable for a new feature.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit aad1cb6. Configure here.

disablePlugins: ['@size-limit/esbuild'],
},
{
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = [
path: 'packages/browser/build/npm/esm/prod/index.js',
import: createImport('init', 'browserTracingIntegration'),
gzip: true,
limit: '44 KB',
limit: '45 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = [
path: 'packages/browser/build/npm/esm/prod/index.js',
import: createImport('init', 'feedbackAsyncIntegration'),
gzip: true,
limit: '36 KB',
limit: '37 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
Expand Down Expand Up @@ -197,7 +197,7 @@ module.exports = [
path: 'packages/svelte/build/esm/index.js',
import: createImport('init'),
gzip: true,
limit: '26 KB',
limit: '27 KB',
disablePlugins: ['@size-limit/esbuild'],
},
// Browser CDN bundles
Expand Down Expand Up @@ -254,7 +254,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',
disablePlugins: ['@size-limit/esbuild'],
},
{
Expand All @@ -270,15 +270,15 @@ module.exports = [
path: createCDNPath('bundle.min.js'),
gzip: false,
brotli: false,
limit: '84 KB',
limit: '85 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
name: 'CDN Bundle (incl. Tracing) - uncompressed',
path: createCDNPath('bundle.tracing.min.js'),
gzip: false,
brotli: false,
limit: '138 KB',
limit: '139 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
Expand All @@ -294,39 +294,39 @@ module.exports = [
path: createCDNPath('bundle.tracing.logs.metrics.min.js'),
gzip: false,
brotli: false,
limit: '141.5 KB',
limit: '142 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
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',
disablePlugins: ['@size-limit/esbuild'],
},
{
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',
disablePlugins: ['@size-limit/esbuild'],
},
{
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',
disablePlugins: ['@size-limit/esbuild'],
},
{
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',
disablePlugins: ['@size-limit/esbuild'],
},
{
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
traceLifecycle: 'stream',
ignoreSpans: [{ attributes: { 'http.method': 'POST' } }],
clientReportFlushInterval: 1_000,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import express from 'express';
import cors from 'cors';
import * as Sentry from '@sentry/node';
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';

const app = express();

app.use(cors());

app.get('/keep', (_req, res) => {
res.send({ status: 'kept' });
setTimeout(() => {
// flush to avoid waiting for the span buffer timeout to send spans
// but defer it to the next tick to let the SDK finish the http.server span first.
Sentry.flush();
});
});

app.post('/drop', (_req, res) => {
res.send({ status: 'dropped' });
});

Sentry.setupExpressErrorHandler(app);

startExpressServerAndSendPortToRunner(app);
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';

describe('filtering segment spans by attribute with ignoreSpans (streaming)', () => {
afterAll(() => {
cleanupChildProcesses();
});

createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => {
test('segment spans matching an attribute filter are dropped including all children', async () => {
const runner = createRunner()
.unignore('client_report')
.expect({
client_report: {
discarded_events: [
{
category: 'span',
quantity: 5, // 1 segment ignored + 4 child spans (implicitly ignored)
reason: 'ignored',
},
],
},
})
.expect({
span: container => {
expect(container.items).toHaveLength(5);
const segmentSpan = container.items.find(s => s.name === 'GET /keep' && !!s.is_segment);

expect(segmentSpan).toBeDefined();
expect(container.items.every(s => s.trace_id === segmentSpan!.trace_id)).toBe(true);
},
})
.start();

const dropRes = await runner.makeRequest('post', '/drop');
expect((dropRes as { status: string }).status).toBe('dropped');

const keepRes = await runner.makeRequest('get', '/keep');
expect((keepRes as { status: string }).status).toBe('kept');

await runner.completed();
});
});
});
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
Loading
Loading