diff --git a/CHANGELOG.md b/CHANGELOG.md index f04f8647af..9e9cb30ca4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,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)) - `opentelemetry-instrumentation-asyncpg` Fix fallback for empty queries. ([#3253](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3253)) - `opentelemetry-instrumentation-threading` Fix broken context typehints diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py index 117613603a..3ff42a3fed 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py @@ -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( diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py index 5d6b94f145..38bdfc28a3 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py @@ -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() @@ -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 @@ -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 @@ -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)