From 0a3b96db27c93c0ff0cd882a0851c46715480145 Mon Sep 17 00:00:00 2001 From: Fernando Daciuk Date: Tue, 12 Sep 2023 16:17:19 -0300 Subject: [PATCH] feat: add observability for lambdas that call other lambdas --- lib/instrumentation/http-shared.js | 5 ++++- lib/lambda.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/instrumentation/http-shared.js b/lib/instrumentation/http-shared.js index b01397c9238..419c626f5bb 100644 --- a/lib/instrumentation/http-shared.js +++ b/lib/instrumentation/http-shared.js @@ -207,7 +207,10 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) { return function wrapHttpRequest(orig) { return function wrappedHttpRequest(input, options, cb) { const parentRunContext = ins.currRunContext(); - var span = ins.createSpan(null, 'external', 'http', { exitSpan: true }); + var span = + input?.headers?.['x-amz-invocation-type'] === 'RequestResponse' + ? null + : ins.createSpan(null, 'external', 'http', { exitSpan: true }); var id = span && span.transaction.id; agent.logger.debug('intercepted call to %s.%s %o', moduleName, method, { id, diff --git a/lib/lambda.js b/lib/lambda.js index 4ec510c5c91..73d9024bea7 100644 --- a/lib/lambda.js +++ b/lib/lambda.js @@ -705,6 +705,14 @@ function elasticApmAwsLambda(agent) { // Look for trace-context info in headers or messageAttributes. let traceparent; let tracestate; + if ( + triggerType === TRIGGER_GENERIC && + event.traceparent && + event.tracestate + ) { + traceparent = event.traceparent; + tracestate = event.tracestate; + } if ( (triggerType === TRIGGER_API_GATEWAY || triggerType === TRIGGER_ELB) && event.headers