diff --git a/dev-packages/e2e-tests/test-applications/node-exports-test-app/package.json b/dev-packages/e2e-tests/test-applications/node-exports-test-app/package.json index 6d187f14c245..432bd7eed4f8 100644 --- a/dev-packages/e2e-tests/test-applications/node-exports-test-app/package.json +++ b/dev-packages/e2e-tests/test-applications/node-exports-test-app/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@sentry/node-experimental": "latest || *", + "@sentry/node": "latest || *", "@sentry/sveltekit": "latest || *", "@sentry/remix": "latest || *", "@sentry/astro": "latest || *", diff --git a/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts b/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts index 5e7344588d56..78f287d37e8c 100644 --- a/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts +++ b/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts @@ -1,38 +1,52 @@ import * as SentryAstro from '@sentry/astro'; import * as SentryBun from '@sentry/bun'; import * as SentryNextJs from '@sentry/nextjs'; -import * as SentryNode from '@sentry/node-experimental'; +import * as SentryNode from '@sentry/node'; +import * as SentryNodeExperimental from '@sentry/node-experimental'; import * as SentryRemix from '@sentry/remix'; import * as SentryServerless from '@sentry/serverless'; import * as SentrySvelteKit from '@sentry/sveltekit'; /* List of exports that are safe to ignore / we don't require in any depending package */ -const NODE_EXPORTS_IGNORE = [ +const NODE_EXPERIMENTAL_EXPORTS_IGNORE = [ 'default', // Probably generated by transpilation, no need to require it '__esModule', - // These Node exports were only made for type definition fixes (see #10339) - 'Undici', + // These are not re-exported where not needed 'Http', - 'DebugSession', - 'AnrIntegrationOptions', - 'LocalVariablesIntegrationOptions', + 'Undici', +]; + +/* List of exports that are safe to ignore / we don't require in any depending package */ +const NODE_EXPORTS_IGNORE = [ + 'default', + // Probably generated by transpilation, no need to require it + '__esModule', ]; +/* Sanitized list of node exports */ +const nodeExperimentalExports = Object.keys(SentryNodeExperimental).filter( + e => !NODE_EXPERIMENTAL_EXPORTS_IGNORE.includes(e), +); +const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e)); + type Dependent = { package: string; exports: string[]; ignoreExports?: string[]; skip?: boolean; + compareWith: string[]; }; const DEPENDENTS: Dependent[] = [ { package: '@sentry/astro', + compareWith: nodeExports, exports: Object.keys(SentryAstro), }, { package: '@sentry/bun', + compareWith: nodeExperimentalExports, exports: Object.keys(SentryBun), ignoreExports: [ // not supported in bun: @@ -44,35 +58,36 @@ const DEPENDENTS: Dependent[] = [ }, { package: '@sentry/nextjs', + compareWith: nodeExperimentalExports, // Next.js doesn't require explicit exports, so we can just merge top level and `default` exports: // @ts-expect-error: `default` is not in the type definition but it's defined exports: Object.keys({ ...SentryNextJs, ...SentryNextJs.default }), }, { package: '@sentry/remix', + compareWith: nodeExperimentalExports, exports: Object.keys(SentryRemix), }, { package: '@sentry/serverless', + compareWith: nodeExperimentalExports, exports: Object.keys(SentryServerless), ignoreExports: ['cron', 'hapiErrorPlugin'], }, { package: '@sentry/sveltekit', + compareWith: nodeExperimentalExports, exports: Object.keys(SentrySvelteKit), }, ]; -/* Sanitized list of node exports */ -const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e)); - console.log('🔎 Checking for consistent exports of @sentry/node exports in depending packages'); const missingExports: Record = {}; const dependentsToCheck = DEPENDENTS.filter(d => !d.skip); -for (const nodeExport of nodeExports) { - for (const dependent of dependentsToCheck) { +for (const dependent of dependentsToCheck) { + for (const nodeExport of dependent.compareWith) { if (dependent.ignoreExports?.includes(nodeExport)) { continue; } diff --git a/packages/astro/package.json b/packages/astro/package.json index cea8347b19f6..7cb351fbc3ec 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -51,7 +51,7 @@ "dependencies": { "@sentry/browser": "8.0.0-alpha.2", "@sentry/core": "8.0.0-alpha.2", - "@sentry/node-experimental": "8.0.0-alpha.2", + "@sentry/node": "8.0.0-alpha.2", "@sentry/types": "8.0.0-alpha.2", "@sentry/utils": "8.0.0-alpha.2", "@sentry/vite-plugin": "^2.14.2" diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 47c301801a35..bc007c82d90d 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -1,5 +1,5 @@ // Node SDK exports -// Unfortunately, we cannot `export * from '@sentry/node-experimental'` because in prod builds, +// Unfortunately, we cannot `export * from '@sentry/node'` because in prod builds, // Vite puts these exports into a `default` property (Sentry.default) rather than // on the top - level namespace. @@ -37,7 +37,6 @@ export { setHttpStatus, withScope, withIsolationScope, - autoDiscoverNodePerformanceMonitoringIntegrations, makeNodeTransport, getDefaultIntegrations, defaultStackParser, @@ -47,7 +46,6 @@ export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData, - Integrations, consoleIntegration, onUncaughtExceptionIntegration, onUnhandledRejectionIntegration, @@ -59,7 +57,6 @@ export { functionToStringIntegration, inboundFiltersIntegration, linkedErrorsIntegration, - Handlers, setMeasurement, getActiveSpan, startSpan, @@ -74,10 +71,24 @@ export { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, -} from '@sentry/node-experimental'; + expressIntegration, + expressErrorHandler, + setupExpressErrorHandler, + fastifyIntegration, + graphqlIntegration, + mongoIntegration, + mongooseIntegration, + mysqlIntegration, + mysql2Integration, + nestIntegration, + postgresIntegration, + prismaIntegration, + hapiIntegration, + setupHapiErrorHandler, +} from '@sentry/node'; // We can still leave this for the carrier init and type exports -export * from '@sentry/node-experimental'; +export * from '@sentry/node'; export { init } from './server/sdk'; diff --git a/packages/astro/src/index.types.ts b/packages/astro/src/index.types.ts index 11ea06bae7c1..4c40343d94ab 100644 --- a/packages/astro/src/index.types.ts +++ b/packages/astro/src/index.types.ts @@ -13,10 +13,6 @@ import sentryAstro from './index.server'; /** Initializes Sentry Astro SDK */ export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): void; -// We only export server Integrations for now, until the exports are removed from Svelte and Node SDKs. -// Necessary to avoid type collision. -export declare const Integrations: typeof serverSdk.Integrations; - export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration; export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration; @@ -26,5 +22,17 @@ export declare const defaultStackParser: StackParser; export declare function close(timeout?: number | undefined): PromiseLike; export declare function flush(timeout?: number | undefined): PromiseLike; +// eslint-disable-next-line deprecation/deprecation +export declare const makeMain: typeof clientSdk.makeMain; +export declare const getActiveSpan: typeof clientSdk.getActiveSpan; +// eslint-disable-next-line deprecation/deprecation +export declare const getCurrentHub: typeof clientSdk.getCurrentHub; +export declare const getClient: typeof clientSdk.getClient; +export declare const startSpan: typeof clientSdk.startSpan; +export declare const startInactiveSpan: typeof clientSdk.startInactiveSpan; +export declare const startSpanManual: typeof clientSdk.startSpanManual; +export declare const withActiveSpan: typeof clientSdk.withActiveSpan; +export declare const Span: clientSdk.Span; + export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics; export default sentryAstro; diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index eedbd9407adf..15e48cb49f12 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -91,7 +91,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { // @sentry/node is required in case we have 2 different @sentry/node // packages installed in the same project. // Ref: https://github.com/getsentry/sentry-javascript/issues/10121 - noExternal: ['@sentry/astro', '@sentry/node-experimental', '@sentry/node'], + noExternal: ['@sentry/astro', '@sentry/node'], }, }, }); diff --git a/packages/astro/src/server/middleware.ts b/packages/astro/src/server/middleware.ts index b5c0e599754a..ec0dbb11d09a 100644 --- a/packages/astro/src/server/middleware.ts +++ b/packages/astro/src/server/middleware.ts @@ -1,13 +1,15 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, setHttpStatus } from '@sentry/core'; import { + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, captureException, continueTrace, getActiveSpan, getClient, getCurrentScope, + setHttpStatus, startSpan, withIsolationScope, -} from '@sentry/node-experimental'; +} from '@sentry/node'; import type { Client, Scope, Span, SpanAttributes } from '@sentry/types'; import { addNonEnumerableProperty, objectify, stripUrlQueryAndFragment } from '@sentry/utils'; import type { APIContext, MiddlewareResponseHandler } from 'astro'; diff --git a/packages/astro/src/server/sdk.ts b/packages/astro/src/server/sdk.ts index d7b4983a7bc3..a34a33cad31d 100644 --- a/packages/astro/src/server/sdk.ts +++ b/packages/astro/src/server/sdk.ts @@ -1,15 +1,22 @@ import { applySdkMetadata } from '@sentry/core'; -import type { NodeOptions } from '@sentry/node-experimental'; -import { init as initNodeSdk, setTag } from '@sentry/node-experimental'; +import type { NodeOptions } from '@sentry/node'; +import { getDefaultIntegrations } from '@sentry/node'; +import { init as initNodeSdk, setTag } from '@sentry/node'; /** * * @param options */ export function init(options: NodeOptions): void { - applySdkMetadata(options, 'astro', ['astro', 'node']); + const opts = { + ...options, + // TODO v8: For now, we disable the Prisma integration, because that has weird esm-cjs interop issues + // We should figure these out and fix these before v8 goes stable. + defaultIntegrations: getDefaultIntegrations(options).filter(integration => integration.name !== 'Prisma'), + }; + applySdkMetadata(opts, 'astro', ['astro', 'node']); - initNodeSdk(options); + initNodeSdk(opts); setTag('runtime', 'node'); } diff --git a/packages/astro/test/client/sdk.test.ts b/packages/astro/test/client/sdk.test.ts index a344cd326bb6..23078dec65f5 100644 --- a/packages/astro/test/client/sdk.test.ts +++ b/packages/astro/test/client/sdk.test.ts @@ -1,11 +1,15 @@ import type { BrowserClient } from '@sentry/browser'; -import { getActiveSpan } from '@sentry/browser'; -import { browserTracingIntegration } from '@sentry/browser'; +import { + browserTracingIntegration, + getActiveSpan, + getCurrentScope, + getGlobalScope, + getIsolationScope, +} from '@sentry/browser'; import * as SentryBrowser from '@sentry/browser'; import { SDK_VERSION, getClient } from '@sentry/browser'; import { vi } from 'vitest'; -import { getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/core'; import { init } from '../../../astro/src/client/sdk'; const browserInit = vi.spyOn(SentryBrowser, 'init'); diff --git a/packages/astro/test/server/meta.test.ts b/packages/astro/test/server/meta.test.ts index 37506cb118b7..8b65beaa4eaf 100644 --- a/packages/astro/test/server/meta.test.ts +++ b/packages/astro/test/server/meta.test.ts @@ -5,7 +5,7 @@ import { vi } from 'vitest'; import { getTracingMetaTags, isValidBaggageString } from '../../src/server/meta'; -const TRACE_FLAG_SAMPLED = 0x1; +const TRACE_FLAG_SAMPLED = 1; const mockedSpan = new SentrySpan({ traceId: '12345678901234567890123456789012', diff --git a/packages/astro/test/server/middleware.test.ts b/packages/astro/test/server/middleware.test.ts index cd5caec43c48..a678fcceaee6 100644 --- a/packages/astro/test/server/middleware.test.ts +++ b/packages/astro/test/server/middleware.test.ts @@ -1,5 +1,5 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; -import * as SentryNode from '@sentry/node-experimental'; +import * as SentryNode from '@sentry/node'; import type { Client, Span } from '@sentry/types'; import { vi } from 'vitest'; diff --git a/packages/astro/test/server/sdk.test.ts b/packages/astro/test/server/sdk.test.ts index b1dc3821c88f..1b042ee5331a 100644 --- a/packages/astro/test/server/sdk.test.ts +++ b/packages/astro/test/server/sdk.test.ts @@ -1,5 +1,5 @@ -import * as SentryNode from '@sentry/node-experimental'; -import { SDK_VERSION } from '@sentry/node-experimental'; +import * as SentryNode from '@sentry/node'; +import { SDK_VERSION } from '@sentry/node'; import { vi } from 'vitest'; import { init } from '../../src/server/sdk'; diff --git a/packages/node-experimental/src/proxy/helpers.ts b/packages/node-experimental/src/proxy/helpers.ts index 2fa5b84f6ccb..031878511f6c 100644 --- a/packages/node-experimental/src/proxy/helpers.ts +++ b/packages/node-experimental/src/proxy/helpers.ts @@ -27,8 +27,8 @@ */ /* eslint-disable jsdoc/require-jsdoc */ -import * as http from 'http'; -import * as https from 'https'; +import * as http from 'node:http'; +import * as https from 'node:https'; import type { Readable } from 'stream'; export type ThenableRequest = http.ClientRequest & { diff --git a/packages/node-experimental/src/transports/http-module.ts b/packages/node-experimental/src/transports/http-module.ts index 26bb37b6f4b9..f5cbe6fd35f9 100644 --- a/packages/node-experimental/src/transports/http-module.ts +++ b/packages/node-experimental/src/transports/http-module.ts @@ -1,5 +1,5 @@ -import type { ClientRequest, IncomingHttpHeaders, RequestOptions as HTTPRequestOptions } from 'http'; -import type { RequestOptions as HTTPSRequestOptions } from 'https'; +import type { ClientRequest, IncomingHttpHeaders, RequestOptions as HTTPRequestOptions } from 'node:http'; +import type { RequestOptions as HTTPSRequestOptions } from 'node:https'; export type HTTPModuleRequestOptions = HTTPRequestOptions | HTTPSRequestOptions | string | URL; diff --git a/packages/node-experimental/src/transports/http.ts b/packages/node-experimental/src/transports/http.ts index 532367578fb5..1fb84d9e8570 100644 --- a/packages/node-experimental/src/transports/http.ts +++ b/packages/node-experimental/src/transports/http.ts @@ -1,5 +1,5 @@ -import * as http from 'http'; -import * as https from 'https'; +import * as http from 'node:http'; +import * as https from 'node:https'; import { Readable } from 'stream'; import { createGzip } from 'zlib'; import { createTransport } from '@sentry/core';