From f1f8f5e514de7960eb6f52af6e50b7fad26f12b0 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Wed, 5 Feb 2025 12:58:09 +0200 Subject: [PATCH] fix test_instrument_aws_lambda by setting AWS_LAMBDA_FUNCTION_NAME env var --- tests/otel_integrations/test_aws_lambda.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/otel_integrations/test_aws_lambda.py b/tests/otel_integrations/test_aws_lambda.py index ed1b3e7dc..170bdf340 100644 --- a/tests/otel_integrations/test_aws_lambda.py +++ b/tests/otel_integrations/test_aws_lambda.py @@ -23,6 +23,9 @@ def lambda_handler(event: Any, context: MockLambdaContext): pass +HANDLER_NAME = f'{__name__}.{lambda_handler.__name__}' + + # The below mock is based on the following code: # https://github.com/open-telemetry/opentelemetry-python-contrib/blob/ecf5529f99222e7d945eddcaa83acb8a47c9ba42/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py#L57-L66 @dataclass @@ -39,7 +42,7 @@ def test_instrument_aws_lambda(exporter: TestExporter) -> None: with logfire.span('span'): current_context = get_context() - with mock.patch.dict('os.environ', {_HANDLER: 'tests.otel_integrations.test_aws_lambda.lambda_handler'}): + with mock.patch.dict('os.environ', {_HANDLER: HANDLER_NAME, 'AWS_LAMBDA_FUNCTION_NAME': HANDLER_NAME}): logfire.instrument_aws_lambda(lambda_handler, event_context_extractor=event_context_extractor) context = MockLambdaContext( @@ -66,14 +69,14 @@ def test_instrument_aws_lambda(exporter: TestExporter) -> None: }, }, { - 'name': 'tests.otel_integrations.test_aws_lambda.lambda_handler', + 'name': HANDLER_NAME, 'context': {'trace_id': 1, 'span_id': 3, 'is_remote': False}, 'parent': {'trace_id': 1, 'span_id': 1, 'is_remote': True}, 'start_time': 3000000000, 'end_time': 4000000000, 'attributes': { 'logfire.span_type': 'span', - 'logfire.msg': 'tests.otel_integrations.test_aws_lambda.lambda_handler', + 'logfire.msg': HANDLER_NAME, 'cloud.resource_id': 'arn:aws:lambda:us-east-1:123456:function:myfunction:myalias', 'faas.invocation_id': 'mock_aws_request_id', 'cloud.account.id': '123456',