Skip to content

Commit 4932714

Browse files
authored
feat(astro): Drop prerendered http.server filter via ignoreSpans (#20513)
Migrates the Astro server pre-rendered route drop filter from an event processor to `ignoreSpans` so it also works in the streaming path. This only adds two unit tests, since the actual drop behavior is already tested by several astro e2e test apps. Closes #20375
1 parent b44ff35 commit 4932714

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

packages/astro/src/server/sdk.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { applySdkMetadata } from '@sentry/core';
2-
import type { Event, NodeClient, NodeOptions } from '@sentry/node';
2+
import type { NodeClient, NodeOptions } from '@sentry/node';
33
import { init as initNodeSdk } from '@sentry/node';
44

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

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

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

18-
client?.addEventProcessor(
19-
Object.assign(
20-
(event: Event) => {
21-
// For http.server spans that did not go though the astro middleware,
22-
// we want to drop them
23-
// this is the case with http.server spans of prerendered pages
24-
// we do not care about those, as they are effectively static
25-
if (
26-
event.type === 'transaction' &&
27-
event.contexts?.trace?.op === 'http.server' &&
28-
event.contexts?.trace?.origin === 'auto.http.otel.http'
29-
) {
30-
return null;
31-
}
32-
33-
return event;
34-
},
35-
{ id: 'AstroHttpEventProcessor' },
36-
),
37-
);
38-
39-
return client;
25+
return initNodeSdk(opts);
4026
}

packages/astro/test/server/sdk.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,27 @@ describe('Sentry server SDK', () => {
4141
it('returns client from init', () => {
4242
expect(init({})).not.toBeUndefined();
4343
});
44+
45+
it('configures ignoreSpans to drop prerendered http.server spans', () => {
46+
init({});
47+
48+
expect(nodeInit).toHaveBeenCalledWith(
49+
expect.objectContaining({
50+
ignoreSpans: expect.arrayContaining([
51+
{ op: 'http.server', attributes: { 'sentry.origin': 'auto.http.otel.http' } },
52+
]),
53+
}),
54+
);
55+
});
56+
57+
it('preserves user-provided ignoreSpans entries', () => {
58+
init({ ignoreSpans: [/keep-me/] });
59+
60+
expect(nodeInit).toHaveBeenCalledWith(
61+
expect.objectContaining({
62+
ignoreSpans: expect.arrayContaining([/keep-me/]),
63+
}),
64+
);
65+
});
4466
});
4567
});

0 commit comments

Comments
 (0)