-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathotel-handler
More file actions
executable file
·25 lines (18 loc) · 1.01 KB
/
otel-handler
File metadata and controls
executable file
·25 lines (18 loc) · 1.01 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
#!/bin/bash
set -ef -o pipefail
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestWrapper"
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi
CLOUD_ACCOUNT_ID=$(readlink /tmp/.otel-aws-account-id 2>/dev/null || true)
if [[ -n "$CLOUD_ACCOUNT_ID" && $OTEL_RESOURCE_ATTRIBUTES != *"cloud.account.id="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="cloud.account.id=${CLOUD_ACCOUNT_ID},${OTEL_RESOURCE_ATTRIBUTES}"
fi
if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi
export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000
# java17 runtime puts the handler to run as a command line argument and seems to prefer
# this over _HANDLER, so apply a regex to replace the original handler name with our wrapper
exec "${@//$OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER/$_HANDLER}"