Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions java/layer-javaagent/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions java/layer-wrapper/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions python/src/otel/otel_sdk/otel-instrument
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we are deviating from the strategy above for initializing the resource attributes? Generally, I think that the single if statement is a bit more readable.

Copy link
Member

@wpessers wpessers Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, agree

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`

Expand Down
8 changes: 8 additions & 0 deletions ruby/src/otel/layer/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
Loading