diff --git a/MIGRATION.md b/MIGRATION.md index f975b13c0f4d..93cf0f730db1 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -11,6 +11,34 @@ enum. If you were using the `Severity` enum, you should replace it with the `Sev The `Offline` integration has been removed in favor of the offline transport wrapper: http://docs.sentry.io/platforms/javascript/configuration/transports/#offline-caching +## Updating `@sentry/serverless` exports + +The `AWSServices`, `GoogleCloudGrpc`, and `GoogleCloudHttp`. integrations have been removed from `@sentry/serverless` package. See the [table below](#deprecate-class-based-integrations) to find what to upgrade to. + +We've also updated the package to use subpath exports instead of namespace exports with `Sentry.AWSLambda` and `Sentry.GCPFunction`. This helps with tree-shaking and organizes the code better. Below is an example of how your imports should look after the upgrade: + +```js +// before +import * as Sentry from '@sentry/serverless'; + +Sentry.AWSLambda.init(...); + +// after +import * as Sentry from '@sentry/serverless/aws'; + +Sentry.init(...); + +// before +import * as Sentry from '@sentry/serverless'; + +Sentry.GCPFunction.init(...); + +// after +import * as Sentry from '@sentry/serverless/gcp'; + +Sentry.init(...); +``` + # Deprecations in 7.x You can use the **Experimental** [@sentry/migr8](https://www.npmjs.com/package/@sentry/migr8) to automatically update @@ -210,6 +238,9 @@ The following list shows how integrations should be migrated: | `new Hapi()` | `hapiIntegration()` | `@sentry/node` | | `new Undici()` | `nativeNodeFetchIntegration()` | `@sentry/node` | | `new Http()` | `httpIntegration()` | `@sentry/node` | +| `new AWSServices()` | `awsServicesIntegration()` | `@sentry/serverless` | +| `new GoogleCloudGrpc()` | `googleCloudGrpcIntegration()` | `@sentry/serverless` | +| `new GoogleCloudHttp()` | `googleCloudHttpIntegration()` | `@sentry/serverless` | ## Deprecate `hub.bindClient()` and `makeMain()` 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 cf8233680c11..606e2dab2cae 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,7 +58,12 @@ const DEPENDENTS: Dependent[] = [ exports: Object.keys(SentryRemix), }, { - package: '@sentry/serverless', + package: '@sentry/serverless/aws', + exports: Object.keys(SentryServerless), + ignoreExports: ['cron', 'hapiErrorPlugin', 'enableAnrDetection'], + }, + { + package: '@sentry/serverless/gcp', exports: Object.keys(SentryServerless), ignoreExports: ['cron', 'hapiErrorPlugin', 'enableAnrDetection'], }, diff --git a/packages/serverless/README.md b/packages/serverless/README.md index aec2e5e27872..2ae222fdc965 100644 --- a/packages/serverless/README.md +++ b/packages/serverless/README.md @@ -13,30 +13,27 @@ ## General -This package is a wrapper around `@sentry/node`, with added functionality related to various Serverless solutions. All -methods available in `@sentry/node` can be imported from `@sentry/serverless`. - -Currently supported environment: +This package is a wrapper around `@sentry/node`, with added functionality related to various Serverless solutions. Currently AWS Lambda and Google Cloud Functions are supported. ### AWS Lambda -To use this SDK, call `Sentry.AWSLambda.init(options)` at the very beginning of your JavaScript file. +To use this SDK, import `Sentry.init` from `@sentry/serverless/aws` at the very beginning of your JavaScript file. ```javascript -import * as Sentry from '@sentry/serverless'; +import * as Sentry from '@sentry/serverless/aws'; -Sentry.AWSLambda.init({ +Sentry.init({ dsn: '__DSN__', // ... }); // async (recommended) -exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => { +exports.handler = Sentry.wrapHandler(async (event, context) => { throw new Error('oh, hello there!'); }); // sync -exports.handler = Sentry.AWSLambda.wrapHandler((event, context, callback) => { +exports.handler = Sentry.wrapHandler((event, context, callback) => { throw new Error('oh, hello there!'); }); ``` @@ -44,9 +41,9 @@ exports.handler = Sentry.AWSLambda.wrapHandler((event, context, callback) => { If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the `tracesSampleRate` option. ```javascript -import * as Sentry from '@sentry/serverless'; +import * as Sentry from '@sentry/serverless/aws'; -Sentry.AWSLambda.init({ +Sentry.init({ dsn: '__DSN__', tracesSampleRate: 1.0, }); @@ -65,12 +62,12 @@ Another and much simpler way to integrate Sentry to your AWS Lambda function is ### Google Cloud Functions -To use this SDK, call `Sentry.GCPFunction.init(options)` at the very beginning of your JavaScript file. +To use this SDK, import `Sentry.init` from `@sentry/serverless/gcp` at the very beginning of your JavaScript file. ```javascript -import * as Sentry from '@sentry/serverless'; +import * as Sentry from '@sentry/serverless/gcp'; -Sentry.GCPFunction.init({ +Sentry.init({ dsn: '__DSN__', tracesSampleRate: 1.0, // ... @@ -78,19 +75,19 @@ Sentry.GCPFunction.init({ // For HTTP Functions: -exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => { +exports.helloHttp = Sentry.wrapHttpFunction((req, res) => { throw new Error('oh, hello there!'); }); // For Background Functions: -exports.helloEvents = Sentry.GCPFunction.wrapEventFunction((data, context, callback) => { +exports.helloEvents = Sentry.wrapEventFunction((data, context, callback) => { throw new Error('oh, hello there!'); }); // For CloudEvents: -exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction((context, callback) => { +exports.helloEvents = Sentry.wrapCloudEventFunction((context, callback) => { throw new Error('oh, hello there!'); }); ``` diff --git a/packages/serverless/package.json b/packages/serverless/package.json index e94ed265dcdc..b2f808e0312c 100644 --- a/packages/serverless/package.json +++ b/packages/serverless/package.json @@ -18,10 +18,49 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "default": "./build/npm/esm/index.js", + "types": "./build/npm/types/index.d.ts" + }, + "require": { + "default": "./build/npm/cjs/index.js", + "types": "./build/npm/types/index.d.ts" + } + }, + "./aws": { + "import": { + "default": "./build/npm/esm/index.aws.js", + "types": "./build/npm/types/index.aws.d.ts" + }, + "require": { + "default": "./build/npm/cjs/index.aws.js", + "types": "./build/npm/types/index.aws.d.ts" + } + }, + "./gcp": { + "import": { + "default": "./build/npm/esm/index.gcp.js", + "types": "./build/npm/types/index.gcp.d.ts" + }, + "require": { + "default": "./build/npm/cjs/index.gcp.js", + "types": "./build/npm/types/index.gcp.d.ts" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ "build/npm/types-ts3.8/index.d.ts" + ], + "build/npm/types/index.aws.d.ts": [ + "build/npm/types-ts3.8/index.aws.d.ts" + ], + "build/npm/types/index.gcp.d.ts": [ + "build/npm/types-ts3.8/index.gcp.d.ts" ] } }, diff --git a/packages/serverless/rollup.aws.config.mjs b/packages/serverless/rollup.aws.config.mjs index 5d9883a3f9f7..d5682eec3ea8 100644 --- a/packages/serverless/rollup.aws.config.mjs +++ b/packages/serverless/rollup.aws.config.mjs @@ -6,7 +6,7 @@ export default [ makeBaseBundleConfig({ // this automatically sets it to be CJS bundleType: 'node', - entrypoints: ['src/index.awslambda.ts'], + entrypoints: ['src/index.aws.ts'], jsVersion: 'es6', licenseTitle: '@sentry/serverless', outputFileBase: () => 'index', diff --git a/packages/serverless/rollup.npm.config.mjs b/packages/serverless/rollup.npm.config.mjs index b51a3bdafdb5..1c7e5e2876b4 100644 --- a/packages/serverless/rollup.npm.config.mjs +++ b/packages/serverless/rollup.npm.config.mjs @@ -2,10 +2,7 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu export default makeNPMConfigVariants( makeBaseNPMConfig({ - // TODO: `awslambda-auto.ts` is a file which the lambda layer uses to automatically init the SDK. Does it need to be - // in the npm package? Is it possible that some people are using it themselves in the same way the layer uses it (in - // which case removing it would be a breaking change)? Should it stay here or not? - entrypoints: ['src/index.ts', 'src/awslambda-auto.ts'], + entrypoints: ['src/index.aws.ts', 'src/index.gcp.ts'], // packages with bundles have a different build directory structure hasBundles: true, }), diff --git a/packages/serverless/src/awsservices.ts b/packages/serverless/src/aws/awsservices.ts similarity index 81% rename from packages/serverless/src/awsservices.ts rename to packages/serverless/src/aws/awsservices.ts index 084fdbf0238a..f041fefb0e88 100644 --- a/packages/serverless/src/awsservices.ts +++ b/packages/serverless/src/aws/awsservices.ts @@ -1,9 +1,7 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, convertIntegrationFnToClass, defineIntegration } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration } from '@sentry/core'; import { getClient, startInactiveSpan } from '@sentry/node'; -import type { Client, Integration, IntegrationClass, IntegrationFn, Span } from '@sentry/types'; +import type { Client, IntegrationFn, Span } from '@sentry/types'; import { fill } from '@sentry/utils'; -// 'aws-sdk/global' import is expected to be type-only so it's erased in the final .js file. -// When TypeScript compiler is upgraded, use `import type` syntax to explicitly assert that we don't want to load a module here. import type * as AWS from 'aws-sdk/global'; type GenericParams = { [key: string]: any }; // eslint-disable-line @typescript-eslint/no-explicit-any @@ -41,21 +39,10 @@ const _awsServicesIntegration = ((options: { optional?: boolean } = {}) => { }; }) satisfies IntegrationFn; -export const awsServicesIntegration = defineIntegration(_awsServicesIntegration); - /** * AWS Service Request Tracking. - * - * @deprecated Use `awsServicesIntegration()` instead. */ -// eslint-disable-next-line deprecation/deprecation -export const AWSServices = convertIntegrationFnToClass( - INTEGRATION_NAME, - awsServicesIntegration, -) as IntegrationClass; - -// eslint-disable-next-line deprecation/deprecation -export type AWSServices = typeof AWSServices; +export const awsServicesIntegration = defineIntegration(_awsServicesIntegration); /** * Patches AWS SDK request to create `http.client` spans. diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/aws/sdk.ts similarity index 96% rename from packages/serverless/src/awslambda.ts rename to packages/serverless/src/aws/sdk.ts index 240dff84eebc..11bbe61fe417 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/aws/sdk.ts @@ -8,7 +8,6 @@ import { captureException, captureMessage, continueTrace, - defaultIntegrations as nodeDefaultIntegrations, flush, getCurrentScope, getDefaultIntegrations as getNodeDefaultIntegrations, @@ -24,10 +23,8 @@ import { performance } from 'perf_hooks'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { awsServicesIntegration } from './awsservices'; -import { DEBUG_BUILD } from './debug-build'; -import { markEventUnhandled } from './utils'; - -export * from '@sentry/node'; +import { DEBUG_BUILD } from '../debug-build'; +import { markEventUnhandled } from '../utils'; const { isPromise } = types; @@ -38,7 +35,7 @@ type SyncHandler = ( callback: Parameters[2], ) => void; -export type AsyncHandler = ( +type AsyncHandler = ( event: Parameters[0], context: Parameters[1], ) => Promise[2]>[1]>>; @@ -66,13 +63,6 @@ export interface WrapperOptions { startTrace: boolean; } -/** @deprecated Use `getDefaultIntegrations(options)` instead. */ -export const defaultIntegrations: Integration[] = [ - // eslint-disable-next-line deprecation/deprecation - ...nodeDefaultIntegrations, - awsServicesIntegration({ optional: true }), -]; - /** Get the default integrations for the AWSLambda SDK. */ export function getDefaultIntegrations(options: Options): Integration[] { return [...getNodeDefaultIntegrations(options), awsServicesIntegration({ optional: true })]; diff --git a/packages/serverless/src/awslambda-auto.ts b/packages/serverless/src/awslambda-auto.ts index ac048cde5aed..a343b6832238 100644 --- a/packages/serverless/src/awslambda-auto.ts +++ b/packages/serverless/src/awslambda-auto.ts @@ -1,4 +1,4 @@ -import * as Sentry from './index'; +import { init, tryPatchHandler } from './aws/sdk'; const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT; if (lambdaTaskRoot) { @@ -7,11 +7,11 @@ if (lambdaTaskRoot) { throw Error(`LAMBDA_TASK_ROOT is non-empty(${lambdaTaskRoot}) but _HANDLER is not set`); } - Sentry.AWSLambda.init({ + init({ _invokedByLambdaLayer: true, }); - Sentry.AWSLambda.tryPatchHandler(lambdaTaskRoot, handlerString); + tryPatchHandler(lambdaTaskRoot, handlerString); } else { throw Error('LAMBDA_TASK_ROOT environment variable is not set'); } diff --git a/packages/serverless/src/gcpfunction/cloud_events.ts b/packages/serverless/src/gcp/cloud_events.ts similarity index 100% rename from packages/serverless/src/gcpfunction/cloud_events.ts rename to packages/serverless/src/gcp/cloud_events.ts diff --git a/packages/serverless/src/gcpfunction/events.ts b/packages/serverless/src/gcp/events.ts similarity index 100% rename from packages/serverless/src/gcpfunction/events.ts rename to packages/serverless/src/gcp/events.ts diff --git a/packages/serverless/src/gcpfunction/general.ts b/packages/serverless/src/gcp/general.ts similarity index 100% rename from packages/serverless/src/gcpfunction/general.ts rename to packages/serverless/src/gcp/general.ts diff --git a/packages/serverless/src/google-cloud-grpc.ts b/packages/serverless/src/gcp/google-cloud-grpc.ts similarity index 86% rename from packages/serverless/src/google-cloud-grpc.ts rename to packages/serverless/src/gcp/google-cloud-grpc.ts index a32ac9dae9ac..0b1aa11a0a9d 100644 --- a/packages/serverless/src/google-cloud-grpc.ts +++ b/packages/serverless/src/gcp/google-cloud-grpc.ts @@ -1,12 +1,7 @@ import type { EventEmitter } from 'events'; -import { - SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - convertIntegrationFnToClass, - defineIntegration, - getClient, -} from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, getClient } from '@sentry/core'; import { startInactiveSpan } from '@sentry/node'; -import type { Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types'; +import type { Client, IntegrationFn } from '@sentry/types'; import { fill } from '@sentry/utils'; interface GrpcFunction extends CallableFunction { @@ -62,21 +57,10 @@ const _googleCloudGrpcIntegration = ((options: { optional?: boolean } = {}) => { }; }) satisfies IntegrationFn; -export const googleCloudGrpcIntegration = defineIntegration(_googleCloudGrpcIntegration); - /** * Google Cloud Platform service requests tracking for GRPC APIs. - * - * @deprecated Use `googleCloudGrpcIntegration()` instead. */ -// eslint-disable-next-line deprecation/deprecation -export const GoogleCloudGrpc = convertIntegrationFnToClass( - INTEGRATION_NAME, - googleCloudGrpcIntegration, -) as IntegrationClass; - -// eslint-disable-next-line deprecation/deprecation -export type GoogleCloudGrpc = typeof GoogleCloudGrpc; +export const googleCloudGrpcIntegration = defineIntegration(_googleCloudGrpcIntegration); /** Returns a wrapped function that returns a stub with tracing enabled */ function wrapCreateStub(origCreate: CreateStubFunc): CreateStubFunc { diff --git a/packages/serverless/src/google-cloud-http.ts b/packages/serverless/src/gcp/google-cloud-http.ts similarity index 80% rename from packages/serverless/src/google-cloud-http.ts rename to packages/serverless/src/gcp/google-cloud-http.ts index 5e7558f4299d..1f331585079c 100644 --- a/packages/serverless/src/google-cloud-http.ts +++ b/packages/serverless/src/gcp/google-cloud-http.ts @@ -1,12 +1,7 @@ import type * as common from '@google-cloud/common'; -import { - SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - convertIntegrationFnToClass, - defineIntegration, - getClient, -} from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, getClient } from '@sentry/core'; import { startInactiveSpan } from '@sentry/node'; -import type { Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types'; +import type { Client, IntegrationFn } from '@sentry/types'; import { fill } from '@sentry/utils'; type RequestOptions = common.DecorateRequestOptions; @@ -41,21 +36,10 @@ const _googleCloudHttpIntegration = ((options: { optional?: boolean } = {}) => { }; }) satisfies IntegrationFn; -export const googleCloudHttpIntegration = defineIntegration(_googleCloudHttpIntegration); - /** * Google Cloud Platform service requests tracking for RESTful APIs. - * - * @deprecated Use `googleCloudHttpIntegration()` instead. */ -// eslint-disable-next-line deprecation/deprecation -export const GoogleCloudHttp = convertIntegrationFnToClass( - INTEGRATION_NAME, - googleCloudHttpIntegration, -) as IntegrationClass; - -// eslint-disable-next-line deprecation/deprecation -export type GoogleCloudHttp = typeof GoogleCloudHttp; +export const googleCloudHttpIntegration = defineIntegration(_googleCloudHttpIntegration); /** Returns a wrapped function that makes a request with tracing enabled */ function wrapRequestFunction(orig: RequestFunction): RequestFunction { diff --git a/packages/serverless/src/gcpfunction/http.ts b/packages/serverless/src/gcp/http.ts similarity index 98% rename from packages/serverless/src/gcpfunction/http.ts rename to packages/serverless/src/gcp/http.ts index e02093acf438..785f2d71156c 100644 --- a/packages/serverless/src/gcpfunction/http.ts +++ b/packages/serverless/src/gcp/http.ts @@ -12,7 +12,7 @@ import { captureException, flush } from '@sentry/node'; import { isString, logger, stripUrlQueryAndFragment } from '@sentry/utils'; import { DEBUG_BUILD } from '../debug-build'; -import { domainify, markEventUnhandled, proxyFunction } from './../utils'; +import { domainify, markEventUnhandled, proxyFunction } from '../utils'; import type { HttpFunction, WrapperOptions } from './general'; // TODO (v8 / #5257): Remove this whole old/new business and just use the new stuff diff --git a/packages/serverless/src/gcpfunction/index.ts b/packages/serverless/src/gcp/sdk.ts similarity index 55% rename from packages/serverless/src/gcpfunction/index.ts rename to packages/serverless/src/gcp/sdk.ts index 50556634c5fc..3077729e82e7 100644 --- a/packages/serverless/src/gcpfunction/index.ts +++ b/packages/serverless/src/gcp/sdk.ts @@ -1,26 +1,9 @@ import type { NodeOptions } from '@sentry/node'; -import { - SDK_VERSION, - defaultIntegrations as defaultNodeIntegrations, - getDefaultIntegrations as getDefaultNodeIntegrations, - init as initNode, -} from '@sentry/node'; +import { SDK_VERSION, getDefaultIntegrations as getDefaultNodeIntegrations, init as initNode } from '@sentry/node'; import type { Integration, Options, SdkMetadata } from '@sentry/types'; -import { googleCloudGrpcIntegration } from '../google-cloud-grpc'; -import { googleCloudHttpIntegration } from '../google-cloud-http'; - -export * from './http'; -export * from './events'; -export * from './cloud_events'; - -/** @deprecated Use `getDefaultIntegrations(options)` instead. */ -export const defaultIntegrations: Integration[] = [ - // eslint-disable-next-line deprecation/deprecation - ...defaultNodeIntegrations, - googleCloudHttpIntegration({ optional: true }), // We mark this integration optional since '@google-cloud/common' module could be missing. - googleCloudGrpcIntegration({ optional: true }), // We mark this integration optional since 'google-gax' module could be missing. -]; +import { googleCloudGrpcIntegration } from './google-cloud-grpc'; +import { googleCloudHttpIntegration } from './google-cloud-http'; /** Get the default integrations for the GCP SDK. */ export function getDefaultIntegrations(options: Options): Integration[] { diff --git a/packages/serverless/src/index.aws.ts b/packages/serverless/src/index.aws.ts new file mode 100644 index 000000000000..6b1606dd5ade --- /dev/null +++ b/packages/serverless/src/index.aws.ts @@ -0,0 +1,74 @@ +export { init, tryPatchHandler, wrapHandler, getDefaultIntegrations } from './aws/sdk'; +export { awsServicesIntegration } from './aws/awsservices'; + +export type { WrapperOptions } from './aws/sdk'; + +// These exports should not export `init` or `getDefaultIntegrations`. +export { + Hub, + SDK_VERSION, + Scope, + addBreadcrumb, + addEventProcessor, + addIntegration, + autoDiscoverNodePerformanceMonitoringIntegrations, + captureEvent, + captureException, + captureMessage, + captureCheckIn, + withMonitor, + createTransport, + getClient, + isInitialized, + getCurrentScope, + getGlobalScope, + getIsolationScope, + getHubFromCarrier, + getSpanStatusFromHttpCode, + setHttpStatus, + setCurrentClient, + setContext, + setExtra, + setExtras, + setTag, + setTags, + setUser, + withScope, + withIsolationScope, + NodeClient, + makeNodeTransport, + close, + defaultStackParser, + flush, + getSentryRelease, + DEFAULT_USER_INCLUDES, + addRequestDataToEvent, + extractRequestData, + Handlers, + setMeasurement, + getActiveSpan, + startSpan, + startInactiveSpan, + startSpanManual, + continueTrace, + parameterize, + requestDataIntegration, + linkedErrorsIntegration, + inboundFiltersIntegration, + functionToStringIntegration, + createGetModuleFromFilename, + metrics, + runWithAsyncContext, + consoleIntegration, + onUncaughtExceptionIntegration, + onUnhandledRejectionIntegration, + modulesIntegration, + contextLinesIntegration, + nodeContextIntegration, + localVariablesIntegration, + anrIntegration, + hapiIntegration, + httpIntegration, + nativeNodeFetchintegration, + spotlightIntegration, +} from '@sentry/node'; diff --git a/packages/serverless/src/index.awslambda.ts b/packages/serverless/src/index.awslambda.ts deleted file mode 100644 index c097591ab9dc..000000000000 --- a/packages/serverless/src/index.awslambda.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** This file is used as the entrypoint for the lambda layer bundle, and is not included in the npm package. */ - -// https://medium.com/unsplash/named-namespace-imports-7345212bbffb -import * as AWSLambda from './awslambda'; -export { AWSLambda }; - -export * from './awsservices'; -export * from '@sentry/node'; diff --git a/packages/serverless/src/index.gcp.ts b/packages/serverless/src/index.gcp.ts new file mode 100644 index 000000000000..29ac5d82e1ad --- /dev/null +++ b/packages/serverless/src/index.gcp.ts @@ -0,0 +1,83 @@ +export { init, getDefaultIntegrations } from './gcp/sdk'; + +export { wrapHttpFunction } from './gcp/http'; +export type { HttpFunctionWrapperOptions } from './gcp/http'; + +export { wrapCloudEventFunction } from './gcp/cloud_events'; +export type { CloudEventFunctionWrapperOptions } from './gcp/cloud_events'; + +export { wrapEventFunction } from './gcp/events'; +export type { EventFunctionWrapperOptions } from './gcp/events'; + +export { googleCloudGrpcIntegration } from './gcp/google-cloud-grpc'; +export { googleCloudHttpIntegration } from './gcp/google-cloud-http'; + +// These exports should not export `init` or `getDefaultIntegrations`. +export { + Hub, + SDK_VERSION, + Scope, + addBreadcrumb, + addEventProcessor, + addIntegration, + autoDiscoverNodePerformanceMonitoringIntegrations, + captureEvent, + captureException, + captureMessage, + captureCheckIn, + withMonitor, + createTransport, + getClient, + isInitialized, + getCurrentScope, + getGlobalScope, + getIsolationScope, + getHubFromCarrier, + getSpanStatusFromHttpCode, + setHttpStatus, + setCurrentClient, + setContext, + setExtra, + setExtras, + setTag, + setTags, + setUser, + withScope, + withIsolationScope, + NodeClient, + makeNodeTransport, + close, + defaultStackParser, + flush, + getSentryRelease, + DEFAULT_USER_INCLUDES, + addRequestDataToEvent, + extractRequestData, + Handlers, + setMeasurement, + getActiveSpan, + startSpan, + startInactiveSpan, + startSpanManual, + continueTrace, + parameterize, + requestDataIntegration, + linkedErrorsIntegration, + inboundFiltersIntegration, + functionToStringIntegration, + createGetModuleFromFilename, + metrics, + runWithAsyncContext, + consoleIntegration, + onUncaughtExceptionIntegration, + onUnhandledRejectionIntegration, + modulesIntegration, + contextLinesIntegration, + nodeContextIntegration, + localVariablesIntegration, + anrIntegration, + hapiIntegration, + httpIntegration, + nativeNodeFetchintegration, + spotlightIntegration, +} from '@sentry/node'; diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts deleted file mode 100644 index 24ee21115f0b..000000000000 --- a/packages/serverless/src/index.ts +++ /dev/null @@ -1,110 +0,0 @@ -// https://medium.com/unsplash/named-namespace-imports-7345212bbffb -import * as AWSLambda from './awslambda'; -import * as GCPFunction from './gcpfunction'; -export { AWSLambda, GCPFunction }; - -// eslint-disable-next-line deprecation/deprecation -export { AWSServices, awsServicesIntegration } from './awsservices'; - -// TODO(v8): We have to explicitly export these because of the namespace exports -// above. This is because just doing `export * from '@sentry/node'` will not -// work with Node native esm while we also have namespace exports in a package. -// What we should do is get rid of the namespace exports. -export { - Hub, - SDK_VERSION, - Scope, - addBreadcrumb, - // eslint-disable-next-line deprecation/deprecation - addGlobalEventProcessor, - addEventProcessor, - addIntegration, - autoDiscoverNodePerformanceMonitoringIntegrations, - captureEvent, - captureException, - captureMessage, - captureCheckIn, - withMonitor, - // eslint-disable-next-line deprecation/deprecation - configureScope, - createTransport, - // eslint-disable-next-line deprecation/deprecation - getActiveTransaction, - // eslint-disable-next-line deprecation/deprecation - getCurrentHub, - getClient, - isInitialized, - getCurrentScope, - getGlobalScope, - getIsolationScope, - getHubFromCarrier, - // eslint-disable-next-line deprecation/deprecation - spanStatusfromHttpCode, - getSpanStatusFromHttpCode, - setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - makeMain, - setCurrentClient, - setContext, - setExtra, - setExtras, - setTag, - setTags, - setUser, - // eslint-disable-next-line deprecation/deprecation - startTransaction, - withScope, - withIsolationScope, - NodeClient, - makeNodeTransport, - close, - // eslint-disable-next-line deprecation/deprecation - defaultIntegrations, - getDefaultIntegrations, - defaultStackParser, - flush, - getSentryRelease, - init, - // eslint-disable-next-line deprecation/deprecation - lastEventId, - DEFAULT_USER_INCLUDES, - addRequestDataToEvent, - extractRequestData, - // eslint-disable-next-line deprecation/deprecation - deepReadDirSync, - Handlers, - // eslint-disable-next-line deprecation/deprecation - Integrations, - setMeasurement, - getActiveSpan, - startSpan, - // eslint-disable-next-line deprecation/deprecation - startActiveSpan, - startInactiveSpan, - startSpanManual, - continueTrace, - parameterize, - requestDataIntegration, - linkedErrorsIntegration, - inboundFiltersIntegration, - functionToStringIntegration, - // eslint-disable-next-line deprecation/deprecation - getModuleFromFilename, - createGetModuleFromFilename, - metrics, - // eslint-disable-next-line deprecation/deprecation - extractTraceparentData, - runWithAsyncContext, - consoleIntegration, - onUncaughtExceptionIntegration, - onUnhandledRejectionIntegration, - modulesIntegration, - contextLinesIntegration, - nodeContextIntegration, - localVariablesIntegration, - anrIntegration, - hapiIntegration, - httpIntegration, - nativeNodeFetchintegration, - spotlightIntegration, -} from '@sentry/node'; diff --git a/packages/serverless/test/awslambda.test.ts b/packages/serverless/test/awslambda.test.ts index 772502057a34..ed94a0a945e7 100644 --- a/packages/serverless/test/awslambda.test.ts +++ b/packages/serverless/test/awslambda.test.ts @@ -3,7 +3,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } fr import type { Event } from '@sentry/types'; import type { Callback, Handler } from 'aws-lambda'; -import { init, wrapHandler } from '../src/awslambda'; +import { init, wrapHandler } from '../src/index.aws'; const mockSpanEnd = jest.fn(); const mockStartInactiveSpan = jest.fn((...spanArgs) => ({ ...spanArgs })); diff --git a/packages/serverless/test/awsservices.test.ts b/packages/serverless/test/awsservices.test.ts index 3170f9056ec0..5398f227a634 100644 --- a/packages/serverless/test/awsservices.test.ts +++ b/packages/serverless/test/awsservices.test.ts @@ -3,7 +3,7 @@ import * as AWS from 'aws-sdk'; import * as nock from 'nock'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; -import { awsServicesIntegration } from '../src/awsservices'; +import { awsServicesIntegration } from '../src/index.aws'; const mockSpanEnd = jest.fn(); const mockStartInactiveSpan = jest.fn(spanArgs => ({ ...spanArgs })); diff --git a/packages/serverless/test/gcpfunction.test.ts b/packages/serverless/test/gcpfunction.test.ts index cde69e6b22d2..1bb15c2b7a65 100644 --- a/packages/serverless/test/gcpfunction.test.ts +++ b/packages/serverless/test/gcpfunction.test.ts @@ -4,7 +4,6 @@ import type { Event, Integration } from '@sentry/types'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; -import { wrapCloudEventFunction, wrapEventFunction, wrapHttpFunction } from '../src/gcpfunction'; import type { CloudEventFunction, CloudEventFunctionWithCallback, @@ -13,9 +12,10 @@ import type { HttpFunction, Request, Response, -} from '../src/gcpfunction/general'; +} from '../src/gcp/general'; +import { wrapCloudEventFunction, wrapEventFunction, wrapHttpFunction } from '../src/index.gcp'; -import { init } from '../src/gcpfunction'; +import { init } from '../src/gcp/sdk'; const mockStartInactiveSpan = jest.fn((...spanArgs) => ({ ...spanArgs })); const mockStartSpanManual = jest.fn((...spanArgs) => ({ ...spanArgs })); diff --git a/packages/serverless/test/google-cloud-grpc.test.ts b/packages/serverless/test/google-cloud-grpc.test.ts index 0ce19ee7db8b..8c88e7dd7e2e 100644 --- a/packages/serverless/test/google-cloud-grpc.test.ts +++ b/packages/serverless/test/google-cloud-grpc.test.ts @@ -10,7 +10,7 @@ import * as nock from 'nock'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; import { NodeClient, createTransport, setCurrentClient } from '@sentry/node'; -import { googleCloudGrpcIntegration } from '../src/google-cloud-grpc'; +import { googleCloudGrpcIntegration } from '../src/index.gcp'; const spyConnect = jest.spyOn(http2, 'connect'); diff --git a/packages/serverless/test/google-cloud-http.test.ts b/packages/serverless/test/google-cloud-http.test.ts index 3389130565f9..6c51a35cb34c 100644 --- a/packages/serverless/test/google-cloud-http.test.ts +++ b/packages/serverless/test/google-cloud-http.test.ts @@ -5,7 +5,7 @@ import * as nock from 'nock'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; import { NodeClient, createTransport, setCurrentClient } from '@sentry/node'; -import { googleCloudHttpIntegration } from '../src/google-cloud-http'; +import { googleCloudHttpIntegration } from '../src/index.gcp'; const mockSpanEnd = jest.fn(); const mockStartInactiveSpan = jest.fn(spanArgs => ({ ...spanArgs }));