-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathawslambda.ts
46 lines (42 loc) · 1.43 KB
/
awslambda.ts
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
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration } from '@sentry/core';
import type { IntegrationFn } from '@sentry/core';
import { generateInstrumentOnce } from '@sentry/node';
import { eventContextExtractor } from '../utils';
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');
},
};
},
);
const _awsLambdaIntegration = ((options: AwsLambdaOptions = {}) => {
return {
name: 'AwsLambda',
setupOnce() {
instrumentAwsLambda(options);
},
};
}) satisfies IntegrationFn;
/**
* Instrumentation for aws-sdk package
*/
export const awsLambdaIntegration = defineIntegration(_awsLambdaIntegration);