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
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/]),
}),
);
});
});
});
Loading