diff --git a/README.md b/README.md index 5256248624..7b384acd8a 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,23 @@ These 2 layers are meant to be used in conjunction to instrument your lambda fun To get a better understanding of the proposed design for the OpenTelemetry Lambda extension, you can see the [Design Proposal here.](docs/design_proposal.md) +## Wrapper Script Configuration + +Each language layer includes a wrapper script (`otel-handler` or `otel-instrument`) that is invoked via `AWS_LAMBDA_EXEC_WRAPPER` before the Lambda runtime starts. These scripts configure the following environment variables: + +### `OTEL_PROPAGATORS` + +If not already set, the wrapper scripts default `OTEL_PROPAGATORS` to `tracecontext,baggage,xray`. + +### `OTEL_RESOURCE_ATTRIBUTES` + +The wrapper scripts extend `OTEL_RESOURCE_ATTRIBUTES` with: + +- **`service.name`** — set to the Lambda function name (`AWS_LAMBDA_FUNCTION_NAME`) if not already present. +- **`cloud.account.id`** — the AWS account ID, read from a symlink at `/tmp/.otel-aws-account-id` that is created by the collector extension during registration. This is added automatically when the collector layer is used alongside a language layer. If the symlink does not exist (e.g., when running without the collector layer), the attribute is silently skipped. + +User-provided values in `OTEL_RESOURCE_ATTRIBUTES` are never overwritten. + ## Features The following is a list of features provided by the OpenTelemetry layers. diff --git a/java/layer-javaagent/scripts/otel-handler b/java/layer-javaagent/scripts/otel-handler index adb31a263e..08cd69a747 100755 --- a/java/layer-javaagent/scripts/otel-handler +++ b/java/layer-javaagent/scripts/otel-handler @@ -8,6 +8,11 @@ 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 diff --git a/java/layer-wrapper/scripts/otel-handler b/java/layer-wrapper/scripts/otel-handler index 0bc9d33dd6..155eaef865 100755 --- a/java/layer-wrapper/scripts/otel-handler +++ b/java/layer-wrapper/scripts/otel-handler @@ -9,6 +9,11 @@ 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 diff --git a/nodejs/packages/layer/scripts/otel-handler b/nodejs/packages/layer/scripts/otel-handler index b3c615e6d3..32e612a1a6 100755 --- a/nodejs/packages/layer/scripts/otel-handler +++ b/nodejs/packages/layer/scripts/otel-handler @@ -12,6 +12,11 @@ if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then fi 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 diff --git a/python/src/otel/otel_sdk/otel-instrument b/python/src/otel/otel_sdk/otel-instrument index 9d89c96b62..90df003d30 100755 --- a/python/src/otel/otel_sdk/otel-instrument +++ b/python/src/otel/otel_sdk/otel-instrument @@ -146,6 +146,14 @@ else export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES,$OTEL_RESOURCE_ATTRIBUTES"; fi +CLOUD_ACCOUNT_ID=$(readlink /tmp/.otel-aws-account-id 2>/dev/null || true) +if [ -n "$CLOUD_ACCOUNT_ID" ]; then + case "$OTEL_RESOURCE_ATTRIBUTES" in + *cloud.account.id=*) ;; + *) export OTEL_RESOURCE_ATTRIBUTES="cloud.account.id=${CLOUD_ACCOUNT_ID},${OTEL_RESOURCE_ATTRIBUTES}" ;; + esac +fi + # - Uses the default `OTEL_PROPAGATORS` which is set to `tracecontext,baggage` diff --git a/ruby/src/otel/layer/otel-handler b/ruby/src/otel/layer/otel-handler index a7994f48ed..87ae1811af 100755 --- a/ruby/src/otel/layer/otel-handler +++ b/ruby/src/otel/layer/otel-handler @@ -19,4 +19,12 @@ else export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES,$OTEL_RESOURCE_ATTRIBUTES"; fi +CLOUD_ACCOUNT_ID=$(readlink /tmp/.otel-aws-account-id 2>/dev/null || true) +if [ -n "$CLOUD_ACCOUNT_ID" ]; then + case "$OTEL_RESOURCE_ATTRIBUTES" in + *cloud.account.id=*) ;; + *) export OTEL_RESOURCE_ATTRIBUTES="cloud.account.id=${CLOUD_ACCOUNT_ID},${OTEL_RESOURCE_ATTRIBUTES}" ;; + esac +fi + exec "$@"