From 8c5a5fe6f816ad4fcb74df86b56715482b0f3829 Mon Sep 17 00:00:00 2001 From: Raphael Manke Date: Mon, 9 Feb 2026 20:48:34 +0100 Subject: [PATCH 1/2] Add cloud.account.id support to Lambda resource detector via symlink Read /tmp/.otel-account-id symlink (created by the OTel Lambda extension) using File.readlink to populate the cloud.account.id resource attribute. Silently skips if the symlink does not exist (ENOENT) or is not a symlink (EINVAL). Account ID is treated as a string to preserve leading zeros. --- .../resource/detector/aws/lambda.rb | 11 ++++++ .../resource/detector/aws/lambda_test.rb | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/resources/aws/lib/opentelemetry/resource/detector/aws/lambda.rb b/resources/aws/lib/opentelemetry/resource/detector/aws/lambda.rb index f8db75bbfd..0e28d847e8 100644 --- a/resources/aws/lib/opentelemetry/resource/detector/aws/lambda.rb +++ b/resources/aws/lib/opentelemetry/resource/detector/aws/lambda.rb @@ -17,6 +17,9 @@ module Lambda # Create a constant for resource semantic conventions RESOURCE = OpenTelemetry::SemanticConventions::Resource + # Path to the symlink created by the OTel Lambda extension containing the AWS account ID + ACCOUNT_ID_SYMLINK_PATH = '/tmp/.otel-account-id' + def detect # Return empty resource if not running on Lambda return OpenTelemetry::SDK::Resources::Resource.create({}) unless lambda_environment? @@ -34,6 +37,14 @@ def detect # Convert memory size to integer resource_attributes[RESOURCE::FAAS_MAX_MEMORY] = ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE'].to_i if ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE'] + + # Read cloud.account.id from symlink created by the OTel Lambda extension + begin + account_id = File.readlink(ACCOUNT_ID_SYMLINK_PATH) + resource_attributes[RESOURCE::CLOUD_ACCOUNT_ID] = account_id + rescue Errno::ENOENT, Errno::EINVAL + # Symlink doesn't exist or is not a symlink — silently skip + end rescue StandardError => e OpenTelemetry.handle_error(exception: e, message: 'Lambda resource detection failed') return OpenTelemetry::SDK::Resources::Resource.create({}) diff --git a/resources/aws/test/opentelemetry/resource/detector/aws/lambda_test.rb b/resources/aws/test/opentelemetry/resource/detector/aws/lambda_test.rb index c94fdcad21..cd8536db32 100644 --- a/resources/aws/test/opentelemetry/resource/detector/aws/lambda_test.rb +++ b/resources/aws/test/opentelemetry/resource/detector/aws/lambda_test.rb @@ -61,6 +61,40 @@ _(attributes).wont_include(OpenTelemetry::SemanticConventions::Resource::FAAS_MAX_MEMORY) end + + describe 'cloud.account.id from symlink' do + it 'reads cloud.account.id from the symlink' do + File.stub :readlink, '123456789012' do + resource = detector.detect + attributes = resource.attribute_enumerator.to_h + _(attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID]).must_equal('123456789012') + end + end + + it 'preserves leading zeros in account id' do + File.stub :readlink, '000123456789' do + resource = detector.detect + attributes = resource.attribute_enumerator.to_h + _(attributes[OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID]).must_equal('000123456789') + end + end + + it 'silently skips when symlink does not exist' do + File.stub :readlink, ->(_path) { raise Errno::ENOENT } do + resource = detector.detect + attributes = resource.attribute_enumerator.to_h + _(attributes).wont_include(OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID) + end + end + + it 'silently skips when path is not a symlink' do + File.stub :readlink, ->(_path) { raise Errno::EINVAL } do + resource = detector.detect + attributes = resource.attribute_enumerator.to_h + _(attributes).wont_include(OpenTelemetry::SemanticConventions::Resource::CLOUD_ACCOUNT_ID) + end + end + end end describe 'when partial Lambda environment is detected' do From 0a6a8b777218b3c25976d630cbe68efcef972aed Mon Sep 17 00:00:00 2001 From: Raphael Manke Date: Wed, 11 Feb 2026 08:25:10 +0100 Subject: [PATCH 2/2] docs: add CHANGELOG entry for cloud.account.id symlink feature --- instrumentation/aws_lambda/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/instrumentation/aws_lambda/CHANGELOG.md b/instrumentation/aws_lambda/CHANGELOG.md index 8a791ca5c8..d7e805cb49 100644 --- a/instrumentation/aws_lambda/CHANGELOG.md +++ b/instrumentation/aws_lambda/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-instrumentation-aws_lambda +### Unreleased + +* ADDED: Read `cloud.account.id` from symlink created by the OTel Lambda Extension + ### v0.6.0 / 2025-10-22 * BREAKING CHANGE: Min Ruby Version 3.2