From 2a84661f37004d859ad15286e1dee90e939a27ec Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Sat, 25 Apr 2026 11:04:09 +0200 Subject: [PATCH 1/2] use ignore spans for astro server event processor --- packages/astro/src/server/sdk.ts | 34 ++++++++++---------------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/packages/astro/src/server/sdk.ts b/packages/astro/src/server/sdk.ts index 25dbb9416fe6..727350f2b046 100644 --- a/packages/astro/src/server/sdk.ts +++ b/packages/astro/src/server/sdk.ts @@ -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'; /** @@ -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); } From 57d8ca0fc4c8e8af08040914f44125d8e8eb138e Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Sat, 25 Apr 2026 11:20:53 +0200 Subject: [PATCH 2/2] add some unit tests --- packages/astro/test/server/sdk.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/astro/test/server/sdk.test.ts b/packages/astro/test/server/sdk.test.ts index 1d915152fdcc..19c80f4f46f0 100644 --- a/packages/astro/test/server/sdk.test.ts +++ b/packages/astro/test/server/sdk.test.ts @@ -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/]), + }), + ); + }); }); });