Skip to content

Commit 17cc8c7

Browse files
authored
fix: Use proto version 2 to fix backfilled user agent and IP (#6256)
### Description Turn off user agent and user IP inference in Relay as it doesn't fill in the correct data for backend SDKs. `"version": 2` implies `"ingest_settings": {"infer_ip": "never", "infer_user_agent": "never"}`, as those are the default values for the settings in version 2. I'm not including the values in the item payload to keep it a bit slimmer. Spec: https://develop.sentry.dev/sdk/telemetry/metrics/#version-and-ingest_settings-properties (for metrics, but applies to logs and spans v2 as well; docs rework pending with getsentry/sentry-docs#17725) #### Issues * closes https://linear.app/getsentry/issue/PY-2413/send-ingest-settings * closes #6255 #### Reminders - Please add tests to validate your changes, and lint your code using `tox -e linters`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr)
1 parent c1921a4 commit 17cc8c7

6 files changed

Lines changed: 18 additions & 7 deletions

File tree

sentry_sdk/_batcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ def _add_to_envelope(self, envelope: "Envelope") -> None:
153153
},
154154
payload=PayloadRef(
155155
json={
156+
"version": 2,
156157
"items": [
157158
self._to_transport_format(item) for item in self._buffer
158-
]
159+
],
159160
}
160161
),
161162
)

sentry_sdk/_log_batcher.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ def _record_lost(self, item: "Log") -> None:
4545
headers={
4646
"item_count": 1,
4747
},
48-
payload=PayloadRef(json={"items": [self._to_transport_format(item)]}),
48+
payload=PayloadRef(
49+
json={
50+
"version": 2,
51+
"items": [self._to_transport_format(item)],
52+
}
53+
),
4954
)
5055

5156
self._record_lost_func(

sentry_sdk/_span_batcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,11 @@ def _flush(self, only_pending: bool = False) -> None:
224224
},
225225
payload=PayloadRef(
226226
json={
227+
"version": 2,
227228
"items": [
228229
self._to_transport_format(spans[j])
229230
for j in range(start, end)
230-
]
231+
],
231232
}
232233
),
233234
)

tests/test_logs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ def test_transport_format(sentry_init, capture_envelopes):
466466
"content_type": "application/vnd.sentry.items.log+json",
467467
}
468468
assert item.payload.json == {
469+
"version": 2,
469470
"items": [
470471
{
471472
"body": "This is a log...",
@@ -504,7 +505,7 @@ def test_transport_format(sentry_init, capture_envelopes):
504505
},
505506
},
506507
}
507-
]
508+
],
508509
}
509510

510511

@@ -544,6 +545,7 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1):
544545
"content_type": "application/vnd.sentry.items.log+json",
545546
}
546547
assert item.payload.json == {
548+
"version": 2,
547549
"items": [
548550
{
549551
"body": "This is a 'info' log...",
@@ -582,7 +584,7 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1):
582584
},
583585
},
584586
}
585-
]
587+
],
586588
}
587589

588590

tests/test_metrics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def test_transport_format(sentry_init, capture_envelopes):
267267
"content_type": "application/vnd.sentry.items.trace-metric+json",
268268
}
269269
assert item.payload.json == {
270+
"version": 2,
270271
"items": [
271272
{
272273
"name": "test.counter",
@@ -297,7 +298,7 @@ def test_transport_format(sentry_init, capture_envelopes):
297298
},
298299
},
299300
}
300-
]
301+
],
301302
}
302303

303304

tests/tracing/test_span_batcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def test_transport_format(sentry_init, capture_envelopes):
406406
"content_type": "application/vnd.sentry.items.span.v2+json",
407407
}
408408
assert item.payload.json == {
409+
"version": 2,
409410
"items": [
410411
{
411412
"trace_id": mock.ANY,
@@ -417,7 +418,7 @@ def test_transport_format(sentry_init, capture_envelopes):
417418
"end_timestamp": mock.ANY,
418419
"attributes": mock.ANY,
419420
}
420-
]
421+
],
421422
}
422423
for attribute, value in item.payload.json["items"][0]["attributes"].items():
423424
assert isinstance(attribute, str)

0 commit comments

Comments
 (0)