-
Notifications
You must be signed in to change notification settings - Fork 569
ref: Cleanup outgoing propagation_context logic #5215
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 all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,8 @@ | |||||
| from typing import Generator | ||||||
| from typing import Optional | ||||||
| from typing import Union | ||||||
| from typing import Iterator | ||||||
| from typing import Tuple | ||||||
|
|
||||||
| from types import FrameType | ||||||
|
|
||||||
|
|
@@ -506,7 +508,28 @@ def span_id(self, value): | |||||
| @property | ||||||
| def dynamic_sampling_context(self): | ||||||
| # type: () -> Optional[Dict[str, Any]] | ||||||
| return self.baggage.dynamic_sampling_context() if self.baggage else None | ||||||
| return self.get_baggage().dynamic_sampling_context() | ||||||
|
|
||||||
| def to_traceparent(self): | ||||||
| # type: () -> str | ||||||
| return f"{self.trace_id}-{self.span_id}" | ||||||
|
|
||||||
| def get_baggage(self): | ||||||
|
Contributor
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. Same nit as above
Suggested change
Member
Author
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. we actually don't use |
||||||
| # type: () -> Baggage | ||||||
| if self.baggage is None: | ||||||
| self.baggage = Baggage.populate_from_propagation_context(self) | ||||||
| return self.baggage | ||||||
|
|
||||||
| def iter_headers(self): | ||||||
alexander-alderman-webb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| # type: () -> Iterator[Tuple[str, str]] | ||||||
| """ | ||||||
| Creates a generator which returns the propagation_context's ``sentry-trace`` and ``baggage`` headers. | ||||||
| """ | ||||||
| yield SENTRY_TRACE_HEADER_NAME, self.to_traceparent() | ||||||
|
|
||||||
| baggage = self.get_baggage().serialize() | ||||||
| if baggage: | ||||||
| yield BAGGAGE_HEADER_NAME, baggage | ||||||
|
|
||||||
| def update(self, other_dict): | ||||||
| # type: (Dict[str, Any]) -> None | ||||||
|
|
@@ -649,21 +672,29 @@ def from_incoming_header( | |||||
| @classmethod | ||||||
| def from_options(cls, scope): | ||||||
| # type: (sentry_sdk.scope.Scope) -> Optional[Baggage] | ||||||
| """ | ||||||
| Deprecated: use populate_from_propagation_context | ||||||
| """ | ||||||
| if scope._propagation_context is None: | ||||||
| return Baggage({}) | ||||||
|
|
||||||
| return Baggage.populate_from_propagation_context(scope._propagation_context) | ||||||
|
|
||||||
| @classmethod | ||||||
| def populate_from_propagation_context(cls, propagation_context): | ||||||
| # type: (PropagationContext) -> Baggage | ||||||
| sentry_items = {} # type: Dict[str, str] | ||||||
| third_party_items = "" | ||||||
| mutable = False | ||||||
|
|
||||||
| client = sentry_sdk.get_client() | ||||||
|
|
||||||
| if not client.is_active() or scope._propagation_context is None: | ||||||
| if not client.is_active(): | ||||||
| return Baggage(sentry_items) | ||||||
|
|
||||||
| options = client.options | ||||||
| propagation_context = scope._propagation_context | ||||||
|
|
||||||
| if propagation_context is not None: | ||||||
| sentry_items["trace_id"] = propagation_context.trace_id | ||||||
| sentry_items["trace_id"] = propagation_context.trace_id | ||||||
|
|
||||||
| if options.get("environment"): | ||||||
| sentry_items["environment"] = options["environment"] | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up PR
#5217