-
Notifications
You must be signed in to change notification settings - Fork 590
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
base: master
Are you sure you want to change the base?
Changes from all 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
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 |
|---|---|---|
|
|
@@ -583,8 +583,12 @@ | |
| client = self.get_client() | ||
|
|
||
| # If we have an active span, return traceparent from there | ||
| if has_tracing_enabled(client.options) and self.span is not None: | ||
| return self.span.to_traceparent() | ||
| if ( | ||
| has_tracing_enabled(client.options) | ||
| and self.span is not None | ||
| and not isinstance(self.span, NoOpStreamedSpan) | ||
| ): | ||
| return self.span._to_traceparent() | ||
|
|
||
| # else return traceparent from the propagation context | ||
| return self.get_active_propagation_context().to_traceparent() | ||
|
|
@@ -597,8 +601,12 @@ | |
| client = self.get_client() | ||
|
|
||
| # If we have an active span, return baggage from there | ||
| if has_tracing_enabled(client.options) and self.span is not None: | ||
| return self.span.to_baggage() | ||
| if ( | ||
| has_tracing_enabled(client.options) | ||
| and self.span is not None | ||
| and not isinstance(self.span, NoOpStreamedSpan) | ||
| ): | ||
| return self.span._to_baggage() | ||
github-actions[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # else return baggage from the propagation context | ||
| return self.get_active_propagation_context().get_baggage() | ||
|
|
@@ -607,8 +615,12 @@ | |
| """ | ||
| Returns the Sentry "trace" context from the Propagation Context. | ||
| """ | ||
| if has_tracing_enabled(self.get_client().options) and self._span is not None: | ||
| return self._span.get_trace_context() | ||
| if ( | ||
| has_tracing_enabled(self.get_client().options) | ||
| and self._span is not None | ||
| and not isinstance(self.span, NoOpStreamedSpan) | ||
| ): | ||
| return self._span._get_trace_context() | ||
|
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. Inconsistent self._span vs self.span in conditionLow Severity In |
||
|
|
||
| # if we are tracing externally (otel), those values take precedence | ||
| external_propagation_context = get_external_propagation_context() | ||
|
|
@@ -673,7 +685,7 @@ | |
| span = span or self.span | ||
|
|
||
| if has_tracing_enabled(client.options) and span is not None: | ||
| for header in span.iter_headers(): | ||
| for header in span._iter_headers(): | ||
|
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. Missing NoOpStreamedSpan guard in iter_trace_propagation_headersHigh Severity
Additional Locations (1) |
||
| yield header | ||
| elif has_external_propagation_context(): | ||
| # when we have an external_propagation_context (otlp) | ||
|
|
@@ -720,7 +732,7 @@ | |
| self.clear_breadcrumbs() | ||
| self._should_capture: bool = True | ||
|
|
||
| self._span: "Optional[Span]" = None | ||
| self._span: "Optional[Union[Span, StreamedSpan]]" = None | ||
| self._session: "Optional[Session]" = None | ||
| self._force_auto_session_tracking: "Optional[bool]" = None | ||
|
|
||
|
|
@@ -774,6 +786,14 @@ | |
| if self._span is None: | ||
| return None | ||
|
|
||
| if isinstance(self._span, StreamedSpan): | ||
| warnings.warn( | ||
| "Scope.transaction is not available in streaming mode.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return None | ||
|
|
||
| # there is an orphan span on the scope | ||
| if self._span.containing_transaction is None: | ||
| return None | ||
|
|
@@ -803,17 +823,36 @@ | |
| "Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead." | ||
| ) | ||
| self._transaction = value | ||
| if self._span and self._span.containing_transaction: | ||
| self._span.containing_transaction.name = value | ||
| if self._span: | ||
| if isinstance(self._span, StreamedSpan): | ||
| warnings.warn( | ||
| "Scope.transaction is not available in streaming mode.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return None | ||
|
|
||
| if self._span.containing_transaction: | ||
| self._span.containing_transaction.name = value | ||
sentry-warden[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def set_transaction_name(self, name: str, source: "Optional[str]" = None) -> None: | ||
| """Set the transaction name and optionally the transaction source.""" | ||
| self._transaction = name | ||
|
|
||
| if self._span and self._span.containing_transaction: | ||
| self._span.containing_transaction.name = name | ||
| if source: | ||
| self._span.containing_transaction.source = source | ||
| if self._span: | ||
| if isinstance(self._span, NoOpStreamedSpan): | ||
| return | ||
|
Check warning on line 843 in sentry_sdk/scope.py
|
||
github-actions[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| elif isinstance(self._span, StreamedSpan): | ||
| self._span._segment.name = name | ||
| if source: | ||
| self._span._segment.set_attribute( | ||
| "sentry.span.source", getattr(source, "value", source) | ||
| ) | ||
|
|
||
| elif self._span.containing_transaction: | ||
| self._span.containing_transaction.name = name | ||
| if source: | ||
| self._span.containing_transaction.source = source | ||
|
|
||
| if source: | ||
| self._transaction_info["source"] = source | ||
|
|
@@ -836,12 +875,12 @@ | |
| session.update(user=value) | ||
|
|
||
| @property | ||
| def span(self) -> "Optional[Span]": | ||
| def span(self) -> "Optional[Union[Span, StreamedSpan]]": | ||
| """Get/set current tracing span or transaction.""" | ||
| return self._span | ||
|
|
||
| @span.setter | ||
| def span(self, span: "Optional[Span]") -> None: | ||
| def span(self, span: "Optional[Union[Span, StreamedSpan]]") -> None: | ||
| self._span = span | ||
| # XXX: this differs from the implementation in JS, there Scope.setSpan | ||
| # does not set Scope._transactionName. | ||
|
|
@@ -1150,6 +1189,15 @@ | |
| be removed in the next major version. Going forward, it should only | ||
| be used by the SDK itself. | ||
| """ | ||
| client = sentry_sdk.get_client() | ||
| if has_span_streaming_enabled(client.options): | ||
| warnings.warn( | ||
| "Scope.start_span is not available in streaming mode.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return NoOpSpan() | ||
|
|
||
| if kwargs.get("description") is not None: | ||
| warnings.warn( | ||
| "The `description` parameter is deprecated. Please use `name` instead.", | ||
|
|
@@ -1169,6 +1217,9 @@ | |
|
|
||
| # get current span or transaction | ||
| span = self.span or self.get_isolation_scope().span | ||
| if isinstance(span, StreamedSpan): | ||
| # make mypy happy | ||
| return NoOpSpan() | ||
|
|
||
| if span is None: | ||
| # New spans get the `trace_id` from the scope | ||
|
|
||


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