Update Flask html meta helper (#2203) · gitcommit90/sentry-python@8051d92 · GitHub
Skip to content

Commit 8051d92

Browse files
authored
Update Flask html meta helper (getsentry#2203)
Update Flask html meta helper to use the new top level API for getting sentry-trace and baggage information.
1 parent 7113508 commit 8051d92

3 files changed

Lines changed: 28 additions & 23 deletions

File tree

sentry_sdk/hub.py

Lines changed: 4 additions & 1 deletion

sentry_sdk/integrations/flask.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sentry_sdk.integrations._wsgi_common import RequestExtractor
77
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
88
from sentry_sdk.scope import Scope
9-
from sentry_sdk.tracing import SENTRY_TRACE_HEADER_NAME, SOURCE_FOR_STYLE
9+
from sentry_sdk.tracing import SOURCE_FOR_STYLE
1010
from sentry_sdk.utils import (
1111
capture_internal_exceptions,
1212
event_from_exception,
@@ -93,22 +93,13 @@ def sentry_patched_wsgi_app(self, environ, start_response):
9393

9494
def _add_sentry_trace(sender, template, context, **extra):
9595
# type: (Flask, Any, Dict[str, Any], **Any) -> None
96-
9796
if "sentry_trace" in context:
9897
return
9998

100-
sentry_span = Hub.current.scope.span
101-
context["sentry_trace"] = (
102-
Markup(
103-
'<meta name="%s" content="%s" />'
104-
% (
105-
SENTRY_TRACE_HEADER_NAME,
106-
sentry_span.to_traceparent(),
107-
)
108-
)
109-
if sentry_span
110-
else ""
111-
)
99+
hub = Hub.current
100+
trace_meta = Markup(hub.trace_propagation_meta())
101+
context["sentry_trace"] = trace_meta # for backwards compatibility
102+
context["sentry_trace_meta"] = trace_meta
112103

113104

114105
def _set_transaction_name_and_source(scope, transaction_style, request):

tests/integrations/flask/test_flask.py

Lines changed: 19 additions & 8 deletions

0 commit comments

Comments
 (0)