Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botocore: sns set destination name attribute only if not phone number #3249

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

emdneto
Copy link
Member

@emdneto emdneto commented Feb 7, 2025

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py::TestSnsExtension::test_publish_to_phone_number 
-------------------------------------------------------------------------------- live log call --------------------------------------------------------------------------------
WARNING  opentelemetry.attributes:__init__.py:100 Invalid type NoneType for attribute 'messaging.destination.name' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

tox.ini Show resolved Hide resolved
@emdneto emdneto marked this pull request as ready for review February 11, 2025 14:29
@emdneto emdneto requested a review from a team as a code owner February 11, 2025 14:29
call_context
)
if not is_phone_number:
attributes[SpanAttributes.MESSAGING_DESTINATION_NAME] = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also the same TODOs in the tests in opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py

)
if not is_phone_number:
attributes[SpanAttributes.MESSAGING_DESTINATION_NAME] = (
cls._extract_input_arn(call_context)
Copy link
Contributor

@xrmx xrmx Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the issue here is that this should be set to destination_namewe got from cls._extract_destination_name a few lines above instead?

Copy link
Member Author

@emdneto emdneto Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, destination_name would be the phone number. I'm not sure if it's a "valid" destination name. According to the semantic convention, it should be used for ARNs, topic /queue names, or something like that 🤔 So I'm presuming if it's phone number there's no destination name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I think we are being redundant here no?

MESSAGING_DESTINATION and MESSAGING_DESTINATION_NAME are the same thing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you ok to drop L82 and keep only attributes[SpanAttributes.MESSAGING_DESTINATION_NAME] = destination_name ?

Copy link
Contributor

@xrmx xrmx Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would break users though. Until we implement the stable opt-in config I would keep the redundancy. Said that there's another issue there we should not publish the phone number because it's PII. So I would reuse the same variable but redact the phone number in _extract_destination_name. This way we can use it directly in the span name.

Copy link
Contributor

@xrmx xrmx Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this:

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 11761360..26388df4 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
@@ -81,14 +81,8 @@ class _OpPublish(_SnsOperation):
             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
+        call_context.span_name = f"{destination_name} send"
 
     @classmethod
     def _extract_destination_name(
@@ -101,7 +95,8 @@ class _OpPublish(_SnsOperation):
         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", True
 
         return "unknown", False

Hopefully people won't have topics called "phone_number" :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants