From 935b98ad5dbb319b48282c95be36dc661e366eaa Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 23 Oct 2026 14:08:45 -0700 Subject: [PATCH] feat(astro): Add `@sentry/astro/integration` entry for the Astro integration The root entry of `@sentry/astro` is both the server runtime SDK and, through its default export, the Astro integration for `astro.config`. The integration imports `@sentry/bundler-plugins/vite`, the orchestrion Vite plugin, `fs` and `createRequire`, so the server runtime entry reaches all of them. Any tool that traces or bundles the server entry then pulls that tooling in. The new `@sentry/astro/integration` entry exports the integration as its default and as `sentryAstro`. The root default export stays, deprecated, until the next major version, so existing `astro.config` files keep working. The E2E apps use the new entry. The new entry has a `node` condition that points at the ESM build, the same as `./middleware`. The CJS build of `@sentry/astro` does not load under the package's `"type": "module"`, and the existing entries avoid it the same way. Refs #25676 Co-Authored-By: Claude Opus 5.5 (1M context) --- .../e2e-tests/test-applications/astro-4/astro.config.mjs | 2 +- .../astro-5-cf-workers/astro.config.mjs | 2 +- .../e2e-tests/test-applications/astro-5/astro.config.mjs | 2 +- .../astro-6-cf-workers/astro.config.mjs | 2 +- .../e2e-tests/test-applications/astro-6/astro.config.mjs | 2 +- .../astro-7-sourcemaps/astro.config.mjs | 2 +- .../test-applications/astro-7-static/astro.config.mjs | 2 +- .../e2e-tests/test-applications/astro-7/astro.config.mjs | 2 +- packages/astro/package.json | 6 ++++++ packages/astro/rollup.npm.config.mjs | 7 ++++++- packages/astro/src/index.integration.ts | 5 +++++ packages/astro/src/index.server.ts | 9 ++++++++- packages/astro/src/index.types.ts | 1 + packages/astro/test/server/index.server.test.ts | 5 +++-- 14 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 packages/astro/src/index.integration.ts diff --git a/dev-packages/e2e-tests/test-applications/astro-4/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-4/astro.config.mjs index 890d1f737e9a..d0848b0f6d00 100644 --- a/dev-packages/e2e-tests/test-applications/astro-4/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-4/astro.config.mjs @@ -1,5 +1,5 @@ import node from '@astrojs/node'; -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; import { defineConfig } from 'astro/config'; import spotlightjs from '@spotlightjs/astro'; diff --git a/dev-packages/e2e-tests/test-applications/astro-5-cf-workers/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-5-cf-workers/astro.config.mjs index 0473ef424d83..a3687388202b 100644 --- a/dev-packages/e2e-tests/test-applications/astro-5-cf-workers/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-5-cf-workers/astro.config.mjs @@ -1,5 +1,5 @@ import cloudflare from '@astrojs/cloudflare'; -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; // @ts-check import { defineConfig } from 'astro/config'; diff --git a/dev-packages/e2e-tests/test-applications/astro-5/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-5/astro.config.mjs index 061db869d94b..54d1c2bbb8cd 100644 --- a/dev-packages/e2e-tests/test-applications/astro-5/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-5/astro.config.mjs @@ -1,4 +1,4 @@ -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; // @ts-check import { defineConfig } from 'astro/config'; diff --git a/dev-packages/e2e-tests/test-applications/astro-6-cf-workers/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-6-cf-workers/astro.config.mjs index 0894958462b2..3e3f72d55942 100644 --- a/dev-packages/e2e-tests/test-applications/astro-6-cf-workers/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-6-cf-workers/astro.config.mjs @@ -1,4 +1,4 @@ -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; // @ts-check import { defineConfig } from 'astro/config'; import cloudflare from '@astrojs/cloudflare'; diff --git a/dev-packages/e2e-tests/test-applications/astro-6/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-6/astro.config.mjs index 061db869d94b..54d1c2bbb8cd 100644 --- a/dev-packages/e2e-tests/test-applications/astro-6/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-6/astro.config.mjs @@ -1,4 +1,4 @@ -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; // @ts-check import { defineConfig } from 'astro/config'; diff --git a/dev-packages/e2e-tests/test-applications/astro-7-sourcemaps/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-7-sourcemaps/astro.config.mjs index 3b859eeb1c75..53887471a483 100644 --- a/dev-packages/e2e-tests/test-applications/astro-7-sourcemaps/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-7-sourcemaps/astro.config.mjs @@ -1,5 +1,5 @@ import node from '@astrojs/node'; -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; import { defineConfig } from 'astro/config'; import * as fs from 'node:fs'; diff --git a/dev-packages/e2e-tests/test-applications/astro-7-static/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-7-static/astro.config.mjs index 061db869d94b..54d1c2bbb8cd 100644 --- a/dev-packages/e2e-tests/test-applications/astro-7-static/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-7-static/astro.config.mjs @@ -1,4 +1,4 @@ -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; // @ts-check import { defineConfig } from 'astro/config'; diff --git a/dev-packages/e2e-tests/test-applications/astro-7/astro.config.mjs b/dev-packages/e2e-tests/test-applications/astro-7/astro.config.mjs index 061db869d94b..54d1c2bbb8cd 100644 --- a/dev-packages/e2e-tests/test-applications/astro-7/astro.config.mjs +++ b/dev-packages/e2e-tests/test-applications/astro-7/astro.config.mjs @@ -1,4 +1,4 @@ -import sentry from '@sentry/astro'; +import sentry from '@sentry/astro/integration'; // @ts-check import { defineConfig } from 'astro/config'; diff --git a/packages/astro/package.json b/packages/astro/package.json index 780ef8ff260f..e91d7e253975 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -32,6 +32,12 @@ "import": "./build/esm/index.client.js", "require": "./build/cjs/index.server.js" }, + "./integration": { + "types": "./build/types/index.integration.d.ts", + "node": "./build/esm/index.integration.js", + "import": "./build/esm/index.integration.js", + "require": "./build/cjs/index.integration.js" + }, "./middleware": { "types": "./build/types/integration/middleware/index.d.ts", "node": "./build/esm/integration/middleware/index.js", diff --git a/packages/astro/rollup.npm.config.mjs b/packages/astro/rollup.npm.config.mjs index e4694afbff88..07a25d8690b1 100644 --- a/packages/astro/rollup.npm.config.mjs +++ b/packages/astro/rollup.npm.config.mjs @@ -2,7 +2,12 @@ import { makeBaseNPMConfig, makeNPMConfigVariants, makeOrchestrionLoader } from const variants = makeNPMConfigVariants( makeBaseNPMConfig({ - entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/integration/middleware/index.ts'], + entrypoints: [ + 'src/index.server.ts', + 'src/index.client.ts', + 'src/index.integration.ts', + 'src/integration/middleware/index.ts', + ], packageSpecificConfig: { output: { dynamicImportInCjs: true, diff --git a/packages/astro/src/index.integration.ts b/packages/astro/src/index.integration.ts new file mode 100644 index 000000000000..64465a872d83 --- /dev/null +++ b/packages/astro/src/index.integration.ts @@ -0,0 +1,5 @@ +import { sentryAstro } from './integration'; + +export { sentryAstro }; + +export default sentryAstro; diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 80158e311e49..65c5cc8a8d4e 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -3,7 +3,7 @@ // Vite puts these exports into a `default` property (Sentry.default) rather than // on the top - level namespace. -import { sentryAstro } from './integration'; +import { sentryAstro as _sentryAstro } from './integration'; import { handleRequest } from './server/middleware'; // Hence, we export everything from the Node SDK explicitly: @@ -206,6 +206,13 @@ export { export { init } from './server/sdk'; +/** + * @deprecated Import the integration from `@sentry/astro/integration` instead. + * This export will be removed in the next major version. + */ +const sentryAstro = _sentryAstro; + +// oxlint-disable-next-line typescript/no-deprecated export default sentryAstro; // This exports the `handleRequest` middleware for manual usage diff --git a/packages/astro/src/index.types.ts b/packages/astro/src/index.types.ts index c08b0b7199f4..c6287009e916 100644 --- a/packages/astro/src/index.types.ts +++ b/packages/astro/src/index.types.ts @@ -46,4 +46,5 @@ export declare const statsigIntegration: typeof clientSdk.statsigIntegration; export declare const unleashIntegration: typeof clientSdk.unleashIntegration; export declare const growthbookIntegration: typeof clientSdk.growthbookIntegration; +// oxlint-disable-next-line typescript/no-deprecated export default sentryAstro; diff --git a/packages/astro/test/server/index.server.test.ts b/packages/astro/test/server/index.server.test.ts index 4a89ebe16a13..6c1ed2de3127 100644 --- a/packages/astro/test/server/index.server.test.ts +++ b/packages/astro/test/server/index.server.test.ts @@ -1,9 +1,10 @@ import { describe, expect, it } from 'vitest'; +import sentryAstroIntegration from '../../src/index.integration'; +// oxlint-disable-next-line typescript/no-deprecated import sentryAstro from '../../src/index.server'; describe('server SDK', () => { it('exports the astro integration as a default export', () => { - const integration = sentryAstro(); - expect(integration.name).toBe('@sentry/astro'); + expect(sentryAstro).toBe(sentryAstroIntegration); }); });