-
Notifications
You must be signed in to change notification settings - Fork 608
ref: Support outgoing trace propagation in span first (18) #5638
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
Changes from 118 commits
946decc
f3ee55c
47ed910
5023c76
6445447
47e6211
1e7b694
80bfe5a
1f0ffc1
d773428
647fa79
49bdbe6
cdd8bd6
54f81af
941863e
4b14e8d
474f8e6
9996e29
e20d4fd
f2738ff
7874a54
63a9396
c974d3e
5d8c238
831adae
656ef2e
1dcf176
0a7eae8
6888c56
09e5cce
ae2fd52
f223574
05a4157
9e8e60e
777a246
9b1e2f3
e589c53
1487ea8
1006e7b
6c16dbf
cb37a07
ad6e7cc
ba29f0c
d6a42b2
5e20ad3
c70fae4
b995770
0235053
60217e1
b673a09
d6fa965
3602f86
9f59eb0
bd8e1c9
9b3df81
8614d52
cdee8bc
72f0968
dab1970
7daa720
b59f3cd
2f0dc01
dc81637
bc9f765
45372c1
c5fcb3e
51342fb
336b643
aba1b50
1e22ed0
8a77d5b
09b88f0
2ac24d3
a9b33a9
4ba4351
ed09e81
6ecad5c
12d7ff7
8e3de76
2448092
5d8c5f3
73e33ea
bd9e0a3
918609c
e850994
f816c0a
989447d
c614249
fd78adf
cb75f15
f178dea
d1618c4
c640251
7403dd2
493706e
8f04a74
a834583
7a5c168
bf62edc
0eca88b
5286dd0
e175733
84cbbd7
fea3b9b
5f26797
cc772a0
52cd46d
a656540
9ef960f
493e0fd
d64b0ee
d472364
c828afb
eaa93b3
98abb6a
e6f207d
4f75492
f2291ac
9458911
59b18de
6663470
7849c2d
658cfad
0466a91
a5f0069
1757fdb
7ada1f3
5175324
acc7126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,13 +26,17 @@ | |
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Any, Callable, Optional, ParamSpec, TypeVar, Union | ||
| from typing import Any, Callable, Iterator, Optional, ParamSpec, TypeVar, Union | ||
| from sentry_sdk._types import Attributes, AttributeValue | ||
|
|
||
| P = ParamSpec("P") | ||
| R = TypeVar("R") | ||
|
|
||
|
|
||
| BAGGAGE_HEADER_NAME = "baggage" | ||
| SENTRY_TRACE_HEADER_NAME = "sentry-trace" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate header name constants across
|
||
|
|
||
|
|
||
| class SpanStatus(str, Enum): | ||
| OK = "ok" | ||
| ERROR = "error" | ||
|
|
@@ -328,7 +332,7 @@ def finish(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> No | |
| def _start(self) -> None: | ||
| if self._active: | ||
| old_span = self._scope.span | ||
| self._scope.span = self # type: ignore | ||
| self._scope.span = self | ||
| self._previous_span_on_scope = old_span | ||
|
|
||
| def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None: | ||
|
|
@@ -463,6 +467,67 @@ def _update_active_thread(self) -> None: | |
| if thread_name is not None: | ||
| self.set_attribute(SPANDATA.THREAD_NAME, thread_name) | ||
|
|
||
| def _dynamic_sampling_context(self) -> "dict[str, str]": | ||
| return self._segment._get_baggage().dynamic_sampling_context() | ||
|
|
||
| def _to_traceparent(self) -> str: | ||
| if self.sampled is True: | ||
| sampled = "1" | ||
| elif self.sampled is False: | ||
| sampled = "0" | ||
| else: | ||
| sampled = None | ||
|
|
||
| traceparent = "%s-%s" % (self.trace_id, self.span_id) | ||
| if sampled is not None: | ||
| traceparent += "-%s" % (sampled,) | ||
|
|
||
| return traceparent | ||
|
|
||
| def _to_baggage(self) -> "Optional[Baggage]": | ||
| if self._segment: | ||
| return self._segment._get_baggage() | ||
| return None | ||
|
|
||
| def _get_baggage(self) -> "Baggage": | ||
| """ | ||
| Return the :py:class:`~sentry_sdk.tracing_utils.Baggage` associated with | ||
| the segment. | ||
|
|
||
| The first time a new baggage with Sentry items is made, it will be frozen. | ||
| """ | ||
| if not self._baggage or self._baggage.mutable: | ||
| self._baggage = Baggage.populate_from_segment(self) | ||
|
|
||
| return self._baggage | ||
|
|
||
| def _iter_headers(self) -> "Iterator[tuple[str, str]]": | ||
| if not self._segment: | ||
| return | ||
|
github-actions[bot] marked this conversation as resolved.
sentrivana marked this conversation as resolved.
|
||
|
|
||
| yield SENTRY_TRACE_HEADER_NAME, self._to_traceparent() | ||
|
|
||
| baggage = self._segment._get_baggage().serialize() | ||
| if baggage: | ||
| yield BAGGAGE_HEADER_NAME, baggage | ||
|
|
||
| def _get_trace_context(self) -> "dict[str, Any]": | ||
| # Even if spans themselves are not event-based anymore, we need this | ||
| # to populate trace context on events | ||
| context: "dict[str, Any]" = { | ||
| "trace_id": self.trace_id, | ||
| "span_id": self.span_id, | ||
| "parent_span_id": self._parent_span_id, | ||
| "dynamic_sampling_context": self._dynamic_sampling_context(), | ||
| } | ||
|
|
||
| if "sentry.op" in self._attributes: | ||
| context["op"] = self._attributes["sentry.op"] | ||
| if "sentry.origin" in self._attributes: | ||
| context["origin"] = self._attributes["sentry.origin"] | ||
|
|
||
| return context | ||
|
|
||
|
|
||
| class NoOpStreamedSpan(StreamedSpan): | ||
| __slots__ = ( | ||
|
|
@@ -498,7 +563,7 @@ def _start(self) -> None: | |
| return | ||
|
|
||
| old_span = self._scope.span | ||
| self._scope.span = self # type: ignore | ||
| self._scope.span = self | ||
| self._previous_span_on_scope = old_span | ||
|
|
||
| def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None: | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.