Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated tracestate #1907

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from sentry_sdk.sessions import SessionFlusher
from sentry_sdk.envelope import Envelope
from sentry_sdk.profiler import setup_profiler
from sentry_sdk.tracing_utils import has_tracestate_enabled, reinflate_tracestate

from sentry_sdk._types import MYPY

Expand Down Expand Up @@ -425,13 +424,6 @@ def capture_event(

attachments = hint.get("attachments")

# this is outside of the `if` immediately below because even if we don't
# use the value, we want to make sure we remove it before the event is
# sent
raw_tracestate = (
event_opt.get("contexts", {}).get("trace", {}).pop("tracestate", "")
)

dynamic_sampling_context = (
event_opt.get("contexts", {})
.get("trace", {})
Expand All @@ -447,14 +439,7 @@ def capture_event(
"sent_at": format_timestamp(datetime.utcnow()),
}

if has_tracestate_enabled():
tracestate_data = raw_tracestate and reinflate_tracestate(
raw_tracestate.replace("sentry=", "")
)

if tracestate_data:
headers["trace"] = tracestate_data
elif dynamic_sampling_context:
if dynamic_sampling_context:
headers["trace"] = dynamic_sampling_context

envelope = Envelope(headers=headers)
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"max_spans": Optional[int],
"record_sql_params": Optional[bool],
"smart_transaction_trimming": Optional[bool],
"propagate_tracestate": Optional[bool],
"custom_measurements": Optional[bool],
"profiles_sample_rate": Optional[float],
"profiler_mode": Optional[str],
Expand Down
99 changes: 5 additions & 94 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def continue_from_environ(
# type: (...) -> Transaction
"""
Create a Transaction with the given params, then add in data pulled from
the 'sentry-trace', 'baggage' and 'tracestate' headers from the environ (if any)
the 'sentry-trace' and 'baggage' headers from the environ (if any)
before returning the Transaction.

This is different from `continue_from_headers` in that it assumes header
Expand All @@ -274,7 +274,7 @@ def continue_from_headers(
# type: (...) -> Transaction
"""
Create a transaction with the given params (including any data pulled from
the 'sentry-trace', 'baggage' and 'tracestate' headers).
the 'sentry-trace' and 'baggage' headers).
"""
# TODO move this to the Transaction class
if cls is Span:
Expand All @@ -300,8 +300,6 @@ def continue_from_headers(
# baggage will be empty and immutable and won't be populated as head SDK.
baggage.freeze()

kwargs.update(extract_tracestate_data(headers.get("tracestate")))

transaction = Transaction(**kwargs)
transaction.same_process_as_parent = False

Expand All @@ -310,22 +308,12 @@ def continue_from_headers(
def iter_headers(self):
# type: () -> Iterator[Tuple[str, str]]
"""
Creates a generator which returns the span's `sentry-trace`, `baggage` and
`tracestate` headers.

If the span's containing transaction doesn't yet have a
`sentry_tracestate` value, this will cause one to be generated and
stored.
Creates a generator which returns the span's `sentry-trace` and `baggage` headers.
If the span's containing transaction doesn't yet have a `baggage` value,
this will cause one to be generated and stored.
"""
yield SENTRY_TRACE_HEADER_NAME, self.to_traceparent()

tracestate = self.to_tracestate() if has_tracestate_enabled(self) else None
# `tracestate` will only be `None` if there's no client or no DSN
# TODO (kmclb) the above will be true once the feature is no longer
# behind a flag
if tracestate:
yield "tracestate", tracestate

if self.containing_transaction:
baggage = self.containing_transaction.get_baggage().serialize()
if baggage:
Expand Down Expand Up @@ -366,57 +354,6 @@ def to_traceparent(self):
sampled = "0"
return "%s-%s-%s" % (self.trace_id, self.span_id, sampled)

def to_tracestate(self):
# type: () -> Optional[str]
"""
Computes the `tracestate` header value using data from the containing
transaction.

If the containing transaction doesn't yet have a `sentry_tracestate`
value, this will cause one to be generated and stored.

If there is no containing transaction, a value will be generated but not
stored.

Returns None if there's no client and/or no DSN.
"""

sentry_tracestate = self.get_or_set_sentry_tracestate()
third_party_tracestate = (
self.containing_transaction._third_party_tracestate
if self.containing_transaction
else None
)

if not sentry_tracestate:
return None

header_value = sentry_tracestate

if third_party_tracestate:
header_value = header_value + "," + third_party_tracestate

return header_value

def get_or_set_sentry_tracestate(self):
# type: (Span) -> Optional[str]
"""
Read sentry tracestate off of the span's containing transaction.

If the transaction doesn't yet have a `_sentry_tracestate` value,
compute one and store it.
"""
transaction = self.containing_transaction

if transaction:
if not transaction._sentry_tracestate:
transaction._sentry_tracestate = compute_tracestate_entry(self)

return transaction._sentry_tracestate

# orphan span - nowhere to store the value, so just return it
return compute_tracestate_entry(self)

def set_tag(self, key, value):
# type: (str, Any) -> None
self._tags[key] = value
Expand Down Expand Up @@ -528,15 +465,6 @@ def get_trace_context(self):
if self.status:
rv["status"] = self.status

# if the transaction didn't inherit a tracestate value, and no outgoing
# requests - whose need for headers would have caused a tracestate value
# to be created - were made as part of the transaction, the transaction
# still won't have a tracestate value, so compute one now
sentry_tracestate = self.get_or_set_sentry_tracestate()

if sentry_tracestate:
rv["tracestate"] = sentry_tracestate

if self.containing_transaction:
rv[
"dynamic_sampling_context"
Expand All @@ -552,13 +480,6 @@ class Transaction(Span):
"parent_sampled",
# used to create baggage value for head SDKs in dynamic sampling
"sample_rate",
# the sentry portion of the `tracestate` header used to transmit
# correlation context for server-side dynamic sampling, of the form
# `sentry=xxxxx`, where `xxxxx` is the base64-encoded json of the
# correlation context data, missing trailing any =
"_sentry_tracestate",
# tracestate data from other vendors, of the form `dogs=yes,cats=maybe`
"_third_party_tracestate",
"_measurements",
"_contexts",
"_profile",
Expand All @@ -569,8 +490,6 @@ def __init__(
self,
name="", # type: str
parent_sampled=None, # type: Optional[bool]
sentry_tracestate=None, # type: Optional[str]
third_party_tracestate=None, # type: Optional[str]
baggage=None, # type: Optional[Baggage]
source=TRANSACTION_SOURCE_CUSTOM, # type: str
**kwargs # type: Any
Expand All @@ -592,11 +511,6 @@ def __init__(
self.source = source
self.sample_rate = None # type: Optional[float]
self.parent_sampled = parent_sampled
# if tracestate isn't inherited and set here, it will get set lazily,
# either the first time an outgoing request needs it for a header or the
# first time an event needs it for inclusion in the captured data
self._sentry_tracestate = sentry_tracestate
self._third_party_tracestate = third_party_tracestate
self._measurements = {} # type: Dict[str, Any]
self._contexts = {} # type: Dict[str, Any]
self._profile = None # type: Optional[sentry_sdk.profiler.Profile]
Expand Down Expand Up @@ -901,10 +815,7 @@ def finish(self, hub=None, end_timestamp=None):
from sentry_sdk.tracing_utils import (
Baggage,
EnvironHeaders,
compute_tracestate_entry,
extract_sentrytrace_data,
extract_tracestate_data,
has_tracestate_enabled,
has_tracing_enabled,
is_valid_sample_rate,
maybe_create_breadcrumbs_from_span,
Expand Down
Loading