Skip to content

Commit 37aba92

Browse files
Add cloud.account.id attribute by AwsLambdaInstrumentor (#2367)
* Add cloud.account.id attribute by AwsLambdaInstrumentor * Changelog * Update test * lint
1 parent d06de3f commit 37aba92

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
([#2266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2266))
2626
- `opentelemetry-instrumentation-elasticsearch` Don't send bulk request body as db statement
2727
([#2355](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2355))
28+
- AwsLambdaInstrumentor sets `cloud.account.id` span attribute
29+
([#2367](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2367))
2830

2931
## Version 1.23.0/0.44b0 (2024-02-23)
3032

instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
354354
lambda_context.aws_request_id,
355355
)
356356

357+
# NOTE: `cloud.account.id` can be parsed from the ARN as the fifth item when splitting on `:`
358+
#
359+
# See more:
360+
# https://github.com/open-telemetry/semantic-conventions/blob/main/docs/faas/aws-lambda.md#all-triggers
361+
account_id = lambda_context.invoked_function_arn.split(":")[4]
362+
span.set_attribute(
363+
ResourceAttributes.CLOUD_ACCOUNT_ID,
364+
account_id,
365+
)
366+
357367
exception = None
358368
try:
359369
result = call_wrapped(*args, **kwargs)

instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, aws_request_id, invoked_function_arn):
5454

5555
MOCK_LAMBDA_CONTEXT = MockLambdaContext(
5656
aws_request_id="mock_aws_request_id",
57-
invoked_function_arn="arn://mock-lambda-function-arn",
57+
invoked_function_arn="arn:aws:lambda:us-east-1:123456:function:myfunction:myalias",
5858
)
5959

6060
MOCK_XRAY_TRACE_ID = 0x5FB7331105E8BB83207FA31D4D9CDB4C
@@ -147,6 +147,11 @@ def test_active_tracing(self):
147147
{
148148
ResourceAttributes.FAAS_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn,
149149
SpanAttributes.FAAS_EXECUTION: MOCK_LAMBDA_CONTEXT.aws_request_id,
150+
ResourceAttributes.CLOUD_ACCOUNT_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn.split(
151+
":"
152+
)[
153+
4
154+
],
150155
},
151156
)
152157

0 commit comments

Comments
 (0)