Skip to content

Commit 9b329de

Browse files
committed
update remote service and remote environment env var names
1 parent 9efb2d5 commit 9b329de

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,22 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
450450
)[-1]
451451
cloudformation_primary_identifier = _escape_delimiters(span.attributes.get(AWS_STEPFUNCTIONS_ACTIVITY_ARN))
452452
elif is_key_present(span, AWS_LAMBDA_FUNCTION_NAME):
453-
# To fix lambda topology issue, we handle the downstream lambda as a service ONLY IF the method
454-
# call is "Invoke". Otherwise, we treat the downstream lambda as an AWS resource.
453+
# Handling downstream Lambda as a service vs. an AWS resource:
454+
# - If the method call is "Invoke", we treat downstream Lambda as a service.
455+
# - Otherwise, we treat it as an AWS resource.
456+
#
457+
# This addresses a Lambda topology issue in Application Signals.
458+
# More context in PR: https://github.com/aws-observability/aws-otel-python-instrumentation/pull/319
459+
#
460+
# NOTE: The env vars LAMBDA_APPLICATION_SIGNALS_REMOTE_SERVICE and
461+
# LAMBDA_APPLICATION_SIGNALS_REMOTE_ENVIRONMENT were introduced as part of this fix.
462+
# They are optional and allow users to override the default values if needed.
455463
if span.attributes.get(_RPC_METHOD) == "Invoke":
456464
attributes[AWS_REMOTE_SERVICE] = os.environ.get(
457-
"AWS_LAMBDA_REMOTE_SERVICE", span.attributes.get(AWS_LAMBDA_FUNCTION_NAME)
465+
"LAMBDA_APPLICATION_SIGNALS_REMOTE_SERVICE", span.attributes.get(AWS_LAMBDA_FUNCTION_NAME)
458466
)
459467
attributes[AWS_REMOTE_ENVIRONMENT] = (
460-
f"lambda:{os.environ.get('AWS_LAMBDA_REMOTE_ENVIRONMENT', 'default')}"
468+
f'lambda:{os.environ.get("LAMBDA_APPLICATION_SIGNALS_REMOTE_ENVIRONMENT", "default")}'
461469
)
462470
else:
463471
remote_resource_type = _NORMALIZED_LAMBDA_SERVICE_NAME + "::Function"

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_metric_attribute_generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
11761176
self._mock_attribute([AWS_LAMBDA_FUNCTION_NAME, SpanAttributes.RPC_METHOD], [None, None])
11771177

11781178
# Test AWS Lambda Invoke scenario with user-configured lambda remote environment
1179-
os.environ["AWS_LAMBDA_REMOTE_ENVIRONMENT"] = "test"
1179+
os.environ["LAMBDA_APPLICATION_SIGNALS_REMOTE_ENVIRONMENT"] = "test"
11801180
self.span_mock.kind = SpanKind.CLIENT
11811181
self._mock_attribute(
11821182
[AWS_LAMBDA_FUNCTION_NAME, SpanAttributes.RPC_METHOD],
@@ -1193,10 +1193,10 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
11931193
self.assertNotIn(AWS_REMOTE_RESOURCE_IDENTIFIER, dependency_attributes)
11941194
self.assertNotIn(AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER, dependency_attributes)
11951195
self._mock_attribute([AWS_LAMBDA_FUNCTION_NAME, SpanAttributes.RPC_METHOD], [None, None])
1196-
os.environ.pop("AWS_LAMBDA_REMOTE_ENVIRONMENT", None)
1196+
os.environ.pop("LAMBDA_APPLICATION_SIGNALS_REMOTE_ENVIRONMENT", None)
11971197

11981198
# Test AWS Lambda Invoke scenario with user-configured lambda remote service
1199-
os.environ["AWS_LAMBDA_REMOTE_SERVICE"] = "test_downstream_lambda2"
1199+
os.environ["LAMBDA_APPLICATION_SIGNALS_REMOTE_SERVICE"] = "test_downstream_lambda2"
12001200
self.span_mock.kind = SpanKind.CLIENT
12011201
self._mock_attribute(
12021202
[AWS_LAMBDA_FUNCTION_NAME, SpanAttributes.RPC_METHOD],
@@ -1213,7 +1213,7 @@ def test_sdk_client_span_with_remote_resource_attributes(self):
12131213
self.assertNotIn(AWS_REMOTE_RESOURCE_IDENTIFIER, dependency_attributes)
12141214
self.assertNotIn(AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER, dependency_attributes)
12151215
self._mock_attribute([AWS_LAMBDA_FUNCTION_NAME, SpanAttributes.RPC_METHOD], [None, None])
1216-
os.environ.pop("AWS_LAMBDA_REMOTE_SERVICE", None)
1216+
os.environ.pop("LAMBDA_APPLICATION_SIGNALS_REMOTE_SERVICE", None)
12171217

12181218
# Test AWS Lambda non-Invoke scenario
12191219
self.span_mock.kind = SpanKind.CLIENT

0 commit comments

Comments
 (0)