Skip to content
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `opentelemetry-instrumentation-redis` Add missing entry in doc string for `def _instrument`
([#3247](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3247))
- `opentelemetry-instrumentation-botocore` sns-extension: Change destination name attribute
to match topic ARN and redact phone number from attributes
([#3249](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3249))

## Version 1.30.0/0.51b0 (2025-02-03)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,35 @@ def span_kind(cls) -> SpanKind:
def extract_attributes(
cls, call_context: _AwsSdkCallContext, attributes: _AttributeMapT
):
destination_name, is_phone_number = cls._extract_destination_name(
span_name, destination_name = cls._extract_destination_name(
call_context
)

call_context.span_name = f"{span_name} send"

attributes[SpanAttributes.MESSAGING_DESTINATION_KIND] = (
MessagingDestinationKindValues.TOPIC.value
)
attributes[SpanAttributes.MESSAGING_DESTINATION] = destination_name

# TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when opentelemetry-semantic-conventions 0.42b0 is released
attributes["messaging.destination.name"] = cls._extract_input_arn(
call_context
)
call_context.span_name = (
f"{'phone_number' if is_phone_number else destination_name} send"
attributes[SpanAttributes.MESSAGING_DESTINATION_NAME] = (
destination_name
)

@classmethod
def _extract_destination_name(
cls, call_context: _AwsSdkCallContext
) -> Tuple[str, bool]:
) -> Tuple[str, str]:
arn = cls._extract_input_arn(call_context)
if arn:
return arn.rsplit(":", 1)[-1], False
return arn.rsplit(":", 1)[-1], arn

if cls._phone_arg_name:
phone_number = call_context.params.get(cls._phone_arg_name)
if phone_number:
return phone_number, True
# phone number redacted because it's a PII
return "phone_number", "phone_number:**"

return "unknown", False
return "unknown", "unknown"

@classmethod
def _extract_input_arn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def setUp(self):
)
self.client = session.create_client("sns", region_name="us-west-2")
self.topic_name = "my-topic"
self.topic_arn = (
f"arn:aws:sns:us-west-2:123456789012:{self.topic_name}"
)

def tearDown(self):
super().tearDown()
Expand Down Expand Up @@ -115,14 +118,12 @@ def _test_publish_to_arn(self, arg_name: str):
span.attributes[SpanAttributes.MESSAGING_DESTINATION_KIND],
)
self.assertEqual(
self.topic_name,
self.topic_arn,
span.attributes[SpanAttributes.MESSAGING_DESTINATION],
)
self.assertEqual(
target_arn,
# TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when
# opentelemetry-semantic-conventions 0.42b0 is released
span.attributes["messaging.destination.name"],
span.attributes[SpanAttributes.MESSAGING_DESTINATION_NAME],
)

@mock_aws
Expand All @@ -135,7 +136,8 @@ def test_publish_to_phone_number(self):

span = self.assert_span("phone_number send")
self.assertEqual(
phone_number, span.attributes[SpanAttributes.MESSAGING_DESTINATION]
"phone_number:**",
span.attributes[SpanAttributes.MESSAGING_DESTINATION],
)

@mock_aws
Expand Down Expand Up @@ -187,14 +189,12 @@ def test_publish_batch_to_topic(self):
span.attributes[SpanAttributes.MESSAGING_DESTINATION_KIND],
)
self.assertEqual(
self.topic_name,
topic_arn,
span.attributes[SpanAttributes.MESSAGING_DESTINATION],
)
self.assertEqual(
topic_arn,
# TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when
# opentelemetry-semantic-conventions 0.42b0 is released
span.attributes["messaging.destination.name"],
span.attributes[SpanAttributes.MESSAGING_DESTINATION_NAME],
)

self.assert_injected_span(message1_attrs, span)
Expand Down