Skip to content

Commit d791f14

Browse files
committed
Bring all span data under pii control
1 parent 4bec4a4 commit d791f14

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

sentry_sdk/integrations/rust_tracing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,18 @@ def on_new_span(self, attrs: str, span_id: str) -> TraceState:
205205
else:
206206
sentry_span = scope.start_span(**kwargs)
207207

208+
send_sensitive_data = (
209+
should_send_default_pii()
210+
if self.send_sensitive_data is None
211+
else self.send_sensitive_data
212+
)
213+
208214
fields = metadata.get("fields", [])
209215
for field in fields:
210-
sentry_span.set_data(field, attrs.get(field))
216+
if send_sensitive_data:
217+
sentry_span.set_data(field, attrs.get(field))
218+
else:
219+
sentry_span.set_data(field, SENSITIVE_DATA_SUBSTITUTE)
211220

212221
scope.span = sentry_span
213222
return (parent_sentry_span, sentry_span)

tests/integrations/rust_tracing/test_rust_tracing.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from unittest import mock
12
import pytest
23

34
from string import Template
@@ -66,7 +67,9 @@ def record(self, span_id: int):
6667
def test_on_new_span_on_close(sentry_init, capture_events):
6768
rust_tracing = FakeRustTracing()
6869
integration = RustTracingIntegration(
69-
"test_on_new_span_on_close", rust_tracing.set_layer_impl
70+
"test_on_new_span_on_close",
71+
initializer=rust_tracing.set_layer_impl,
72+
send_sensitive_data=True,
7073
)
7174
sentry_init(integrations=[integration], traces_sample_rate=1.0)
7275

@@ -105,7 +108,9 @@ def test_on_new_span_on_close(sentry_init, capture_events):
105108
def test_nested_on_new_span_on_close(sentry_init, capture_events):
106109
rust_tracing = FakeRustTracing()
107110
integration = RustTracingIntegration(
108-
"test_nested_on_new_span_on_close", rust_tracing.set_layer_impl
111+
"test_nested_on_new_span_on_close",
112+
initializer=rust_tracing.set_layer_impl,
113+
send_sensitive_data=True,
109114
)
110115
sentry_init(integrations=[integration], traces_sample_rate=1.0)
111116

@@ -331,7 +336,10 @@ def span_filter(metadata: Dict[str, object]) -> bool:
331336

332337
rust_tracing = FakeRustTracing()
333338
integration = RustTracingIntegration(
334-
"test_span_filter", rust_tracing.set_layer_impl, span_filter=span_filter
339+
"test_span_filter",
340+
initializer=rust_tracing.set_layer_impl,
341+
span_filter=span_filter,
342+
send_sensitive_data=True,
335343
)
336344
sentry_init(integrations=[integration], traces_sample_rate=1.0)
337345

@@ -391,6 +399,7 @@ def span_filter(metadata: Dict[str, object]) -> bool:
391399
"test_record_in_ignored_span",
392400
rust_tracing.set_layer_impl,
393401
span_filter=span_filter,
402+
send_sensitive_data=True,
394403
)
395404
sentry_init(integrations=[integration], traces_sample_rate=1.0)
396405

@@ -438,13 +447,29 @@ def test_sensitive_data(
438447
rust_tracing.new_span(RustTracingLevel.Info, 3)
439448

440449
span_before_record = sentry_sdk.get_current_span().to_json()
441-
assert span_before_record["data"]["version"] is None
450+
if sensitive_data_expected:
451+
assert span_before_record["data"]["version"] is None
452+
else:
453+
assert span_before_record["data"]["version"] == "[Filtered]"
442454

443455
rust_tracing.record(3)
444456

445457
span_after_record = sentry_sdk.get_current_span().to_json()
446458

447459
if sensitive_data_expected:
448-
assert span_after_record["data"]["version"] == "memoized"
460+
assert span_after_record["data"] == {
461+
"thread.id": mock.ANY,
462+
"thread.name": mock.ANY,
463+
"use_memoized": True,
464+
"version": "memoized",
465+
"index": 10,
466+
}
467+
449468
else:
450-
assert span_after_record["data"]["version"] == "[Filtered]"
469+
assert span_after_record["data"] == {
470+
"thread.id": mock.ANY,
471+
"thread.name": mock.ANY,
472+
"use_memoized": "[Filtered]",
473+
"version": "[Filtered]",
474+
"index": "[Filtered]",
475+
}

0 commit comments

Comments
 (0)