-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathawslambda.ts
More file actions
51 lines (47 loc) · 1.65 KB
/
awslambda.ts
File metadata and controls
51 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import { captureException, generateInstrumentOnce } from '@sentry/node';
import { eventContextExtractor, markEventUnhandled } from '../utils';
import { AwsLambdaInstrumentation } from './instrumentation-aws-lambda/instrumentation';
interface AwsLambdaOptions {
/**
* Disables the AWS context propagation and instead uses
* Sentry's context. Defaults to `true`, in order for
* Sentry trace propagation to take precedence, but can
* be disabled if you want AWS propagation to take take
* precedence.
*/
disableAwsContextPropagation?: boolean;
}
export const instrumentAwsLambda = generateInstrumentOnce(
'AwsLambda',
AwsLambdaInstrumentation,
(options: AwsLambdaOptions) => {
return {
disableAwsContextPropagation: true,
...options,
eventContextExtractor,
requestHook(span) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.otel.aws_lambda');
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'function.aws.lambda');
},
responseHook(_span, { err }) {
if (err) {
captureException(err, scope => markEventUnhandled(scope, 'auto.function.aws_serverless.otel'));
}
},
};
},
);
const _awsLambdaIntegration = ((options: AwsLambdaOptions = {}) => {
return {
name: 'AwsLambda',
setupOnce() {
instrumentAwsLambda(options);
},
};
}) satisfies IntegrationFn;
/**
* Instrumentation for aws-sdk package
*/
export const awsLambdaIntegration = defineIntegration(_awsLambdaIntegration);