Skip to content

Commit

Permalink
Add cloud.account.id attribute by AwsLambdaInstrumentor (#2367)
Browse files Browse the repository at this point in the history
* Add cloud.account.id attribute by AwsLambdaInstrumentor

* Changelog

* Update test

* lint
  • Loading branch information
tammy-baylis-swi authored Mar 22, 2024
1 parent d06de3f commit 37aba92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2266))
- `opentelemetry-instrumentation-elasticsearch` Don't send bulk request body as db statement
([#2355](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2355))
- AwsLambdaInstrumentor sets `cloud.account.id` span attribute
([#2367](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2367))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,16 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
lambda_context.aws_request_id,
)

# NOTE: `cloud.account.id` can be parsed from the ARN as the fifth item when splitting on `:`
#
# See more:
# https://github.com/open-telemetry/semantic-conventions/blob/main/docs/faas/aws-lambda.md#all-triggers
account_id = lambda_context.invoked_function_arn.split(":")[4]
span.set_attribute(
ResourceAttributes.CLOUD_ACCOUNT_ID,
account_id,
)

exception = None
try:
result = call_wrapped(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, aws_request_id, invoked_function_arn):

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

MOCK_XRAY_TRACE_ID = 0x5FB7331105E8BB83207FA31D4D9CDB4C
Expand Down Expand Up @@ -147,6 +147,11 @@ def test_active_tracing(self):
{
ResourceAttributes.FAAS_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn,
SpanAttributes.FAAS_EXECUTION: MOCK_LAMBDA_CONTEXT.aws_request_id,
ResourceAttributes.CLOUD_ACCOUNT_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn.split(
":"
)[
4
],
},
)

Expand Down

0 comments on commit 37aba92

Please sign in to comment.