From 22a14ce66dc1a9e4d58586fac2fca3bb2eed7411 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 8 Mar 2024 13:31:46 -0500 Subject: [PATCH 01/12] Update @sentry/bun to use OTEL node --- .../scripts/consistentExports.ts | 12 +-- packages/bun/package.json | 2 +- packages/bun/src/index.ts | 89 +++++++++---------- 3 files changed, 45 insertions(+), 58 deletions(-) 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 0f0c4d3ac104..5d7d9ecd1964 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 @@ -49,21 +49,11 @@ const DEPENDENTS: Dependent[] = [ }, { package: '@sentry/bun', - compareWith: nodeExperimentalExports, + compareWith: nodeExports, exports: Object.keys(SentryBun), ignoreExports: [ // not supported in bun: - 'Handlers', 'NodeClient', - 'hapiErrorPlugin', - 'makeNodeTransport', - // TODO: remove these when we switch exports from nodeExperimentalExports to nodeExports - 'Integrations', - 'addGlobalEventProcessor', - 'getActiveTransaction', - 'getCurrentHub', - 'makeMain', - 'startTransaction', ], }, { diff --git a/packages/bun/package.json b/packages/bun/package.json index ff7bdf6c5147..fd6bea26fe3d 100644 --- a/packages/bun/package.json +++ b/packages/bun/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "@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" }, diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 30bb42eff92c..0b58008aed03 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -18,19 +18,17 @@ export type { } from '@sentry/types'; export type { AddRequestDataToEventOptions } from '@sentry/utils'; -export type { TransactionNamingScheme } from '@sentry/node-experimental'; -export type { BunOptions } from './types'; - export { addEventProcessor, addBreadcrumb, - addIntegration, captureException, captureEvent, captureMessage, - close, + captureCheckIn, + withMonitor, createTransport, - flush, + // eslint-disable-next-line deprecation/deprecation + getCurrentHub, getClient, isInitialized, getCurrentScope, @@ -50,8 +48,25 @@ export { setHttpStatus, withScope, withIsolationScope, - captureCheckIn, - withMonitor, + makeNodeTransport, + defaultStackParser, + flush, + close, + getSentryRelease, + addRequestDataToEvent, + DEFAULT_USER_INCLUDES, + extractRequestData, + consoleIntegration, + onUncaughtExceptionIntegration, + onUnhandledRejectionIntegration, + modulesIntegration, + contextLinesIntegration, + nodeContextIntegration, + localVariablesIntegration, + requestDataIntegration, + functionToStringIntegration, + inboundFiltersIntegration, + linkedErrorsIntegration, setMeasurement, getActiveSpan, getRootSpan, @@ -61,53 +76,35 @@ export { withActiveSpan, getSpanDescendants, continueTrace, - metricsDefault as metrics, - functionToStringIntegration, - inboundFiltersIntegration, - linkedErrorsIntegration, - requestDataIntegration, - captureConsoleIntegration, - debugIntegration, - dedupeIntegration, - extraErrorDataIntegration, - rewriteFramesIntegration, - sessionTimingIntegration, - parameterize, - startSession, - captureSession, - endSession, -} from '@sentry/core'; -export { - DEFAULT_USER_INCLUDES, - autoDiscoverNodePerformanceMonitoringIntegrations, cron, - createGetModuleFromFilename, - defaultStackParser, - extractRequestData, - getSentryRelease, - addRequestDataToEvent, - anrIntegration, - consoleIntegration, - contextLinesIntegration, - hapiIntegration, - httpIntegration, - localVariablesIntegration, - modulesIntegration, - nativeNodeFetchintegration, - nodeContextIntegration, - onUncaughtExceptionIntegration, - onUnhandledRejectionIntegration, - spotlightIntegration, + parameterize, SEMANTIC_ATTRIBUTE_SENTRY_OP, 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, + spotlightIntegration, +} from '@sentry/node'; + +export type { BunOptions } from './types'; export { BunClient } from './client'; export { getDefaultIntegrations, init, } from './sdk'; - export { bunServerIntegration } from './integrations/bunserver'; +export { makeFetchTransport } from './transports'; From 1bdd0b3be0c983be9a322cff85b7ec648511b59f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 8 Mar 2024 14:58:43 -0500 Subject: [PATCH 02/12] make sure exports are included --- packages/bun/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 0b58008aed03..7783b3df8de4 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -77,6 +77,7 @@ export { getSpanDescendants, continueTrace, cron, + metrics, parameterize, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, From ccda87f4425881601bc547de8f5d01b25ed9b959 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 11 Mar 2024 16:02:40 -0400 Subject: [PATCH 03/12] emit cjs for bun --- packages/bun/package.json | 2 +- packages/bun/rollup.npm.config.mjs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/bun/package.json b/packages/bun/package.json index fd6bea26fe3d..74d05fd64616 100644 --- a/packages/bun/package.json +++ b/packages/bun/package.json @@ -15,7 +15,7 @@ "types", "types-ts3.8" ], - "main": "build/esm/index.js", + "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", "exports": { diff --git a/packages/bun/rollup.npm.config.mjs b/packages/bun/rollup.npm.config.mjs index 19f01d8cb3f8..84a06f2fb64a 100644 --- a/packages/bun/rollup.npm.config.mjs +++ b/packages/bun/rollup.npm.config.mjs @@ -1,6 +1,3 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; -const config = makeNPMConfigVariants(makeBaseNPMConfig()); - -// remove cjs from config array config[0].output.format == cjs -export default [config[1]]; +export default makeNPMConfigVariants(makeBaseNPMConfig()); From cd2363cb48b014b10a745c821712a0ed19b492d0 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 11 Mar 2024 16:42:48 -0400 Subject: [PATCH 04/12] fix type --- packages/bun/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bun/package.json b/packages/bun/package.json index 74d05fd64616..034c0cd0b948 100644 --- a/packages/bun/package.json +++ b/packages/bun/package.json @@ -33,8 +33,8 @@ }, "typesVersions": { "<4.9": { - "build/npm/types/index.d.ts": [ - "build/npm/types-ts3.8/index.d.ts" + "build/types/index.d.ts": [ + "build/types-ts3.8/index.d.ts" ] } }, From b83089ed36b4cb41130c0761d94de7592b7ddb49 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 13:15:16 -0400 Subject: [PATCH 05/12] use CJS import for bun SDK --- .../node-exports-test-app/scripts/consistentExports.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 5d7d9ecd1964..c2dac81a44b0 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,5 +1,4 @@ import * as SentryAstro from '@sentry/astro'; -import * as SentryBun from '@sentry/bun'; import * as SentryGoogleCloud from '@sentry/google-cloud'; import * as SentryNextJs from '@sentry/nextjs'; import * as SentryNode from '@sentry/node'; @@ -9,6 +8,8 @@ import * as SentrySvelteKit from '@sentry/sveltekit'; // SentryAWS is CJS only const SentryAWS = require('@sentry/aws-serverless'); +// Using CJS export for Bun SDK +const SentryBun = require('@sentry/bun'); /* List of exports that are safe to ignore / we don't require in any depending package */ const NODE_EXPERIMENTAL_EXPORTS_IGNORE = [ From ebe378063a1991ce80809d1e8fe6564f3af2e4f7 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 14:01:45 -0400 Subject: [PATCH 06/12] found the bug --- .../scripts/consistentExports.ts | 3 ++- packages/bun/src/client.ts | 3 +-- packages/bun/src/sdk.ts | 6 +++--- packages/bun/tsconfig.json | 18 ++---------------- 4 files changed, 8 insertions(+), 22 deletions(-) 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 c2dac81a44b0..bafcbadc7c4d 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,4 +1,5 @@ import * as SentryAstro from '@sentry/astro'; +import * as SentryBun from '@sentry/bun'; import * as SentryGoogleCloud from '@sentry/google-cloud'; import * as SentryNextJs from '@sentry/nextjs'; import * as SentryNode from '@sentry/node'; @@ -9,7 +10,7 @@ import * as SentrySvelteKit from '@sentry/sveltekit'; // SentryAWS is CJS only const SentryAWS = require('@sentry/aws-serverless'); // Using CJS export for Bun SDK -const SentryBun = require('@sentry/bun'); +// const SentryBun = require('@sentry/bun'); /* List of exports that are safe to ignore / we don't require in any depending package */ const NODE_EXPERIMENTAL_EXPORTS_IGNORE = [ diff --git a/packages/bun/src/client.ts b/packages/bun/src/client.ts index 7b3a350f2821..40e430dc2545 100644 --- a/packages/bun/src/client.ts +++ b/packages/bun/src/client.ts @@ -1,7 +1,6 @@ import * as os from 'os'; import type { ServerRuntimeClientOptions } from '@sentry/core'; -import { applySdkMetadata } from '@sentry/core'; -import { ServerRuntimeClient } from '@sentry/core'; +import { ServerRuntimeClient, applySdkMetadata } from '@sentry/core'; import type { BunClientOptions } from './types'; diff --git a/packages/bun/src/sdk.ts b/packages/bun/src/sdk.ts index b7eddfed9c73..db39e0361dfa 100644 --- a/packages/bun/src/sdk.ts +++ b/packages/bun/src/sdk.ts @@ -11,9 +11,9 @@ import { httpIntegration, init as initNode, modulesIntegration, - nativeNodeFetchintegration, + nativeNodeFetchIntegration, nodeContextIntegration, -} from '@sentry/node-experimental'; +} from '@sentry/node'; import type { Integration, Options } from '@sentry/types'; import { BunClient } from './client'; @@ -33,7 +33,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] { // Native Wrappers consoleIntegration(), httpIntegration(), - nativeNodeFetchintegration(), + nativeNodeFetchIntegration(), // Global Handlers # TODO (waiting for https://github.com/oven-sh/bun/issues/5091) // new NodeIntegrations.OnUncaughtException(), // new NodeIntegrations.OnUnhandledRejection(), diff --git a/packages/bun/tsconfig.json b/packages/bun/tsconfig.json index 70c4bde02040..dcbef254b942 100644 --- a/packages/bun/tsconfig.json +++ b/packages/bun/tsconfig.json @@ -4,21 +4,7 @@ "include": ["src/**/*"], "compilerOptions": { - "types": ["bun-types"], - "lib": ["esnext"], - "module": "esnext", - "target": "esnext", - - // if TS 4.x or earlier - "moduleResolution": "nodenext", - - "jsx": "react-jsx", // support JSX - "allowJs": true, // allow importing `.js` from `.ts` - "esModuleInterop": true, // allow default imports for CommonJS modules - - // best practices - "strict": true, - "forceConsistentCasingInFileNames": true, - "skipLibCheck": true + // package-specific options + "types": ["bun-types"] } } From 5d6362bbd9af871753d5bd0db3abf0ecf63f3fda Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 14:02:41 -0400 Subject: [PATCH 07/12] lint fix --- packages/bun/src/sdk.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/bun/src/sdk.ts b/packages/bun/src/sdk.ts index db39e0361dfa..51099eb814b2 100644 --- a/packages/bun/src/sdk.ts +++ b/packages/bun/src/sdk.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-lines */ import { functionToStringIntegration, inboundFiltersIntegration, From ffac2d8dbc0468197107b6b2a7630f32b9de2d7c Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 14:12:47 -0400 Subject: [PATCH 08/12] correct exports --- packages/bun/src/index.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 7783b3df8de4..0b1c76f31afe 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -21,10 +21,14 @@ export type { AddRequestDataToEventOptions } from '@sentry/utils'; export { addEventProcessor, addBreadcrumb, + addIntegration, captureException, captureEvent, captureMessage, captureCheckIn, + startSession, + captureSession, + endSession, withMonitor, createTransport, // eslint-disable-next-line deprecation/deprecation @@ -49,6 +53,7 @@ export { withScope, withIsolationScope, makeNodeTransport, + NodeClient, defaultStackParser, flush, close, @@ -56,7 +61,11 @@ export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData, + createGetModuleFromFilename, + anrIntegration, consoleIntegration, + httpIntegration, + nativeNodeFetchIntegration, onUncaughtExceptionIntegration, onUnhandledRejectionIntegration, modulesIntegration, @@ -69,13 +78,14 @@ export { linkedErrorsIntegration, setMeasurement, getActiveSpan, - getRootSpan, startSpan, startInactiveSpan, startSpanManual, withActiveSpan, + getRootSpan, getSpanDescendants, continueTrace, + getAutoPerformanceIntegrations, cron, metrics, parameterize, @@ -100,6 +110,15 @@ export { spotlightIntegration, } from '@sentry/node'; +export { + captureConsoleIntegration, + debugIntegration, + dedupeIntegration, + extraErrorDataIntegration, + rewriteFramesIntegration, + sessionTimingIntegration, +} from '@sentry/core'; + export type { BunOptions } from './types'; export { BunClient } from './client'; From 402f657ee781479d2c950f19651514dd5d6c3b1f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 14:13:26 -0400 Subject: [PATCH 09/12] node client too --- .../node-exports-test-app/scripts/consistentExports.ts | 1 + packages/google-cloud/src/index.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) 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 bafcbadc7c4d..c46f77e2abeb 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 @@ -56,6 +56,7 @@ const DEPENDENTS: Dependent[] = [ ignoreExports: [ // not supported in bun: 'NodeClient', + 'makeMain' ], }, { diff --git a/packages/google-cloud/src/index.ts b/packages/google-cloud/src/index.ts index 6505088d7c93..46331ee81dbe 100644 --- a/packages/google-cloud/src/index.ts +++ b/packages/google-cloud/src/index.ts @@ -33,7 +33,6 @@ export { withScope, withIsolationScope, makeNodeTransport, - NodeClient, defaultStackParser, flush, close, From 8c09d8da4854baf58b64209f852b6d4099e6ae37 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 14:17:10 -0400 Subject: [PATCH 10/12] yarn fix --- .../node-exports-test-app/scripts/consistentExports.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c46f77e2abeb..a2291fb35f35 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 @@ -56,7 +56,7 @@ const DEPENDENTS: Dependent[] = [ ignoreExports: [ // not supported in bun: 'NodeClient', - 'makeMain' + 'makeMain', ], }, { From 2493d652c75c3a1a5604ac9ba1c84790c074ab70 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 12 Mar 2024 14:44:48 -0400 Subject: [PATCH 11/12] node client --- .../node-exports-test-app/scripts/consistentExports.ts | 2 -- packages/google-cloud/src/index.ts | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) 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 a2291fb35f35..d6612bc6a8e8 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 @@ -9,8 +9,6 @@ import * as SentrySvelteKit from '@sentry/sveltekit'; // SentryAWS is CJS only const SentryAWS = require('@sentry/aws-serverless'); -// Using CJS export for Bun SDK -// const SentryBun = require('@sentry/bun'); /* List of exports that are safe to ignore / we don't require in any depending package */ const NODE_EXPERIMENTAL_EXPORTS_IGNORE = [ diff --git a/packages/google-cloud/src/index.ts b/packages/google-cloud/src/index.ts index 46331ee81dbe..6505088d7c93 100644 --- a/packages/google-cloud/src/index.ts +++ b/packages/google-cloud/src/index.ts @@ -33,6 +33,7 @@ export { withScope, withIsolationScope, makeNodeTransport, + NodeClient, defaultStackParser, flush, close, From 5c5918f48074cfc2bd94401dbb99baafb7578b1e Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 13 Mar 2024 10:04:57 -0400 Subject: [PATCH 12/12] add setupFastifyErrorHandler to bun --- .../node-exports-test-app/scripts/consistentExports.ts | 1 + packages/bun/src/index.ts | 1 + 2 files changed, 2 insertions(+) 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 eee82c881d4e..99d2ed614d2b 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 @@ -58,6 +58,7 @@ const DEPENDENTS: Dependent[] = [ ignoreExports: [ // not supported in bun: 'NodeClient', + // legacy, to be removed... 'makeMain', ], }, diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 0b1c76f31afe..da25f6cb08bd 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -97,6 +97,7 @@ export { expressErrorHandler, setupExpressErrorHandler, fastifyIntegration, + setupFastifyErrorHandler, graphqlIntegration, mongoIntegration, mongooseIntegration,