Skip to content

Commit 26f2063

Browse files
committed
redact phone_number
Signed-off-by: emdneto <[email protected]>
1 parent 9497566 commit 26f2063

File tree

2 files changed

+20
-21
lines changed
  • instrumentation/opentelemetry-instrumentation-botocore

2 files changed

+20
-21
lines changed

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,35 @@ def span_kind(cls) -> SpanKind:
7373
def extract_attributes(
7474
cls, call_context: _AwsSdkCallContext, attributes: _AttributeMapT
7575
):
76-
destination_name, is_phone_number = cls._extract_destination_name(
76+
span_name, destination_name = cls._extract_destination_name(
7777
call_context
7878
)
79+
80+
call_context.span_name = f"{span_name} send"
81+
7982
attributes[SpanAttributes.MESSAGING_DESTINATION_KIND] = (
8083
MessagingDestinationKindValues.TOPIC.value
8184
)
8285
attributes[SpanAttributes.MESSAGING_DESTINATION] = destination_name
83-
84-
if not is_phone_number:
85-
attributes[SpanAttributes.MESSAGING_DESTINATION_NAME] = (
86-
cls._extract_input_arn(call_context)
87-
)
88-
call_context.span_name = (
89-
f"{'phone_number' if is_phone_number else destination_name} send"
86+
attributes[SpanAttributes.MESSAGING_DESTINATION_NAME] = (
87+
destination_name
9088
)
9189

9290
@classmethod
9391
def _extract_destination_name(
9492
cls, call_context: _AwsSdkCallContext
95-
) -> Tuple[str, bool]:
93+
) -> Tuple[str, str]:
9694
arn = cls._extract_input_arn(call_context)
9795
if arn:
98-
return arn.rsplit(":", 1)[-1], False
96+
return arn.rsplit(":", 1)[-1], arn
9997

10098
if cls._phone_arg_name:
10199
phone_number = call_context.params.get(cls._phone_arg_name)
102100
if phone_number:
103-
return phone_number, True
101+
# phone number redacted because it's a PII
102+
return "phone_number", "phone_number:**"
104103

105-
return "unknown", False
104+
return "unknown", "unknown"
106105

107106
@classmethod
108107
def _extract_input_arn(

instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def setUp(self):
4141
)
4242
self.client = session.create_client("sns", region_name="us-west-2")
4343
self.topic_name = "my-topic"
44+
self.topic_arn = (
45+
f"arn:aws:sns:us-west-2:123456789012:{self.topic_name}"
46+
)
4447

4548
def tearDown(self):
4649
super().tearDown()
@@ -115,14 +118,12 @@ def _test_publish_to_arn(self, arg_name: str):
115118
span.attributes[SpanAttributes.MESSAGING_DESTINATION_KIND],
116119
)
117120
self.assertEqual(
118-
self.topic_name,
121+
self.topic_arn,
119122
span.attributes[SpanAttributes.MESSAGING_DESTINATION],
120123
)
121124
self.assertEqual(
122125
target_arn,
123-
# TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when
124-
# opentelemetry-semantic-conventions 0.42b0 is released
125-
span.attributes["messaging.destination.name"],
126+
span.attributes[SpanAttributes.MESSAGING_DESTINATION_NAME],
126127
)
127128

128129
@mock_aws
@@ -135,7 +136,8 @@ def test_publish_to_phone_number(self):
135136

136137
span = self.assert_span("phone_number send")
137138
self.assertEqual(
138-
phone_number, span.attributes[SpanAttributes.MESSAGING_DESTINATION]
139+
"phone_number:**",
140+
span.attributes[SpanAttributes.MESSAGING_DESTINATION],
139141
)
140142

141143
@mock_aws
@@ -187,14 +189,12 @@ def test_publish_batch_to_topic(self):
187189
span.attributes[SpanAttributes.MESSAGING_DESTINATION_KIND],
188190
)
189191
self.assertEqual(
190-
self.topic_name,
192+
topic_arn,
191193
span.attributes[SpanAttributes.MESSAGING_DESTINATION],
192194
)
193195
self.assertEqual(
194196
topic_arn,
195-
# TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when
196-
# opentelemetry-semantic-conventions 0.42b0 is released
197-
span.attributes["messaging.destination.name"],
197+
span.attributes[SpanAttributes.MESSAGING_DESTINATION_NAME],
198198
)
199199

200200
self.assert_injected_span(message1_attrs, span)

0 commit comments

Comments
 (0)