Skip to content

Commit 298b073

Browse files
committed
feat(aws): Add OTEL based integrations
1 parent c8bc80b commit 298b073

File tree

12 files changed

+153
-259
lines changed

12 files changed

+153
-259
lines changed

MIGRATION.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,10 @@ The `Transaction` integration has been removed from `@sentry/integrations`. Ther
176176
#### @sentry/serverless
177177

178178
`@sentry/serverless` has been removed and will no longer be published. The serverless package has been split into two
179-
different packages, `@sentry/aws-serverless` and `@sentry/google-cloud-serverless`. These new packages have smaller
180-
bundle size than `@sentry/serverless`, which should improve your serverless cold-start times.
179+
different packages, `@sentry/aws-serverless` and `@sentry/google-cloud-serverless`.
181180

182-
`@sentry/aws-serverless` and `@sentry/google-cloud-serverless` has also been changed to only emit CJS builds. The ESM
183-
build for the `@sentry/serverless` package was always broken and we decided to remove it entirely. ESM support will be
184-
re-added at a later date.
181+
The `@sentry/google-cloud-serverless` package has also been changed to only emit CJS builds because it can only
182+
instrument CJS. ESM support will be re-added at a later date.
185183

186184
In `@sentry/serverless` you had to use a namespace import to initialize the SDK. This has been removed so that you can
187185
directly import from the SDK instead.

packages/aws-serverless/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"exports": {
2121
"./package.json": "./package.json",
2222
".": {
23+
"import": {
24+
"types": "./build/npm/types/index.d.ts",
25+
"default": "./build/npm/esm/index.js"
26+
},
2327
"require": {
2428
"types": "./build/npm/types/index.d.ts",
2529
"default": "./build/npm/cjs/index.js"
@@ -47,6 +51,9 @@
4751
"access": "public"
4852
},
4953
"dependencies": {
54+
"@opentelemetry/instrumentation": "0.48.0",
55+
"@opentelemetry/instrumentation-aws-lambda": "0.40.0",
56+
"@opentelemetry/instrumentation-aws-sdk": "0.40.0",
5057
"@sentry/core": "8.0.0-alpha.9",
5158
"@sentry/node": "8.0.0-alpha.9",
5259
"@sentry/types": "8.0.0-alpha.9",

packages/aws-serverless/rollup.npm.config.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default [
1010
// packages with bundles have a different build directory structure
1111
hasBundles: true,
1212
}),
13-
{ emitEsm: false },
1413
),
1514
...makeOtelLoaders('./build', 'sentry-node'),
1615
];

packages/aws-serverless/src/awslambda-auto.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { init, tryPatchHandler } from './awslambda';
1+
import { init, tryPatchHandler } from './sdk';
22

33
const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT;
44
if (lambdaTaskRoot) {

packages/aws-serverless/src/awsservices.ts

-115
This file was deleted.

packages/aws-serverless/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export {
106106
sessionTimingIntegration,
107107
} from '@sentry/core';
108108

109-
export { getDefaultIntegrations, init, tryPatchHandler, wrapHandler } from './awslambda';
110-
export type { WrapperOptions } from './awslambda';
109+
export { awsIntegration } from './integration/aws';
110+
export { awsLambdaIntegration } from './integration/awslambda';
111111

112-
export { awsServicesIntegration } from './awsservices';
112+
export { getDefaultIntegrations, init, tryPatchHandler, wrapHandler } from './sdk';
113+
export type { WrapperOptions } from './sdk';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
2+
import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration } from '@sentry/core';
4+
import type { IntegrationFn } from '@sentry/types';
5+
6+
const _awsIntegration = (() => {
7+
return {
8+
name: 'Aws',
9+
setupOnce() {
10+
registerInstrumentations({
11+
instrumentations: [
12+
new AwsInstrumentation({
13+
preRequestHook(span) {
14+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.otel.aws');
15+
},
16+
}),
17+
],
18+
});
19+
},
20+
};
21+
}) satisfies IntegrationFn;
22+
23+
/**
24+
* Instrumentation for aws-sdk package
25+
*/
26+
export const awsIntegration = defineIntegration(_awsIntegration);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
2+
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration } from '@sentry/core';
4+
import type { IntegrationFn } from '@sentry/types';
5+
6+
const _awsLambdaIntegration = (() => {
7+
return {
8+
name: 'AwsLambda',
9+
setupOnce() {
10+
registerInstrumentations({
11+
instrumentations: [
12+
new AwsLambdaInstrumentation({
13+
requestHook(span) {
14+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.otel.aws-lambda');
15+
},
16+
}),
17+
],
18+
});
19+
},
20+
};
21+
}) satisfies IntegrationFn;
22+
23+
/**
24+
* Instrumentation for aws-sdk package
25+
*/
26+
export const awsLambdaIntegration = defineIntegration(_awsLambdaIntegration);

packages/aws-serverless/src/awslambda.ts renamed to packages/aws-serverless/src/sdk.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import type { Context, Handler } from 'aws-lambda';
2121
import { performance } from 'perf_hooks';
2222

2323
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
24-
import { awsServicesIntegration } from './awsservices';
2524

2625
import { DEBUG_BUILD } from './debug-build';
26+
import { awsIntegration } from './integration/aws';
27+
import { awsLambdaIntegration } from './integration/awslambda';
2728
import { markEventUnhandled } from './utils';
2829

2930
const { isPromise } = types;
@@ -61,7 +62,7 @@ export interface WrapperOptions {
6162

6263
/** Get the default integrations for the AWSLambda SDK. */
6364
export function getDefaultIntegrations(options: Options): Integration[] {
64-
return [...getNodeDefaultIntegrations(options), awsServicesIntegration({ optional: true })];
65+
return [...getNodeDefaultIntegrations(options), awsIntegration(), awsLambdaIntegration()];
6566
}
6667

6768
/**

packages/aws-serverless/test/awsservices.test.ts

-131
This file was deleted.

packages/aws-serverless/test/awslambda.test.ts renamed to packages/aws-serverless/test/sdk.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } fr
33
import type { Event } from '@sentry/types';
44
import type { Callback, Handler } from 'aws-lambda';
55

6-
import { init, wrapHandler } from '../src/awslambda';
6+
import { init, wrapHandler } from '../src/sdk';
77

88
const mockSpanEnd = jest.fn();
99
const mockStartInactiveSpan = jest.fn((...spanArgs) => ({ ...spanArgs }));

0 commit comments

Comments
 (0)