Skip to content

Commit f21fc0f

Browse files
Remove deprecated tracestate (#1907)
Remove deprecated `tracestate` implementation in favor of `baggage`. --------- Co-authored-by: Neel Shah <neel.shah@sentry.io>
1 parent 9ed5e27 commit f21fc0f

File tree

8 files changed

+34
-629
lines changed

8 files changed

+34
-629
lines changed

sentry_sdk/client.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from sentry_sdk.sessions import SessionFlusher
3030
from sentry_sdk.envelope import Envelope
3131
from sentry_sdk.profiler import setup_profiler
32-
from sentry_sdk.tracing_utils import has_tracestate_enabled, reinflate_tracestate
3332

3433
from sentry_sdk._types import MYPY
3534

@@ -425,13 +424,6 @@ def capture_event(
425424

426425
attachments = hint.get("attachments")
427426

428-
# this is outside of the `if` immediately below because even if we don't
429-
# use the value, we want to make sure we remove it before the event is
430-
# sent
431-
raw_tracestate = (
432-
event_opt.get("contexts", {}).get("trace", {}).pop("tracestate", "")
433-
)
434-
435427
dynamic_sampling_context = (
436428
event_opt.get("contexts", {})
437429
.get("trace", {})
@@ -447,14 +439,7 @@ def capture_event(
447439
"sent_at": format_timestamp(datetime.utcnow()),
448440
}
449441

450-
if has_tracestate_enabled():
451-
tracestate_data = raw_tracestate and reinflate_tracestate(
452-
raw_tracestate.replace("sentry=", "")
453-
)
454-
455-
if tracestate_data:
456-
headers["trace"] = tracestate_data
457-
elif dynamic_sampling_context:
442+
if dynamic_sampling_context:
458443
headers["trace"] = dynamic_sampling_context
459444

460445
envelope = Envelope(headers=headers)

sentry_sdk/consts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"max_spans": Optional[int],
3434
"record_sql_params": Optional[bool],
3535
"smart_transaction_trimming": Optional[bool],
36-
"propagate_tracestate": Optional[bool],
3736
"custom_measurements": Optional[bool],
3837
"profiles_sample_rate": Optional[float],
3938
"profiler_mode": Optional[str],

sentry_sdk/tracing.py

Lines changed: 5 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def continue_from_environ(
251251
# type: (...) -> Transaction
252252
"""
253253
Create a Transaction with the given params, then add in data pulled from
254-
the 'sentry-trace', 'baggage' and 'tracestate' headers from the environ (if any)
254+
the 'sentry-trace' and 'baggage' headers from the environ (if any)
255255
before returning the Transaction.
256256
257257
This is different from `continue_from_headers` in that it assumes header
@@ -274,7 +274,7 @@ def continue_from_headers(
274274
# type: (...) -> Transaction
275275
"""
276276
Create a transaction with the given params (including any data pulled from
277-
the 'sentry-trace', 'baggage' and 'tracestate' headers).
277+
the 'sentry-trace' and 'baggage' headers).
278278
"""
279279
# TODO move this to the Transaction class
280280
if cls is Span:
@@ -300,8 +300,6 @@ def continue_from_headers(
300300
# baggage will be empty and immutable and won't be populated as head SDK.
301301
baggage.freeze()
302302

303-
kwargs.update(extract_tracestate_data(headers.get("tracestate")))
304-
305303
transaction = Transaction(**kwargs)
306304
transaction.same_process_as_parent = False
307305

@@ -310,22 +308,12 @@ def continue_from_headers(
310308
def iter_headers(self):
311309
# type: () -> Iterator[Tuple[str, str]]
312310
"""
313-
Creates a generator which returns the span's `sentry-trace`, `baggage` and
314-
`tracestate` headers.
315-
316-
If the span's containing transaction doesn't yet have a
317-
`sentry_tracestate` value, this will cause one to be generated and
318-
stored.
311+
Creates a generator which returns the span's `sentry-trace` and `baggage` headers.
312+
If the span's containing transaction doesn't yet have a `baggage` value,
313+
this will cause one to be generated and stored.
319314
"""
320315
yield SENTRY_TRACE_HEADER_NAME, self.to_traceparent()
321316

322-
tracestate = self.to_tracestate() if has_tracestate_enabled(self) else None
323-
# `tracestate` will only be `None` if there's no client or no DSN
324-
# TODO (kmclb) the above will be true once the feature is no longer
325-
# behind a flag
326-
if tracestate:
327-
yield "tracestate", tracestate
328-
329317
if self.containing_transaction:
330318
baggage = self.containing_transaction.get_baggage().serialize()
331319
if baggage:
@@ -366,57 +354,6 @@ def to_traceparent(self):
366354
sampled = "0"
367355
return "%s-%s-%s" % (self.trace_id, self.span_id, sampled)
368356

369-
def to_tracestate(self):
370-
# type: () -> Optional[str]
371-
"""
372-
Computes the `tracestate` header value using data from the containing
373-
transaction.
374-
375-
If the containing transaction doesn't yet have a `sentry_tracestate`
376-
value, this will cause one to be generated and stored.
377-
378-
If there is no containing transaction, a value will be generated but not
379-
stored.
380-
381-
Returns None if there's no client and/or no DSN.
382-
"""
383-
384-
sentry_tracestate = self.get_or_set_sentry_tracestate()
385-
third_party_tracestate = (
386-
self.containing_transaction._third_party_tracestate
387-
if self.containing_transaction
388-
else None
389-
)
390-
391-
if not sentry_tracestate:
392-
return None
393-
394-
header_value = sentry_tracestate
395-
396-
if third_party_tracestate:
397-
header_value = header_value + "," + third_party_tracestate
398-
399-
return header_value
400-
401-
def get_or_set_sentry_tracestate(self):
402-
# type: (Span) -> Optional[str]
403-
"""
404-
Read sentry tracestate off of the span's containing transaction.
405-
406-
If the transaction doesn't yet have a `_sentry_tracestate` value,
407-
compute one and store it.
408-
"""
409-
transaction = self.containing_transaction
410-
411-
if transaction:
412-
if not transaction._sentry_tracestate:
413-
transaction._sentry_tracestate = compute_tracestate_entry(self)
414-
415-
return transaction._sentry_tracestate
416-
417-
# orphan span - nowhere to store the value, so just return it
418-
return compute_tracestate_entry(self)
419-
420357
def set_tag(self, key, value):
421358
# type: (str, Any) -> None
422359
self._tags[key] = value
@@ -528,15 +465,6 @@ def get_trace_context(self):
528465
if self.status:
529466
rv["status"] = self.status
530467

531-
# if the transaction didn't inherit a tracestate value, and no outgoing
532-
# requests - whose need for headers would have caused a tracestate value
533-
# to be created - were made as part of the transaction, the transaction
534-
# still won't have a tracestate value, so compute one now
535-
sentry_tracestate = self.get_or_set_sentry_tracestate()
536-
537-
if sentry_tracestate:
538-
rv["tracestate"] = sentry_tracestate
539-
540468
if self.containing_transaction:
541469
rv[
542470
"dynamic_sampling_context"
@@ -552,13 +480,6 @@ class Transaction(Span):
552480
"parent_sampled",
553481
# used to create baggage value for head SDKs in dynamic sampling
554482
"sample_rate",
555-
# the sentry portion of the `tracestate` header used to transmit
556-
# correlation context for server-side dynamic sampling, of the form
557-
# `sentry=xxxxx`, where `xxxxx` is the base64-encoded json of the
558-
# correlation context data, missing trailing any =
559-
"_sentry_tracestate",
560-
# tracestate data from other vendors, of the form `dogs=yes,cats=maybe`
561-
"_third_party_tracestate",
562483
"_measurements",
563484
"_contexts",
564485
"_profile",
@@ -569,8 +490,6 @@ def __init__(
569490
self,
570491
name="", # type: str
571492
parent_sampled=None, # type: Optional[bool]
572-
sentry_tracestate=None, # type: Optional[str]
573-
third_party_tracestate=None, # type: Optional[str]
574493
baggage=None, # type: Optional[Baggage]
575494
source=TRANSACTION_SOURCE_CUSTOM, # type: str
576495
**kwargs # type: Any
@@ -592,11 +511,6 @@ def __init__(
592511
self.source = source
593512
self.sample_rate = None # type: Optional[float]
594513
self.parent_sampled = parent_sampled
595-
# if tracestate isn't inherited and set here, it will get set lazily,
596-
# either the first time an outgoing request needs it for a header or the
597-
# first time an event needs it for inclusion in the captured data
598-
self._sentry_tracestate = sentry_tracestate
599-
self._third_party_tracestate = third_party_tracestate
600514
self._measurements = {} # type: Dict[str, Any]
601515
self._contexts = {} # type: Dict[str, Any]
602516
self._profile = None # type: Optional[sentry_sdk.profiler.Profile]
@@ -901,10 +815,7 @@ def finish(self, hub=None, end_timestamp=None):
901815
from sentry_sdk.tracing_utils import (
902816
Baggage,
903817
EnvironHeaders,
904-
compute_tracestate_entry,
905818
extract_sentrytrace_data,
906-
extract_tracestate_data,
907-
has_tracestate_enabled,
908819
has_tracing_enabled,
909820
is_valid_sample_rate,
910821
maybe_create_breadcrumbs_from_span,

0 commit comments

Comments
 (0)