diff --git a/.vscode/settings.json b/.vscode/settings.json
index c167a13dc2..ba2472c4c9 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,4 +1,6 @@
{
"python.pythonPath": ".venv/bin/python",
- "python.formatting.provider": "black"
-}
\ No newline at end of file
+ "python.formatting.provider": "black",
+ "python.testing.unittestEnabled": false,
+ "python.testing.pytestEnabled": true
+}
diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py
index 6d463f3dc5..6fd61d395b 100644
--- a/sentry_sdk/consts.py
+++ b/sentry_sdk/consts.py
@@ -44,6 +44,31 @@
DEFAULT_MAX_BREADCRUMBS = 100
+class OP:
+ DB = "db"
+ DB_REDIS = "db.redis"
+ EVENT_DJANGO = "event.django"
+ FUNCTION = "function"
+ FUNCTION_AWS = "function.aws"
+ FUNCTION_GCP = "function.gcp"
+ HTTP_CLIENT = "http.client"
+ HTTP_CLIENT_STREAM = "http.client.stream"
+ HTTP_SERVER = "http.server"
+ MIDDLEWARE_DJANGO = "middleware.django"
+ MIDDLEWARE_STARLETTE = "middleware.starlette"
+ MIDDLEWARE_STARLETTE_RECEIVE = "middleware.starlette.receive"
+ MIDDLEWARE_STARLETTE_SEND = "middleware.starlette.send"
+ QUEUE_SUBMIT_CELERY = "queue.submit.celery"
+ QUEUE_TASK_CELERY = "queue.task.celery"
+ QUEUE_TASK_RQ = "queue.task.rq"
+ SUBPROCESS = "subprocess"
+ SUBPROCESS_WAIT = "subprocess.wait"
+ SUBPROCESS_COMMUNICATE = "subprocess.communicate"
+ TEMPLATE_RENDER = "template.render"
+ VIEW_RENDER = "view.render"
+ WEBSOCKET_SERVER = "websocket.server"
+
+
# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
# take these arguments (even though they take opaque **kwargs)
class ClientConstructor(object):
@@ -106,28 +131,3 @@ def _get_default_options():
VERSION = "1.11.1"
-
-
-class OP:
- DB = "db"
- DB_REDIS = "db.redis"
- EVENT_DJANGO = "event.django"
- FUNCTION = "function"
- FUNCTION_AWS = "function.aws"
- FUNCTION_GCP = "function.gcp"
- HTTP_CLIENT = "http.client"
- HTTP_CLIENT_STREAM = "http.client.stream"
- HTTP_SERVER = "http.server"
- MIDDLEWARE_DJANGO = "middleware.django"
- MIDDLEWARE_STARLETTE = "middleware.starlette"
- MIDDLEWARE_STARLETTE_RECEIVE = "middleware.starlette.receive"
- MIDDLEWARE_STARLETTE_SEND = "middleware.starlette.send"
- QUEUE_SUBMIT_CELERY = "queue.submit.celery"
- QUEUE_TASK_CELERY = "queue.task.celery"
- QUEUE_TASK_RQ = "queue.task.rq"
- SUBPROCESS = "subprocess"
- SUBPROCESS_WAIT = "subprocess.wait"
- SUBPROCESS_COMMUNICATE = "subprocess.communicate"
- TEMPLATE_RENDER = "template.render"
- VIEW_RENDER = "view.render"
- WEBSOCKET_SERVER = "websocket.server"
diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py
index 52cce0b4b4..67c87b64f6 100644
--- a/sentry_sdk/integrations/flask.py
+++ b/sentry_sdk/integrations/flask.py
@@ -6,7 +6,7 @@
from sentry_sdk.integrations._wsgi_common import RequestExtractor
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import Scope
-from sentry_sdk.tracing import SOURCE_FOR_STYLE
+from sentry_sdk.tracing import SENTRY_TRACE_HEADER_NAME, SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
event_from_exception,
@@ -101,8 +101,11 @@ def _add_sentry_trace(sender, template, context, **extra):
sentry_span = Hub.current.scope.span
context["sentry_trace"] = (
Markup(
- ''
- % (sentry_span.to_traceparent(),)
+ ''
+ % (
+ SENTRY_TRACE_HEADER_NAME,
+ sentry_span.to_traceparent(),
+ )
)
if sentry_span
else ""
diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py
index 3b81b6c2c5..687d9dd2c1 100644
--- a/sentry_sdk/integrations/stdlib.py
+++ b/sentry_sdk/integrations/stdlib.py
@@ -187,7 +187,6 @@ def sentry_patched_popen_init(self, *a, **kw):
env = None
with hub.start_span(op=OP.SUBPROCESS, description=description) as span:
-
for k, v in hub.iter_trace_propagation_headers(span):
if env is None:
env = _init_argument(
diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py
index aacb3a5bb3..8be9028aa5 100644
--- a/sentry_sdk/tracing.py
+++ b/sentry_sdk/tracing.py
@@ -6,7 +6,6 @@
from datetime import datetime, timedelta
import sentry_sdk
-
from sentry_sdk.utils import logger
from sentry_sdk._types import MYPY
@@ -24,6 +23,9 @@
import sentry_sdk.profiler
from sentry_sdk._types import Event, SamplingContext, MeasurementUnit
+BAGGAGE_HEADER_NAME = "baggage"
+SENTRY_TRACE_HEADER_NAME = "sentry-trace"
+
# Transaction source
# see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
@@ -278,10 +280,12 @@ def continue_from_headers(
# TODO-neel move away from this kwargs stuff, it's confusing and opaque
# make more explicit
- baggage = Baggage.from_incoming_header(headers.get("baggage"))
- kwargs.update({"baggage": baggage})
+ baggage = Baggage.from_incoming_header(headers.get(BAGGAGE_HEADER_NAME))
+ kwargs.update({BAGGAGE_HEADER_NAME: baggage})
- sentrytrace_kwargs = extract_sentrytrace_data(headers.get("sentry-trace"))
+ sentrytrace_kwargs = extract_sentrytrace_data(
+ headers.get(SENTRY_TRACE_HEADER_NAME)
+ )
if sentrytrace_kwargs is not None:
kwargs.update(sentrytrace_kwargs)
@@ -308,7 +312,7 @@ def iter_headers(self):
`sentry_tracestate` value, this will cause one to be generated and
stored.
"""
- yield "sentry-trace", self.to_traceparent()
+ yield SENTRY_TRACE_HEADER_NAME, self.to_traceparent()
tracestate = self.to_tracestate() if has_tracestate_enabled(self) else None
# `tracestate` will only be `None` if there's no client or no DSN
@@ -320,7 +324,7 @@ def iter_headers(self):
if self.containing_transaction:
baggage = self.containing_transaction.get_baggage().serialize()
if baggage:
- yield "baggage", baggage
+ yield BAGGAGE_HEADER_NAME, baggage
@classmethod
def from_traceparent(
@@ -344,7 +348,9 @@ def from_traceparent(
if not traceparent:
return None
- return cls.continue_from_headers({"sentry-trace": traceparent}, **kwargs)
+ return cls.continue_from_headers(
+ {SENTRY_TRACE_HEADER_NAME: traceparent}, **kwargs
+ )
def to_traceparent(self):
# type: () -> str
@@ -653,6 +659,7 @@ def finish(self, hub=None):
# to a concrete decision.
if self.sampled is None:
logger.warning("Discarding transaction without sampling decision.")
+
return None
finished_spans = [