|
22 | 22 | if MYPY:
|
23 | 23 | import typing
|
24 | 24 |
|
25 |
| - from typing import Generator |
26 | 25 | from typing import Optional
|
27 | 26 | from typing import Any
|
28 | 27 | from typing import Dict
|
29 | 28 | from typing import List
|
30 | 29 | from typing import Tuple
|
| 30 | + from typing import Iterator |
31 | 31 |
|
32 | 32 | from sentry_sdk._types import SamplingContext
|
33 | 33 |
|
@@ -183,19 +183,19 @@ def start_child(self, **kwargs):
|
183 | 183 | """
|
184 | 184 | kwargs.setdefault("sampled", self.sampled)
|
185 | 185 |
|
186 |
| - rv = Span( |
| 186 | + child = Span( |
187 | 187 | trace_id=self.trace_id, span_id=None, parent_span_id=self.span_id, **kwargs
|
188 | 188 | )
|
189 | 189 |
|
190 | 190 | if isinstance(self, Transaction):
|
191 |
| - rv._containing_transaction = self |
| 191 | + child._containing_transaction = self |
192 | 192 | else:
|
193 |
| - rv._containing_transaction = self._containing_transaction |
| 193 | + child._containing_transaction = self._containing_transaction |
194 | 194 |
|
195 |
| - rv._span_recorder = recorder = self._span_recorder |
| 195 | + child._span_recorder = recorder = self._span_recorder |
196 | 196 | if recorder:
|
197 |
| - recorder.add(rv) |
198 |
| - return rv |
| 197 | + recorder.add(child) |
| 198 | + return child |
199 | 199 |
|
200 | 200 | def new_span(self, **kwargs):
|
201 | 201 | # type: (**Any) -> Span
|
@@ -253,9 +253,15 @@ def continue_from_headers(
|
253 | 253 | return transaction
|
254 | 254 |
|
255 | 255 | def iter_headers(self):
|
256 |
| - # type: () -> Generator[Tuple[str, str], None, None] |
| 256 | + # type: () -> Iterator[Tuple[str, str]] |
| 257 | + """ |
| 258 | + Creates a generator which returns the span's `sentry-trace` and |
| 259 | + `tracestate` headers. |
| 260 | + """ |
257 | 261 | yield "sentry-trace", self.to_traceparent()
|
| 262 | + |
258 | 263 | tracestate = self.to_tracestate()
|
| 264 | + # `tracestate` will only be `None` if there's no client or no DSN |
259 | 265 | if tracestate:
|
260 | 266 | yield "tracestate", tracestate
|
261 | 267 |
|
@@ -295,9 +301,11 @@ def to_traceparent(self):
|
295 | 301 | def to_tracestate(self):
|
296 | 302 | # type: () -> Optional[str]
|
297 | 303 | """
|
298 |
| - Generates the `tracestate` header value to attach to outgoing requests. |
| 304 | + Computes the `tracestate` header value using data from the containing |
| 305 | + transaction. |
| 306 | +
|
| 307 | + Returns None if there's no client and/or no DSN. |
299 | 308 | """
|
300 |
| - header_value = None |
301 | 309 |
|
302 | 310 | if isinstance(self, Transaction):
|
303 | 311 | transaction = self # type: Optional[Transaction]
|
|
0 commit comments