Skip to content

feat(v8/serverless): Remove deprecated exports #10540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ 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.

Using the `Sentry.AWSLambda` export has also changed. It no longer re-exports all of methods of the Node SDK, you'll have to import them directly from `@sentry/serverless`, instead it only exports `init`, `wrapHandler` and `tryPatchHandler`.

```js
import * as Sentry from '@sentry/serverless';

// before
Sentry.AWSLambda.captureException(...);

// after
Sentry.captureException(...);
```

# Deprecations in 7.x

You can use the **Experimental** [@sentry/migr8](https://www.npmjs.com/package/@sentry/migr8) to automatically update
Expand Down Expand Up @@ -210,6 +226,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()`

Expand Down
6 changes: 3 additions & 3 deletions packages/serverless/src/awslambda-auto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Sentry from './index';
import { init, tryPatchHandler } from './awslambda';

const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT;
if (lambdaTaskRoot) {
Expand All @@ -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');
}
12 changes: 1 addition & 11 deletions packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
captureException,
captureMessage,
continueTrace,
defaultIntegrations as nodeDefaultIntegrations,
flush,
getCurrentScope,
getDefaultIntegrations as getNodeDefaultIntegrations,
Expand All @@ -27,8 +26,6 @@ import { awsServicesIntegration } from './awsservices';
import { DEBUG_BUILD } from './debug-build';
import { markEventUnhandled } from './utils';

export * from '@sentry/node';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include this in the migration docs somehow? 🤔


const { isPromise } = types;

// https://www.npmjs.com/package/aws-lambda-consumer
Expand All @@ -38,7 +35,7 @@ type SyncHandler<T extends Handler> = (
callback: Parameters<T>[2],
) => void;

export type AsyncHandler<T extends Handler> = (
type AsyncHandler<T extends Handler> = (
event: Parameters<T>[0],
context: Parameters<T>[1],
) => Promise<NonNullable<Parameters<Parameters<T>[2]>[1]>>;
Expand Down Expand Up @@ -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 })];
Expand Down
17 changes: 3 additions & 14 deletions packages/serverless/src/awsservices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.
Expand Down Expand Up @@ -41,21 +41,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<Integration>;

// 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.
Expand Down
15 changes: 1 addition & 14 deletions packages/serverless/src/gcpfunction/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
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';
Expand All @@ -14,14 +9,6 @@ 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.
];

/** Get the default integrations for the GCP SDK. */
export function getDefaultIntegrations(options: Options): Integration[] {
return [
Expand Down
22 changes: 3 additions & 19 deletions packages/serverless/src/google-cloud-grpc.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<Integration>;

// 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 {
Expand Down
22 changes: 3 additions & 19 deletions packages/serverless/src/google-cloud-http.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Integration>;

// eslint-disable-next-line deprecation/deprecation
export type GoogleCloudHttp = typeof GoogleCloudHttp;
export const googleCloudHttpIntegration = defineIntegration(_googleCloudHttpIntegration);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: I guess we could inline the integration here now? Same for the others.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason to keep this separated (initially) is that I though we may want to export the "unwrapped" version for tests, where we could then use the type safe form - but this is a nice to have, no strong feelings on this!


/** Returns a wrapped function that makes a request with tracing enabled */
function wrapRequestFunction(orig: RequestFunction): RequestFunction {
Expand Down
10 changes: 7 additions & 3 deletions packages/serverless/src/index.awslambda.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/** 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 };
import { init as awsLambdaInit, tryPatchHandler, wrapHandler } from './awslambda';

export const AWSLambda = {
init: awsLambdaInit,
wrapHandler,
tryPatchHandler,
};

export * from './awsservices';
export * from '@sentry/node';
49 changes: 15 additions & 34 deletions packages/serverless/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// https://medium.com/unsplash/named-namespace-imports-7345212bbffb
import * as AWSLambda from './awslambda';
import * as GCPFunction from './gcpfunction';
export { AWSLambda, GCPFunction };
export { awsServicesIntegration } from './awsservices';
import { init as awsLambdaInit, tryPatchHandler, wrapHandler } from './awslambda';
import { init as gcpFunctionInit } from './gcpfunction';

// eslint-disable-next-line deprecation/deprecation
export { AWSServices, awsServicesIntegration } from './awsservices';
export const AWSLambda = {
init: awsLambdaInit,
wrapHandler,
tryPatchHandler,
};

export const GCPFunction = {
init: gcpFunctionInit,
};

import type { WrapperOptions as AWSWrapperOptions } from './awslambda';
export type { AWSWrapperOptions };

// 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
Expand All @@ -15,8 +24,6 @@ export {
SDK_VERSION,
Scope,
addBreadcrumb,
// eslint-disable-next-line deprecation/deprecation
addGlobalEventProcessor,
addEventProcessor,
addIntegration,
autoDiscoverNodePerformanceMonitoringIntegrations,
Expand All @@ -25,61 +32,39 @@ export {
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,
Expand All @@ -88,12 +73,8 @@ export {
linkedErrorsIntegration,
inboundFiltersIntegration,
functionToStringIntegration,
// eslint-disable-next-line deprecation/deprecation
getModuleFromFilename,
createGetModuleFromFilename,
metrics,
// eslint-disable-next-line deprecation/deprecation
extractTraceparentData,
runWithAsyncContext,
consoleIntegration,
onUncaughtExceptionIntegration,
Expand Down