Skip to content

Commit d27121a

Browse files
authored
prefix AWS.SDK to the RemoteService for AWS SDK spans (#83)
Similar to what we do in adot java: aws-observability/aws-otel-java-instrumentation#756 If the span is an AWS SDK (boto) span, then we will prefix the RemoteService name with `AWS.SDK.` for consistency across the metrics generated from different ADOT SDKs By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
2 parents 5fa9864 + 7a8b0aa commit d27121a

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
extract_api_path_value,
2828
get_egress_operation,
2929
get_ingress_operation,
30+
is_aws_sdk_span,
3031
is_key_present,
3132
is_local_root,
3233
should_generate_dependency_metric_attributes,
@@ -268,10 +269,9 @@ def _get_db_statement_remote_operation(span: ReadableSpan, statement_key: str) -
268269

269270

270271
def _normalize_service_name(span: ReadableSpan, service_name: str) -> str:
271-
"""
272-
TODO: Determine if problems in Java instrumentation are relevant here. Do we need normalization? If so, probably we
273-
are looking for boto, not aws-sdk
274-
"""
272+
if is_aws_sdk_span(span):
273+
return "AWS.SDK." + service_name
274+
275275
return service_name
276276

277277

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,25 @@ def test_both_metric_when_local_root_consumer_process(self):
674674
self.assertIsNotNone(service_attributes)
675675
self.assertIsNotNone(dependency_attributes)
676676

677+
def test_normalize_service_name_non_aws_sdk_span(self):
678+
service_name: str = "non aws service"
679+
self._mock_attribute([SpanAttributes.RPC_SERVICE], [service_name])
680+
self.span_mock.kind = SpanKind.CLIENT
681+
682+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
683+
self.span_mock, self.resource
684+
).get(DEPENDENCY_METRIC)
685+
self.assertEqual(actual_attributes.get(AWS_REMOTE_SERVICE), service_name)
686+
687+
def test_normalize_service_name_aws_sdk_span(self):
688+
self._mock_attribute([SpanAttributes.RPC_SYSTEM, SpanAttributes.RPC_SERVICE], ["aws-api", "EC2"])
689+
self.span_mock.kind = SpanKind.CLIENT
690+
691+
actual_attributes: Attributes = _GENERATOR.generate_metric_attributes_dict_from_span(
692+
self.span_mock, self.resource
693+
).get(DEPENDENCY_METRIC)
694+
self.assertEqual(actual_attributes.get(AWS_REMOTE_SERVICE), "AWS.SDK.EC2")
695+
677696
def _update_resource_with_service_name(self) -> None:
678697
self.resource: Resource = Resource(attributes={SERVICE_NAME: _SERVICE_NAME_VALUE})
679698

0 commit comments

Comments
 (0)