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
34 changes: 10 additions & 24 deletions packages/astro/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applySdkMetadata } from '@sentry/core';
import type { Event, NodeClient, NodeOptions } from '@sentry/node';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { init as initNodeSdk } from '@sentry/node';

/**
Expand All @@ -13,28 +13,14 @@ export function init(options: NodeOptions): NodeClient | undefined {

applySdkMetadata(opts, 'astro', ['astro', 'node']);

const client = initNodeSdk(opts);
opts.ignoreSpans = [
...(opts.ignoreSpans || []),
// For http.server spans that did not go though the astro middleware,
// we want to drop them
// this is the case with http.server spans of prerendered pages
// we do not care about those, as they are effectively static
{ op: 'http.server', attributes: { 'sentry.origin': 'auto.http.otel.http' } },
];

client?.addEventProcessor(
Object.assign(
(event: Event) => {
// For http.server spans that did not go though the astro middleware,
// we want to drop them
// this is the case with http.server spans of prerendered pages
// we do not care about those, as they are effectively static
if (
event.type === 'transaction' &&
event.contexts?.trace?.op === 'http.server' &&
event.contexts?.trace?.origin === 'auto.http.otel.http'
) {
return null;
}

return event;
},
{ id: 'AstroHttpEventProcessor' },
),
);

return client;
return initNodeSdk(opts);
}
22 changes: 22 additions & 0 deletions packages/astro/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,27 @@ describe('Sentry server SDK', () => {
it('returns client from init', () => {
expect(init({})).not.toBeUndefined();
});

it('configures ignoreSpans to drop prerendered http.server spans', () => {
init({});

expect(nodeInit).toHaveBeenCalledWith(
expect.objectContaining({
ignoreSpans: expect.arrayContaining([
{ op: 'http.server', attributes: { 'sentry.origin': 'auto.http.otel.http' } },
]),
}),
);
});

it('preserves user-provided ignoreSpans entries', () => {
init({ ignoreSpans: [/keep-me/] });

expect(nodeInit).toHaveBeenCalledWith(
expect.objectContaining({
ignoreSpans: expect.arrayContaining([/keep-me/]),
}),
);
});
});
});
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