UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

65 lines (61 loc) • 2.63 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const attributes = require('@sentry/conventions/attributes'); const core = require('@sentry/core'); const INTEGRATION_NAME = "AwsLambdaWeb"; let requestHandled = false; const _awsLambdaWebIntegration = (() => { if (!process.env.AWS_LAMBDA_HTTP_ENDPOINT) { return { name: INTEGRATION_NAME }; } const memory = Number(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE) * 1024 * 1024; const lambdaContext = { memory_size: Number.isFinite(memory) && memory > 0 ? memory : void 0, initialization_type: process.env.AWS_LAMBDA_INITIALIZATION_TYPE }; const environmentAttributes = { [attributes.FAAS_MAX_MEMORY]: lambdaContext.memory_size, [attributes.AWS_LAMBDA_INITIALIZATION_TYPE]: lambdaContext.initialization_type }; return { name: INTEGRATION_NAME, setup(client) { client.on("httpServerRequest", (_request, _response, request) => { const coldStart = !requestHandled; requestHandled = true; const requestId = request.headers?.["lambda-web-request-id"]; const endpointName = request.headers?.["lambda-web-endpoint-name"]; const scope = core.getIsolationScope(); scope.setContext("aws.lambda", { ...scope.getScopeData().contexts["aws.lambda"], cold_start: coldStart, aws_request_id: typeof requestId === "string" ? requestId : void 0, endpoint_name: typeof endpointName === "string" ? endpointName : void 0 }); }); }, processEvent(event) { event.contexts = { ...event.contexts, "aws.lambda": { ...lambdaContext, ...event.contexts?.["aws.lambda"] } }; return event; }, processSegmentSpan(span) { const requestContext = core.getIsolationScope().getScopeData().contexts["aws.lambda"]; const attributes$1 = { ...environmentAttributes }; if (typeof requestContext?.cold_start === "boolean") { attributes$1[attributes.FAAS_COLDSTART] = requestContext.cold_start; } if (typeof requestContext?.aws_request_id === "string") { attributes$1[attributes.FAAS_INVOCATION_ID] = requestContext.aws_request_id; } if (typeof requestContext?.endpoint_name === "string") { attributes$1[attributes.AWS_LAMBDA_WEB_ENDPOINT_NAME] = requestContext.endpoint_name; } core.safeSetSpanJSONAttributes(span, attributes$1); } }; }); const awsLambdaWebIntegration = core.defineIntegration(_awsLambdaWebIntegration); exports.awsLambdaWebIntegration = awsLambdaWebIntegration; //# sourceMappingURL=awsLambdaWeb.js.map