Change AwsLambdaInstrumentor span attrs to meet faas semconv (#2372)

This commit is contained in:
Tammy Baylis 2024-04-17 09:09:55 -07:00 committed by GitHub
parent 99678ccd3a
commit 07318bd378
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View File

@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rename `type` attribute to `asgi.event.type` in `opentelemetry-instrumentation-asgi` - Rename `type` attribute to `asgi.event.type` in `opentelemetry-instrumentation-asgi`
([#2300](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2300)) ([#2300](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2300))
- Rename AwsLambdaInstrumentor span attributes `faas.id` to `cloud.resource_id`, `faas.execution` to `faas.invocation_id`
([#2372](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2372))
### Added ### Added

View File

@ -340,17 +340,17 @@ def _instrument(
if span.is_recording(): if span.is_recording():
lambda_context = args[1] lambda_context = args[1]
# NOTE: The specs mention an exception here, allowing the # NOTE: The specs mention an exception here, allowing the
# `ResourceAttributes.FAAS_ID` attribute to be set as a span # `SpanAttributes.CLOUD_RESOURCE_ID` attribute to be set as a span
# attribute instead of a resource attribute. # attribute instead of a resource attribute.
# #
# See more: # See more:
# https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/faas.md#example # https://github.com/open-telemetry/semantic-conventions/blob/main/docs/faas/aws-lambda.md#resource-detector
span.set_attribute( span.set_attribute(
ResourceAttributes.FAAS_ID, SpanAttributes.CLOUD_RESOURCE_ID,
lambda_context.invoked_function_arn, lambda_context.invoked_function_arn,
) )
span.set_attribute( span.set_attribute(
SpanAttributes.FAAS_EXECUTION, SpanAttributes.FAAS_INVOCATION_ID,
lambda_context.aws_request_id, lambda_context.aws_request_id,
) )

View File

@ -145,8 +145,8 @@ class TestAwsLambdaInstrumentor(TestBase):
self.assertSpanHasAttributes( self.assertSpanHasAttributes(
span, span,
{ {
ResourceAttributes.FAAS_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn, SpanAttributes.CLOUD_RESOURCE_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn,
SpanAttributes.FAAS_EXECUTION: MOCK_LAMBDA_CONTEXT.aws_request_id, SpanAttributes.FAAS_INVOCATION_ID: MOCK_LAMBDA_CONTEXT.aws_request_id,
ResourceAttributes.CLOUD_ACCOUNT_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn.split( ResourceAttributes.CLOUD_ACCOUNT_ID: MOCK_LAMBDA_CONTEXT.invoked_function_arn.split(
":" ":"
)[ )[