Skip to content

Commit e50210c

Browse files
committed
use reinflation method in client
1 parent dacf534 commit e50210c

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

sentry_sdk/client.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
from datetime import datetime
55
from itertools import islice
66
import socket
7-
import json
87

98
from sentry_sdk._compat import string_types, text_type, iteritems
109
from sentry_sdk.utils import (
1110
capture_internal_exceptions,
1211
current_stacktrace,
1312
disable_capture_event,
1413
format_timestamp,
15-
from_base64,
1614
get_type_name,
1715
get_default_release,
1816
handle_in_app,
@@ -25,6 +23,7 @@
2523
from sentry_sdk.utils import ContextVar
2624
from sentry_sdk.sessions import SessionFlusher
2725
from sentry_sdk.envelope import Envelope
26+
from sentry_sdk.tracing_utils import reinflate_tracestate
2827

2928
from sentry_sdk._types import MYPY
3029

@@ -352,30 +351,9 @@ def capture_event(
352351
"sent_at": format_timestamp(datetime.utcnow()),
353352
}
354353

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
379357

380358
envelope = Envelope(headers=headers)
381359

0 commit comments

Comments
 (0)