6
6
from datetime import datetime , timedelta
7
7
8
8
import sentry_sdk
9
-
10
9
from sentry_sdk .utils import logger
11
10
from sentry_sdk ._types import MYPY
12
11
24
23
import sentry_sdk .profiler
25
24
from sentry_sdk ._types import Event , SamplingContext , MeasurementUnit
26
25
26
+ BAGGAGE_HEADER_NAME = "baggage"
27
+ SENTRY_TRACE_HEADER_NAME = "sentry-trace"
28
+
27
29
28
30
# Transaction source
29
31
# see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
@@ -278,10 +280,12 @@ def continue_from_headers(
278
280
279
281
# TODO-neel move away from this kwargs stuff, it's confusing and opaque
280
282
# make more explicit
281
- baggage = Baggage .from_incoming_header (headers .get ("baggage" ))
282
- kwargs .update ({"baggage" : baggage })
283
+ baggage = Baggage .from_incoming_header (headers .get (BAGGAGE_HEADER_NAME ))
284
+ kwargs .update ({BAGGAGE_HEADER_NAME : baggage })
283
285
284
- sentrytrace_kwargs = extract_sentrytrace_data (headers .get ("sentry-trace" ))
286
+ sentrytrace_kwargs = extract_sentrytrace_data (
287
+ headers .get (SENTRY_TRACE_HEADER_NAME )
288
+ )
285
289
286
290
if sentrytrace_kwargs is not None :
287
291
kwargs .update (sentrytrace_kwargs )
@@ -308,7 +312,7 @@ def iter_headers(self):
308
312
`sentry_tracestate` value, this will cause one to be generated and
309
313
stored.
310
314
"""
311
- yield "sentry-trace" , self .to_traceparent ()
315
+ yield SENTRY_TRACE_HEADER_NAME , self .to_traceparent ()
312
316
313
317
tracestate = self .to_tracestate () if has_tracestate_enabled (self ) else None
314
318
# `tracestate` will only be `None` if there's no client or no DSN
@@ -320,7 +324,7 @@ def iter_headers(self):
320
324
if self .containing_transaction :
321
325
baggage = self .containing_transaction .get_baggage ().serialize ()
322
326
if baggage :
323
- yield "baggage" , baggage
327
+ yield BAGGAGE_HEADER_NAME , baggage
324
328
325
329
@classmethod
326
330
def from_traceparent (
@@ -344,7 +348,9 @@ def from_traceparent(
344
348
if not traceparent :
345
349
return None
346
350
347
- return cls .continue_from_headers ({"sentry-trace" : traceparent }, ** kwargs )
351
+ return cls .continue_from_headers (
352
+ {SENTRY_TRACE_HEADER_NAME : traceparent }, ** kwargs
353
+ )
348
354
349
355
def to_traceparent (self ):
350
356
# type: () -> str
@@ -653,6 +659,7 @@ def finish(self, hub=None):
653
659
# to a concrete decision.
654
660
if self .sampled is None :
655
661
logger .warning ("Discarding transaction without sampling decision." )
662
+
656
663
return None
657
664
658
665
finished_spans = [
0 commit comments