|
4 | 4 | from datetime import datetime
|
5 | 5 | from itertools import islice
|
6 | 6 | import socket
|
7 |
| -import json |
8 | 7 |
|
9 | 8 | from sentry_sdk._compat import string_types, text_type, iteritems
|
10 | 9 | from sentry_sdk.utils import (
|
11 | 10 | capture_internal_exceptions,
|
12 | 11 | current_stacktrace,
|
13 | 12 | disable_capture_event,
|
14 | 13 | format_timestamp,
|
15 |
| - from_base64, |
16 | 14 | get_type_name,
|
17 | 15 | get_default_release,
|
18 | 16 | handle_in_app,
|
|
25 | 23 | from sentry_sdk.utils import ContextVar
|
26 | 24 | from sentry_sdk.sessions import SessionFlusher
|
27 | 25 | from sentry_sdk.envelope import Envelope
|
| 26 | +from sentry_sdk.tracing_utils import reinflate_tracestate |
28 | 27 |
|
29 | 28 | from sentry_sdk._types import MYPY
|
30 | 29 |
|
@@ -352,30 +351,9 @@ def capture_event(
|
352 | 351 | "sent_at": format_timestamp(datetime.utcnow()),
|
353 | 352 | }
|
354 | 353 |
|
355 |
| - if raw_tracestate: |
356 |
| - # Base64-encoded strings always come out with a length which is a multiple |
357 |
| - # of 4. In order to achieve this, the end is padded with one or more `=` |
358 |
| - # signs. Because the tracestate standard calls for using `=` signs between |
359 |
| - # vendor name and value (`sentry=xxx,dogsaregreat=yyy`), to avoid confusion |
360 |
| - # we strip the `=` when the data is initially encoded. Python's decoding |
361 |
| - # function requires they be put back. |
362 |
| - |
363 |
| - # The final mod 4 is necessary because 4 is represented as 4 |
364 |
| - # rather than 0. |
365 |
| - missing_equals = (4 - (len(raw_tracestate) % 4)) % 4 |
366 |
| - base64_tracestate = raw_tracestate + "=" * missing_equals |
367 |
| - |
368 |
| - tracestate_json = from_base64(base64_tracestate) |
369 |
| - |
370 |
| - try: |
371 |
| - assert tracestate_json is not None |
372 |
| - headers["trace"] = json.loads(tracestate_json) |
373 |
| - except Exception as err: |
374 |
| - logger.warning( |
375 |
| - "Unable to attach tracestate data to envelope header: {err}\nTracestate value is {base64_tracestate}".format( |
376 |
| - err=err, base64_tracestate=base64_tracestate |
377 |
| - ), |
378 |
| - ) |
| 354 | + tracestate_data = reinflate_tracestate(raw_tracestate) |
| 355 | + if tracestate_data: |
| 356 | + headers["trace"] = tracestate_data |
379 | 357 |
|
380 | 358 | envelope = Envelope(headers=headers)
|
381 | 359 |
|
|
0 commit comments