Skip to content

Commit

Permalink
fix test_instrument_aws_lambda by setting AWS_LAMBDA_FUNCTION_NAME en…
Browse files Browse the repository at this point in the history
…v var
  • Loading branch information
alexmojaki committed Feb 5, 2025
1 parent e257eb2 commit f1f8f5e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/otel_integrations/test_aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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',
Expand Down

0 comments on commit f1f8f5e

Please sign in to comment.