sentry-sdk 0.7.5__py2.py3-none-any.whl → 2.46.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sentry_sdk/__init__.py +48 -30
- sentry_sdk/_compat.py +74 -61
- sentry_sdk/_init_implementation.py +84 -0
- sentry_sdk/_log_batcher.py +172 -0
- sentry_sdk/_lru_cache.py +47 -0
- sentry_sdk/_metrics_batcher.py +167 -0
- sentry_sdk/_queue.py +289 -0
- sentry_sdk/_types.py +338 -0
- sentry_sdk/_werkzeug.py +98 -0
- sentry_sdk/ai/__init__.py +7 -0
- sentry_sdk/ai/monitoring.py +137 -0
- sentry_sdk/ai/utils.py +144 -0
- sentry_sdk/api.py +496 -80
- sentry_sdk/attachments.py +75 -0
- sentry_sdk/client.py +1023 -103
- sentry_sdk/consts.py +1438 -66
- sentry_sdk/crons/__init__.py +10 -0
- sentry_sdk/crons/api.py +62 -0
- sentry_sdk/crons/consts.py +4 -0
- sentry_sdk/crons/decorator.py +135 -0
- sentry_sdk/debug.py +15 -14
- sentry_sdk/envelope.py +369 -0
- sentry_sdk/feature_flags.py +71 -0
- sentry_sdk/hub.py +611 -280
- sentry_sdk/integrations/__init__.py +276 -49
- sentry_sdk/integrations/_asgi_common.py +108 -0
- sentry_sdk/integrations/_wsgi_common.py +180 -44
- sentry_sdk/integrations/aiohttp.py +291 -42
- sentry_sdk/integrations/anthropic.py +439 -0
- sentry_sdk/integrations/argv.py +9 -8
- sentry_sdk/integrations/ariadne.py +161 -0
- sentry_sdk/integrations/arq.py +247 -0
- sentry_sdk/integrations/asgi.py +341 -0
- sentry_sdk/integrations/asyncio.py +144 -0
- sentry_sdk/integrations/asyncpg.py +208 -0
- sentry_sdk/integrations/atexit.py +17 -10
- sentry_sdk/integrations/aws_lambda.py +377 -62
- sentry_sdk/integrations/beam.py +176 -0
- sentry_sdk/integrations/boto3.py +137 -0
- sentry_sdk/integrations/bottle.py +221 -0
- sentry_sdk/integrations/celery/__init__.py +529 -0
- sentry_sdk/integrations/celery/beat.py +293 -0
- sentry_sdk/integrations/celery/utils.py +43 -0
- sentry_sdk/integrations/chalice.py +134 -0
- sentry_sdk/integrations/clickhouse_driver.py +177 -0
- sentry_sdk/integrations/cloud_resource_context.py +280 -0
- sentry_sdk/integrations/cohere.py +274 -0
- sentry_sdk/integrations/dedupe.py +48 -14
- sentry_sdk/integrations/django/__init__.py +584 -191
- sentry_sdk/integrations/django/asgi.py +245 -0
- sentry_sdk/integrations/django/caching.py +204 -0
- sentry_sdk/integrations/django/middleware.py +187 -0
- sentry_sdk/integrations/django/signals_handlers.py +91 -0
- sentry_sdk/integrations/django/templates.py +79 -5
- sentry_sdk/integrations/django/transactions.py +49 -22
- sentry_sdk/integrations/django/views.py +96 -0
- sentry_sdk/integrations/dramatiq.py +226 -0
- sentry_sdk/integrations/excepthook.py +50 -13
- sentry_sdk/integrations/executing.py +67 -0
- sentry_sdk/integrations/falcon.py +272 -0
- sentry_sdk/integrations/fastapi.py +141 -0
- sentry_sdk/integrations/flask.py +142 -88
- sentry_sdk/integrations/gcp.py +239 -0
- sentry_sdk/integrations/gnu_backtrace.py +99 -0
- sentry_sdk/integrations/google_genai/__init__.py +301 -0
- sentry_sdk/integrations/google_genai/consts.py +16 -0
- sentry_sdk/integrations/google_genai/streaming.py +155 -0
- sentry_sdk/integrations/google_genai/utils.py +576 -0
- sentry_sdk/integrations/gql.py +162 -0
- sentry_sdk/integrations/graphene.py +151 -0
- sentry_sdk/integrations/grpc/__init__.py +168 -0
- sentry_sdk/integrations/grpc/aio/__init__.py +7 -0
- sentry_sdk/integrations/grpc/aio/client.py +95 -0
- sentry_sdk/integrations/grpc/aio/server.py +100 -0
- sentry_sdk/integrations/grpc/client.py +91 -0
- sentry_sdk/integrations/grpc/consts.py +1 -0
- sentry_sdk/integrations/grpc/server.py +66 -0
- sentry_sdk/integrations/httpx.py +178 -0
- sentry_sdk/integrations/huey.py +174 -0
- sentry_sdk/integrations/huggingface_hub.py +378 -0
- sentry_sdk/integrations/langchain.py +1132 -0
- sentry_sdk/integrations/langgraph.py +337 -0
- sentry_sdk/integrations/launchdarkly.py +61 -0
- sentry_sdk/integrations/litellm.py +287 -0
- sentry_sdk/integrations/litestar.py +315 -0
- sentry_sdk/integrations/logging.py +307 -96
- sentry_sdk/integrations/loguru.py +213 -0
- sentry_sdk/integrations/mcp.py +566 -0
- sentry_sdk/integrations/modules.py +14 -31
- sentry_sdk/integrations/openai.py +725 -0
- sentry_sdk/integrations/openai_agents/__init__.py +61 -0
- sentry_sdk/integrations/openai_agents/consts.py +1 -0
- sentry_sdk/integrations/openai_agents/patches/__init__.py +5 -0
- sentry_sdk/integrations/openai_agents/patches/agent_run.py +140 -0
- sentry_sdk/integrations/openai_agents/patches/error_tracing.py +77 -0
- sentry_sdk/integrations/openai_agents/patches/models.py +50 -0
- sentry_sdk/integrations/openai_agents/patches/runner.py +45 -0
- sentry_sdk/integrations/openai_agents/patches/tools.py +77 -0
- sentry_sdk/integrations/openai_agents/spans/__init__.py +5 -0
- sentry_sdk/integrations/openai_agents/spans/agent_workflow.py +21 -0
- sentry_sdk/integrations/openai_agents/spans/ai_client.py +42 -0
- sentry_sdk/integrations/openai_agents/spans/execute_tool.py +48 -0
- sentry_sdk/integrations/openai_agents/spans/handoff.py +19 -0
- sentry_sdk/integrations/openai_agents/spans/invoke_agent.py +86 -0
- sentry_sdk/integrations/openai_agents/utils.py +199 -0
- sentry_sdk/integrations/openfeature.py +35 -0
- sentry_sdk/integrations/opentelemetry/__init__.py +7 -0
- sentry_sdk/integrations/opentelemetry/consts.py +5 -0
- sentry_sdk/integrations/opentelemetry/integration.py +58 -0
- sentry_sdk/integrations/opentelemetry/propagator.py +117 -0
- sentry_sdk/integrations/opentelemetry/span_processor.py +391 -0
- sentry_sdk/integrations/otlp.py +82 -0
- sentry_sdk/integrations/pure_eval.py +141 -0
- sentry_sdk/integrations/pydantic_ai/__init__.py +47 -0
- sentry_sdk/integrations/pydantic_ai/consts.py +1 -0
- sentry_sdk/integrations/pydantic_ai/patches/__init__.py +4 -0
- sentry_sdk/integrations/pydantic_ai/patches/agent_run.py +215 -0
- sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py +110 -0
- sentry_sdk/integrations/pydantic_ai/patches/model_request.py +40 -0
- sentry_sdk/integrations/pydantic_ai/patches/tools.py +98 -0
- sentry_sdk/integrations/pydantic_ai/spans/__init__.py +3 -0
- sentry_sdk/integrations/pydantic_ai/spans/ai_client.py +246 -0
- sentry_sdk/integrations/pydantic_ai/spans/execute_tool.py +49 -0
- sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py +112 -0
- sentry_sdk/integrations/pydantic_ai/utils.py +223 -0
- sentry_sdk/integrations/pymongo.py +214 -0
- sentry_sdk/integrations/pyramid.py +112 -68
- sentry_sdk/integrations/quart.py +237 -0
- sentry_sdk/integrations/ray.py +165 -0
- sentry_sdk/integrations/redis/__init__.py +48 -0
- sentry_sdk/integrations/redis/_async_common.py +116 -0
- sentry_sdk/integrations/redis/_sync_common.py +119 -0
- sentry_sdk/integrations/redis/consts.py +19 -0
- sentry_sdk/integrations/redis/modules/__init__.py +0 -0
- sentry_sdk/integrations/redis/modules/caches.py +118 -0
- sentry_sdk/integrations/redis/modules/queries.py +65 -0
- sentry_sdk/integrations/redis/rb.py +32 -0
- sentry_sdk/integrations/redis/redis.py +69 -0
- sentry_sdk/integrations/redis/redis_cluster.py +107 -0
- sentry_sdk/integrations/redis/redis_py_cluster_legacy.py +50 -0
- sentry_sdk/integrations/redis/utils.py +148 -0
- sentry_sdk/integrations/rq.py +95 -37
- sentry_sdk/integrations/rust_tracing.py +284 -0
- sentry_sdk/integrations/sanic.py +294 -123
- sentry_sdk/integrations/serverless.py +48 -19
- sentry_sdk/integrations/socket.py +96 -0
- sentry_sdk/integrations/spark/__init__.py +4 -0
- sentry_sdk/integrations/spark/spark_driver.py +316 -0
- sentry_sdk/integrations/spark/spark_worker.py +116 -0
- sentry_sdk/integrations/sqlalchemy.py +142 -0
- sentry_sdk/integrations/starlette.py +737 -0
- sentry_sdk/integrations/starlite.py +292 -0
- sentry_sdk/integrations/statsig.py +37 -0
- sentry_sdk/integrations/stdlib.py +235 -29
- sentry_sdk/integrations/strawberry.py +394 -0
- sentry_sdk/integrations/sys_exit.py +70 -0
- sentry_sdk/integrations/threading.py +158 -28
- sentry_sdk/integrations/tornado.py +84 -52
- sentry_sdk/integrations/trytond.py +50 -0
- sentry_sdk/integrations/typer.py +60 -0
- sentry_sdk/integrations/unleash.py +33 -0
- sentry_sdk/integrations/unraisablehook.py +53 -0
- sentry_sdk/integrations/wsgi.py +201 -119
- sentry_sdk/logger.py +96 -0
- sentry_sdk/metrics.py +81 -0
- sentry_sdk/monitor.py +120 -0
- sentry_sdk/profiler/__init__.py +49 -0
- sentry_sdk/profiler/continuous_profiler.py +730 -0
- sentry_sdk/profiler/transaction_profiler.py +839 -0
- sentry_sdk/profiler/utils.py +195 -0
- sentry_sdk/py.typed +0 -0
- sentry_sdk/scope.py +1713 -85
- sentry_sdk/scrubber.py +177 -0
- sentry_sdk/serializer.py +405 -0
- sentry_sdk/session.py +177 -0
- sentry_sdk/sessions.py +275 -0
- sentry_sdk/spotlight.py +242 -0
- sentry_sdk/tracing.py +1486 -0
- sentry_sdk/tracing_utils.py +1236 -0
- sentry_sdk/transport.py +806 -134
- sentry_sdk/types.py +52 -0
- sentry_sdk/utils.py +1625 -465
- sentry_sdk/worker.py +54 -25
- sentry_sdk-2.46.0.dist-info/METADATA +268 -0
- sentry_sdk-2.46.0.dist-info/RECORD +189 -0
- {sentry_sdk-0.7.5.dist-info → sentry_sdk-2.46.0.dist-info}/WHEEL +1 -1
- sentry_sdk-2.46.0.dist-info/entry_points.txt +2 -0
- sentry_sdk-2.46.0.dist-info/licenses/LICENSE +21 -0
- sentry_sdk/integrations/celery.py +0 -119
- sentry_sdk-0.7.5.dist-info/LICENSE +0 -9
- sentry_sdk-0.7.5.dist-info/METADATA +0 -36
- sentry_sdk-0.7.5.dist-info/RECORD +0 -39
- {sentry_sdk-0.7.5.dist-info → sentry_sdk-2.46.0.dist-info}/top_level.txt +0 -0
sentry_sdk/hub.py
CHANGED
|
@@ -1,151 +1,125 @@
|
|
|
1
|
-
import
|
|
2
|
-
import copy
|
|
3
|
-
import weakref
|
|
4
|
-
from datetime import datetime
|
|
1
|
+
import warnings
|
|
5
2
|
from contextlib import contextmanager
|
|
6
|
-
from warnings import warn
|
|
7
3
|
|
|
4
|
+
from sentry_sdk import (
|
|
5
|
+
get_client,
|
|
6
|
+
get_global_scope,
|
|
7
|
+
get_isolation_scope,
|
|
8
|
+
get_current_scope,
|
|
9
|
+
)
|
|
8
10
|
from sentry_sdk._compat import with_metaclass
|
|
9
|
-
from sentry_sdk.
|
|
11
|
+
from sentry_sdk.consts import INSTRUMENTER
|
|
12
|
+
from sentry_sdk.scope import _ScopeManager
|
|
10
13
|
from sentry_sdk.client import Client
|
|
14
|
+
from sentry_sdk.tracing import (
|
|
15
|
+
NoOpSpan,
|
|
16
|
+
Span,
|
|
17
|
+
Transaction,
|
|
18
|
+
)
|
|
19
|
+
|
|
11
20
|
from sentry_sdk.utils import (
|
|
12
|
-
exc_info_from_error,
|
|
13
|
-
event_from_exception,
|
|
14
21
|
logger,
|
|
15
22
|
ContextVar,
|
|
16
23
|
)
|
|
17
24
|
|
|
25
|
+
from typing import TYPE_CHECKING
|
|
18
26
|
|
|
19
|
-
if
|
|
20
|
-
from typing import Union
|
|
27
|
+
if TYPE_CHECKING:
|
|
21
28
|
from typing import Any
|
|
22
|
-
from typing import
|
|
29
|
+
from typing import Callable
|
|
30
|
+
from typing import ContextManager
|
|
23
31
|
from typing import Dict
|
|
24
|
-
from typing import
|
|
32
|
+
from typing import Generator
|
|
25
33
|
from typing import List
|
|
26
|
-
from typing import
|
|
34
|
+
from typing import Optional
|
|
27
35
|
from typing import overload
|
|
28
|
-
from
|
|
36
|
+
from typing import Tuple
|
|
37
|
+
from typing import Type
|
|
38
|
+
from typing import TypeVar
|
|
39
|
+
from typing import Union
|
|
40
|
+
|
|
41
|
+
from typing_extensions import Unpack
|
|
42
|
+
|
|
43
|
+
from sentry_sdk.scope import Scope
|
|
44
|
+
from sentry_sdk.client import BaseClient
|
|
29
45
|
from sentry_sdk.integrations import Integration
|
|
46
|
+
from sentry_sdk._types import (
|
|
47
|
+
Event,
|
|
48
|
+
Hint,
|
|
49
|
+
Breadcrumb,
|
|
50
|
+
BreadcrumbHint,
|
|
51
|
+
ExcInfo,
|
|
52
|
+
LogLevelStr,
|
|
53
|
+
SamplingContext,
|
|
54
|
+
)
|
|
55
|
+
from sentry_sdk.tracing import TransactionKwargs
|
|
56
|
+
|
|
57
|
+
T = TypeVar("T")
|
|
58
|
+
|
|
30
59
|
else:
|
|
31
60
|
|
|
32
61
|
def overload(x):
|
|
62
|
+
# type: (T) -> T
|
|
33
63
|
return x
|
|
34
64
|
|
|
35
65
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _should_send_default_pii():
|
|
41
|
-
# type: () -> bool
|
|
42
|
-
client = Hub.current.client
|
|
43
|
-
if not client:
|
|
44
|
-
return False
|
|
45
|
-
return client.options["send_default_pii"]
|
|
46
|
-
|
|
66
|
+
class SentryHubDeprecationWarning(DeprecationWarning):
|
|
67
|
+
"""
|
|
68
|
+
A custom deprecation warning to inform users that the Hub is deprecated.
|
|
69
|
+
"""
|
|
47
70
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
_MESSAGE = (
|
|
72
|
+
"`sentry_sdk.Hub` is deprecated and will be removed in a future major release. "
|
|
73
|
+
"Please consult our 1.x to 2.x migration guide for details on how to migrate "
|
|
74
|
+
"`Hub` usage to the new API: "
|
|
75
|
+
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x"
|
|
76
|
+
)
|
|
51
77
|
|
|
52
|
-
def
|
|
53
|
-
|
|
78
|
+
def __init__(self, *_):
|
|
79
|
+
# type: (*object) -> None
|
|
80
|
+
super().__init__(self._MESSAGE)
|
|
54
81
|
|
|
55
|
-
def __exit__(self, exc_type, exc_value, tb):
|
|
56
|
-
c = self._client
|
|
57
|
-
if c is not None:
|
|
58
|
-
c.close()
|
|
59
82
|
|
|
83
|
+
@contextmanager
|
|
84
|
+
def _suppress_hub_deprecation_warning():
|
|
85
|
+
# type: () -> Generator[None, None, None]
|
|
86
|
+
"""Utility function to suppress deprecation warnings for the Hub."""
|
|
87
|
+
with warnings.catch_warnings():
|
|
88
|
+
warnings.filterwarnings("ignore", category=SentryHubDeprecationWarning)
|
|
89
|
+
yield
|
|
60
90
|
|
|
61
|
-
def init(*args, **kwargs):
|
|
62
|
-
"""Initializes the SDK and optionally integrations.
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
"""
|
|
66
|
-
global _initial_client
|
|
67
|
-
client = Client(*args, **kwargs)
|
|
68
|
-
Hub.current.bind_client(client)
|
|
69
|
-
rv = _InitGuard(client)
|
|
70
|
-
if client is not None:
|
|
71
|
-
_initial_client = weakref.ref(client)
|
|
72
|
-
return rv
|
|
92
|
+
_local = ContextVar("sentry_current_hub")
|
|
73
93
|
|
|
74
94
|
|
|
75
95
|
class HubMeta(type):
|
|
76
96
|
@property
|
|
77
|
-
def current(
|
|
97
|
+
def current(cls):
|
|
78
98
|
# type: () -> Hub
|
|
79
99
|
"""Returns the current instance of the hub."""
|
|
100
|
+
warnings.warn(SentryHubDeprecationWarning(), stacklevel=2)
|
|
80
101
|
rv = _local.get(None)
|
|
81
102
|
if rv is None:
|
|
82
|
-
|
|
103
|
+
with _suppress_hub_deprecation_warning():
|
|
104
|
+
# This will raise a deprecation warning; suppress it since we already warned above.
|
|
105
|
+
rv = Hub(GLOBAL_HUB)
|
|
83
106
|
_local.set(rv)
|
|
84
107
|
return rv
|
|
85
108
|
|
|
86
109
|
@property
|
|
87
|
-
def main(
|
|
110
|
+
def main(cls):
|
|
111
|
+
# type: () -> Hub
|
|
88
112
|
"""Returns the main instance of the hub."""
|
|
113
|
+
warnings.warn(SentryHubDeprecationWarning(), stacklevel=2)
|
|
89
114
|
return GLOBAL_HUB
|
|
90
115
|
|
|
91
116
|
|
|
92
|
-
class _HubManager(object):
|
|
93
|
-
def __init__(self, hub):
|
|
94
|
-
self._old = Hub.current
|
|
95
|
-
_local.set(hub)
|
|
96
|
-
|
|
97
|
-
def __exit__(self, exc_type, exc_value, tb):
|
|
98
|
-
_local.set(self._old)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
class _ScopeManager(object):
|
|
102
|
-
def __init__(self, hub):
|
|
103
|
-
self._hub = hub
|
|
104
|
-
self._original_len = len(hub._stack)
|
|
105
|
-
self._layer = hub._stack[-1]
|
|
106
|
-
|
|
107
|
-
def __enter__(self):
|
|
108
|
-
# type: () -> Scope
|
|
109
|
-
scope = self._layer[1]
|
|
110
|
-
assert scope is not None
|
|
111
|
-
return scope
|
|
112
|
-
|
|
113
|
-
def __exit__(self, exc_type, exc_value, tb):
|
|
114
|
-
current_len = len(self._hub._stack)
|
|
115
|
-
if current_len < self._original_len:
|
|
116
|
-
logger.error(
|
|
117
|
-
"Scope popped too soon. Popped %s scopes too many.",
|
|
118
|
-
self._original_len - current_len,
|
|
119
|
-
)
|
|
120
|
-
return
|
|
121
|
-
elif current_len > self._original_len:
|
|
122
|
-
logger.warning(
|
|
123
|
-
"Leaked %s scopes: %s",
|
|
124
|
-
current_len - self._original_len,
|
|
125
|
-
self._hub._stack[self._original_len :],
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
layer = self._hub._stack[self._original_len - 1]
|
|
129
|
-
del self._hub._stack[self._original_len - 1 :]
|
|
130
|
-
|
|
131
|
-
if layer[1] != self._layer[1]:
|
|
132
|
-
logger.error(
|
|
133
|
-
"Wrong scope found. Meant to pop %s, but popped %s.",
|
|
134
|
-
layer[1],
|
|
135
|
-
self._layer[1],
|
|
136
|
-
)
|
|
137
|
-
elif layer[0] != self._layer[0]:
|
|
138
|
-
warning = (
|
|
139
|
-
"init() called inside of pushed scope. This might be entirely "
|
|
140
|
-
"legitimate but usually occurs when initializing the SDK inside "
|
|
141
|
-
"a request handler or task/job function. Try to initialize the "
|
|
142
|
-
"SDK as early as possible instead."
|
|
143
|
-
)
|
|
144
|
-
logger.warning(warning)
|
|
145
|
-
|
|
146
|
-
|
|
147
117
|
class Hub(with_metaclass(HubMeta)): # type: ignore
|
|
148
|
-
"""
|
|
118
|
+
"""
|
|
119
|
+
.. deprecated:: 2.0.0
|
|
120
|
+
The Hub is deprecated. Its functionality will be merged into :py:class:`sentry_sdk.scope.Scope`.
|
|
121
|
+
|
|
122
|
+
The hub wraps the concurrency management of the SDK. Each thread has
|
|
149
123
|
its own hub but the hub might transfer with the flow of execution if
|
|
150
124
|
context vars are available.
|
|
151
125
|
|
|
@@ -153,27 +127,65 @@ class Hub(with_metaclass(HubMeta)): # type: ignore
|
|
|
153
127
|
"""
|
|
154
128
|
|
|
155
129
|
_stack = None # type: List[Tuple[Optional[Client], Scope]]
|
|
130
|
+
_scope = None # type: Optional[Scope]
|
|
131
|
+
|
|
132
|
+
# Mypy doesn't pick up on the metaclass.
|
|
133
|
+
|
|
134
|
+
if TYPE_CHECKING:
|
|
135
|
+
current = None # type: Hub
|
|
136
|
+
main = None # type: Hub
|
|
137
|
+
|
|
138
|
+
def __init__(
|
|
139
|
+
self,
|
|
140
|
+
client_or_hub=None, # type: Optional[Union[Hub, Client]]
|
|
141
|
+
scope=None, # type: Optional[Any]
|
|
142
|
+
):
|
|
143
|
+
# type: (...) -> None
|
|
144
|
+
warnings.warn(SentryHubDeprecationWarning(), stacklevel=2)
|
|
145
|
+
|
|
146
|
+
current_scope = None
|
|
156
147
|
|
|
157
|
-
def __init__(self, client_or_hub=None, scope=None):
|
|
158
|
-
# type: (Union[Hub, Client], Optional[Any]) -> None
|
|
159
148
|
if isinstance(client_or_hub, Hub):
|
|
160
|
-
|
|
161
|
-
client, other_scope = hub._stack[-1]
|
|
149
|
+
client = get_client()
|
|
162
150
|
if scope is None:
|
|
163
|
-
scope
|
|
151
|
+
# hub cloning is going on, we use a fork of the current/isolation scope for context manager
|
|
152
|
+
scope = get_isolation_scope().fork()
|
|
153
|
+
current_scope = get_current_scope().fork()
|
|
164
154
|
else:
|
|
165
|
-
client = client_or_hub
|
|
166
|
-
|
|
167
|
-
scope = Scope()
|
|
155
|
+
client = client_or_hub # type: ignore
|
|
156
|
+
get_global_scope().set_client(client)
|
|
168
157
|
|
|
169
|
-
|
|
158
|
+
if scope is None: # so there is no Hub cloning going on
|
|
159
|
+
# just the current isolation scope is used for context manager
|
|
160
|
+
scope = get_isolation_scope()
|
|
161
|
+
current_scope = get_current_scope()
|
|
162
|
+
|
|
163
|
+
if current_scope is None:
|
|
164
|
+
# just the current current scope is used for context manager
|
|
165
|
+
current_scope = get_current_scope()
|
|
166
|
+
|
|
167
|
+
self._stack = [(client, scope)] # type: ignore
|
|
170
168
|
self._last_event_id = None # type: Optional[str]
|
|
171
169
|
self._old_hubs = [] # type: List[Hub]
|
|
172
170
|
|
|
171
|
+
self._old_current_scopes = [] # type: List[Scope]
|
|
172
|
+
self._old_isolation_scopes = [] # type: List[Scope]
|
|
173
|
+
self._current_scope = current_scope # type: Scope
|
|
174
|
+
self._scope = scope # type: Scope
|
|
175
|
+
|
|
173
176
|
def __enter__(self):
|
|
174
177
|
# type: () -> Hub
|
|
175
178
|
self._old_hubs.append(Hub.current)
|
|
176
179
|
_local.set(self)
|
|
180
|
+
|
|
181
|
+
current_scope = get_current_scope()
|
|
182
|
+
self._old_current_scopes.append(current_scope)
|
|
183
|
+
scope._current_scope.set(self._current_scope)
|
|
184
|
+
|
|
185
|
+
isolation_scope = get_isolation_scope()
|
|
186
|
+
self._old_isolation_scopes.append(isolation_scope)
|
|
187
|
+
scope._isolation_scope.set(self._scope)
|
|
188
|
+
|
|
177
189
|
return self
|
|
178
190
|
|
|
179
191
|
def __exit__(
|
|
@@ -186,231 +198,550 @@ class Hub(with_metaclass(HubMeta)): # type: ignore
|
|
|
186
198
|
old = self._old_hubs.pop()
|
|
187
199
|
_local.set(old)
|
|
188
200
|
|
|
189
|
-
|
|
190
|
-
|
|
201
|
+
old_current_scope = self._old_current_scopes.pop()
|
|
202
|
+
scope._current_scope.set(old_current_scope)
|
|
203
|
+
|
|
204
|
+
old_isolation_scope = self._old_isolation_scopes.pop()
|
|
205
|
+
scope._isolation_scope.set(old_isolation_scope)
|
|
206
|
+
|
|
207
|
+
def run(
|
|
208
|
+
self,
|
|
209
|
+
callback, # type: Callable[[], T]
|
|
210
|
+
):
|
|
211
|
+
# type: (...) -> T
|
|
212
|
+
"""
|
|
213
|
+
.. deprecated:: 2.0.0
|
|
214
|
+
This function is deprecated and will be removed in a future release.
|
|
215
|
+
|
|
216
|
+
Runs a callback in the context of the hub. Alternatively the
|
|
191
217
|
with statement can be used on the hub directly.
|
|
192
218
|
"""
|
|
193
219
|
with self:
|
|
194
220
|
return callback()
|
|
195
221
|
|
|
196
|
-
def get_integration(
|
|
197
|
-
|
|
198
|
-
|
|
222
|
+
def get_integration(
|
|
223
|
+
self,
|
|
224
|
+
name_or_class, # type: Union[str, Type[Integration]]
|
|
225
|
+
):
|
|
226
|
+
# type: (...) -> Any
|
|
227
|
+
"""
|
|
228
|
+
.. deprecated:: 2.0.0
|
|
229
|
+
This function is deprecated and will be removed in a future release.
|
|
230
|
+
Please use :py:meth:`sentry_sdk.client._Client.get_integration` instead.
|
|
231
|
+
|
|
232
|
+
Returns the integration for this hub by name or class. If there
|
|
199
233
|
is no client bound or the client does not have that integration
|
|
200
234
|
then `None` is returned.
|
|
201
235
|
|
|
202
236
|
If the return value is not `None` the hub is guaranteed to have a
|
|
203
237
|
client attached.
|
|
204
238
|
"""
|
|
205
|
-
|
|
206
|
-
integration_name = name_or_class
|
|
207
|
-
elif name_or_class.identifier is not None:
|
|
208
|
-
integration_name = name_or_class.identifier
|
|
209
|
-
else:
|
|
210
|
-
raise ValueError("Integration has no name")
|
|
211
|
-
|
|
212
|
-
client = self._stack[-1][0]
|
|
213
|
-
if client is not None:
|
|
214
|
-
rv = client.integrations.get(integration_name)
|
|
215
|
-
if rv is not None:
|
|
216
|
-
return rv
|
|
217
|
-
|
|
218
|
-
initial_client = _initial_client
|
|
219
|
-
if initial_client is not None:
|
|
220
|
-
initial_client = initial_client()
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
initial_client is not None
|
|
224
|
-
and initial_client is not client
|
|
225
|
-
and initial_client.integrations.get(name_or_class) is not None
|
|
226
|
-
):
|
|
227
|
-
warning = (
|
|
228
|
-
"Integration %r attempted to run but it was only "
|
|
229
|
-
"enabled on init() but not the client that "
|
|
230
|
-
"was bound to the current flow. Earlier versions of "
|
|
231
|
-
"the SDK would consider these integrations enabled but "
|
|
232
|
-
"this is no longer the case." % (name_or_class,)
|
|
233
|
-
)
|
|
234
|
-
warn(Warning(warning), stacklevel=3)
|
|
235
|
-
logger.warning(warning)
|
|
239
|
+
return get_client().get_integration(name_or_class)
|
|
236
240
|
|
|
237
241
|
@property
|
|
238
242
|
def client(self):
|
|
239
|
-
# type: () -> Optional[
|
|
240
|
-
"""
|
|
241
|
-
|
|
243
|
+
# type: () -> Optional[BaseClient]
|
|
244
|
+
"""
|
|
245
|
+
.. deprecated:: 2.0.0
|
|
246
|
+
This property is deprecated and will be removed in a future release.
|
|
247
|
+
Please use :py:func:`sentry_sdk.api.get_client` instead.
|
|
248
|
+
|
|
249
|
+
Returns the current client on the hub.
|
|
250
|
+
"""
|
|
251
|
+
client = get_client()
|
|
252
|
+
|
|
253
|
+
if not client.is_active():
|
|
254
|
+
return None
|
|
255
|
+
|
|
256
|
+
return client
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def scope(self):
|
|
260
|
+
# type: () -> Scope
|
|
261
|
+
"""
|
|
262
|
+
.. deprecated:: 2.0.0
|
|
263
|
+
This property is deprecated and will be removed in a future release.
|
|
264
|
+
Returns the current scope on the hub.
|
|
265
|
+
"""
|
|
266
|
+
return get_isolation_scope()
|
|
242
267
|
|
|
243
268
|
def last_event_id(self):
|
|
244
|
-
|
|
269
|
+
# type: () -> Optional[str]
|
|
270
|
+
"""
|
|
271
|
+
Returns the last event ID.
|
|
272
|
+
|
|
273
|
+
.. deprecated:: 1.40.5
|
|
274
|
+
This function is deprecated and will be removed in a future release. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly.
|
|
275
|
+
"""
|
|
276
|
+
logger.warning(
|
|
277
|
+
"Deprecated: last_event_id is deprecated. This will be removed in the future. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly."
|
|
278
|
+
)
|
|
245
279
|
return self._last_event_id
|
|
246
280
|
|
|
247
|
-
def bind_client(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
The event is a dictionary following the Sentry v7/v8 protocol
|
|
257
|
-
specification. Optionally an event hint dict can be passed that
|
|
258
|
-
is used by processors to extract additional information from it.
|
|
259
|
-
Typically the event hint object would contain exception information.
|
|
260
|
-
"""
|
|
261
|
-
client, scope = self._stack[-1]
|
|
262
|
-
if client is not None:
|
|
263
|
-
rv = client.capture_event(event, hint, scope)
|
|
264
|
-
if rv is not None:
|
|
265
|
-
self._last_event_id = rv
|
|
266
|
-
return rv
|
|
267
|
-
return None
|
|
281
|
+
def bind_client(
|
|
282
|
+
self,
|
|
283
|
+
new, # type: Optional[BaseClient]
|
|
284
|
+
):
|
|
285
|
+
# type: (...) -> None
|
|
286
|
+
"""
|
|
287
|
+
.. deprecated:: 2.0.0
|
|
288
|
+
This function is deprecated and will be removed in a future release.
|
|
289
|
+
Please use :py:meth:`sentry_sdk.Scope.set_client` instead.
|
|
268
290
|
|
|
269
|
-
|
|
270
|
-
# type: (str, Optional[Any]) -> Optional[str]
|
|
271
|
-
"""Captures a message. The message is just a string. If no level
|
|
272
|
-
is provided the default level is `info`.
|
|
291
|
+
Binds a new client to the hub.
|
|
273
292
|
"""
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
The argument passed can be `None` in which case the last exception
|
|
284
|
-
will be reported, otherwise an exception object or an `exc_info`
|
|
285
|
-
tuple.
|
|
286
|
-
"""
|
|
287
|
-
client = self.client
|
|
288
|
-
if client is None:
|
|
289
|
-
return
|
|
290
|
-
if error is None:
|
|
291
|
-
exc_info = sys.exc_info()
|
|
292
|
-
else:
|
|
293
|
-
exc_info = exc_info_from_error(error)
|
|
293
|
+
get_global_scope().set_client(new)
|
|
294
|
+
|
|
295
|
+
def capture_event(self, event, hint=None, scope=None, **scope_kwargs):
|
|
296
|
+
# type: (Event, Optional[Hint], Optional[Scope], Any) -> Optional[str]
|
|
297
|
+
"""
|
|
298
|
+
.. deprecated:: 2.0.0
|
|
299
|
+
This function is deprecated and will be removed in a future release.
|
|
300
|
+
Please use :py:meth:`sentry_sdk.Scope.capture_event` instead.
|
|
294
301
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
302
|
+
Captures an event.
|
|
303
|
+
|
|
304
|
+
Alias of :py:meth:`sentry_sdk.Scope.capture_event`.
|
|
305
|
+
|
|
306
|
+
:param event: A ready-made event that can be directly sent to Sentry.
|
|
307
|
+
|
|
308
|
+
:param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object.
|
|
309
|
+
|
|
310
|
+
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
|
|
311
|
+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
|
|
312
|
+
|
|
313
|
+
:param scope_kwargs: Optional data to apply to event.
|
|
314
|
+
For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
|
|
315
|
+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
|
|
316
|
+
"""
|
|
317
|
+
last_event_id = get_current_scope().capture_event(
|
|
318
|
+
event, hint, scope=scope, **scope_kwargs
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
is_transaction = event.get("type") == "transaction"
|
|
322
|
+
if last_event_id is not None and not is_transaction:
|
|
323
|
+
self._last_event_id = last_event_id
|
|
324
|
+
|
|
325
|
+
return last_event_id
|
|
326
|
+
|
|
327
|
+
def capture_message(self, message, level=None, scope=None, **scope_kwargs):
|
|
328
|
+
# type: (str, Optional[LogLevelStr], Optional[Scope], Any) -> Optional[str]
|
|
329
|
+
"""
|
|
330
|
+
.. deprecated:: 2.0.0
|
|
331
|
+
This function is deprecated and will be removed in a future release.
|
|
332
|
+
Please use :py:meth:`sentry_sdk.Scope.capture_message` instead.
|
|
333
|
+
|
|
334
|
+
Captures a message.
|
|
335
|
+
|
|
336
|
+
Alias of :py:meth:`sentry_sdk.Scope.capture_message`.
|
|
337
|
+
|
|
338
|
+
:param message: The string to send as the message to Sentry.
|
|
339
|
+
|
|
340
|
+
:param level: If no level is provided, the default level is `info`.
|
|
341
|
+
|
|
342
|
+
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
|
|
343
|
+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
|
|
344
|
+
|
|
345
|
+
:param scope_kwargs: Optional data to apply to event.
|
|
346
|
+
For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
|
|
347
|
+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
|
|
348
|
+
|
|
349
|
+
:returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
|
|
350
|
+
"""
|
|
351
|
+
last_event_id = get_current_scope().capture_message(
|
|
352
|
+
message, level=level, scope=scope, **scope_kwargs
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
if last_event_id is not None:
|
|
356
|
+
self._last_event_id = last_event_id
|
|
357
|
+
|
|
358
|
+
return last_event_id
|
|
359
|
+
|
|
360
|
+
def capture_exception(self, error=None, scope=None, **scope_kwargs):
|
|
361
|
+
# type: (Optional[Union[BaseException, ExcInfo]], Optional[Scope], Any) -> Optional[str]
|
|
362
|
+
"""
|
|
363
|
+
.. deprecated:: 2.0.0
|
|
364
|
+
This function is deprecated and will be removed in a future release.
|
|
365
|
+
Please use :py:meth:`sentry_sdk.Scope.capture_exception` instead.
|
|
366
|
+
|
|
367
|
+
Captures an exception.
|
|
368
|
+
|
|
369
|
+
Alias of :py:meth:`sentry_sdk.Scope.capture_exception`.
|
|
370
|
+
|
|
371
|
+
:param error: An exception to capture. If `None`, `sys.exc_info()` will be used.
|
|
372
|
+
|
|
373
|
+
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
|
|
374
|
+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
|
|
375
|
+
|
|
376
|
+
:param scope_kwargs: Optional data to apply to event.
|
|
377
|
+
For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
|
|
378
|
+
The `scope` and `scope_kwargs` parameters are mutually exclusive.
|
|
379
|
+
|
|
380
|
+
:returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
|
|
381
|
+
"""
|
|
382
|
+
last_event_id = get_current_scope().capture_exception(
|
|
383
|
+
error, scope=scope, **scope_kwargs
|
|
384
|
+
)
|
|
300
385
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
386
|
+
if last_event_id is not None:
|
|
387
|
+
self._last_event_id = last_event_id
|
|
388
|
+
|
|
389
|
+
return last_event_id
|
|
305
390
|
|
|
306
391
|
def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
|
|
307
|
-
# type: (
|
|
308
|
-
"""
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
392
|
+
# type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None
|
|
393
|
+
"""
|
|
394
|
+
.. deprecated:: 2.0.0
|
|
395
|
+
This function is deprecated and will be removed in a future release.
|
|
396
|
+
Please use :py:meth:`sentry_sdk.Scope.add_breadcrumb` instead.
|
|
397
|
+
|
|
398
|
+
Adds a breadcrumb.
|
|
399
|
+
|
|
400
|
+
:param crumb: Dictionary with the data as the sentry v7/v8 protocol expects.
|
|
401
|
+
|
|
402
|
+
:param hint: An optional value that can be used by `before_breadcrumb`
|
|
403
|
+
to customize the breadcrumbs that are emitted.
|
|
404
|
+
"""
|
|
405
|
+
get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
|
|
406
|
+
|
|
407
|
+
def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
|
|
408
|
+
# type: (str, Any) -> Span
|
|
409
|
+
"""
|
|
410
|
+
.. deprecated:: 2.0.0
|
|
411
|
+
This function is deprecated and will be removed in a future release.
|
|
412
|
+
Please use :py:meth:`sentry_sdk.Scope.start_span` instead.
|
|
413
|
+
|
|
414
|
+
Start a span whose parent is the currently active span or transaction, if any.
|
|
415
|
+
|
|
416
|
+
The return value is a :py:class:`sentry_sdk.tracing.Span` instance,
|
|
417
|
+
typically used as a context manager to start and stop timing in a `with`
|
|
418
|
+
block.
|
|
419
|
+
|
|
420
|
+
Only spans contained in a transaction are sent to Sentry. Most
|
|
421
|
+
integrations start a transaction at the appropriate time, for example
|
|
422
|
+
for every incoming HTTP request. Use
|
|
423
|
+
:py:meth:`sentry_sdk.start_transaction` to start a new transaction when
|
|
424
|
+
one is not already in progress.
|
|
425
|
+
|
|
426
|
+
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
|
|
427
|
+
"""
|
|
428
|
+
scope = get_current_scope()
|
|
429
|
+
return scope.start_span(instrumenter=instrumenter, **kwargs)
|
|
430
|
+
|
|
431
|
+
def start_transaction(
|
|
432
|
+
self,
|
|
433
|
+
transaction=None,
|
|
434
|
+
instrumenter=INSTRUMENTER.SENTRY,
|
|
435
|
+
custom_sampling_context=None,
|
|
436
|
+
**kwargs,
|
|
437
|
+
):
|
|
438
|
+
# type: (Optional[Transaction], str, Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
|
|
439
|
+
"""
|
|
440
|
+
.. deprecated:: 2.0.0
|
|
441
|
+
This function is deprecated and will be removed in a future release.
|
|
442
|
+
Please use :py:meth:`sentry_sdk.Scope.start_transaction` instead.
|
|
443
|
+
|
|
444
|
+
Start and return a transaction.
|
|
445
|
+
|
|
446
|
+
Start an existing transaction if given, otherwise create and start a new
|
|
447
|
+
transaction with kwargs.
|
|
448
|
+
|
|
449
|
+
This is the entry point to manual tracing instrumentation.
|
|
450
|
+
|
|
451
|
+
A tree structure can be built by adding child spans to the transaction,
|
|
452
|
+
and child spans to other spans. To start a new child span within the
|
|
453
|
+
transaction or any span, call the respective `.start_child()` method.
|
|
454
|
+
|
|
455
|
+
Every child span must be finished before the transaction is finished,
|
|
456
|
+
otherwise the unfinished spans are discarded.
|
|
338
457
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
458
|
+
When used as context managers, spans and transactions are automatically
|
|
459
|
+
finished at the end of the `with` block. If not using context managers,
|
|
460
|
+
call the `.finish()` method.
|
|
461
|
+
|
|
462
|
+
When the transaction is finished, it will be sent to Sentry with all its
|
|
463
|
+
finished child spans.
|
|
464
|
+
|
|
465
|
+
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Transaction`.
|
|
466
|
+
"""
|
|
467
|
+
scope = get_current_scope()
|
|
468
|
+
|
|
469
|
+
# For backwards compatibility, we allow passing the scope as the hub.
|
|
470
|
+
# We need a major release to make this nice. (if someone searches the code: deprecated)
|
|
471
|
+
# Type checking disabled for this line because deprecated keys are not allowed in the type signature.
|
|
472
|
+
kwargs["hub"] = scope # type: ignore
|
|
473
|
+
|
|
474
|
+
return scope.start_transaction(
|
|
475
|
+
transaction, instrumenter, custom_sampling_context, **kwargs
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
def continue_trace(self, environ_or_headers, op=None, name=None, source=None):
|
|
479
|
+
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str]) -> Transaction
|
|
480
|
+
"""
|
|
481
|
+
.. deprecated:: 2.0.0
|
|
482
|
+
This function is deprecated and will be removed in a future release.
|
|
483
|
+
Please use :py:meth:`sentry_sdk.Scope.continue_trace` instead.
|
|
342
484
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
485
|
+
Sets the propagation context from environment or headers and returns a transaction.
|
|
486
|
+
"""
|
|
487
|
+
return get_isolation_scope().continue_trace(
|
|
488
|
+
environ_or_headers=environ_or_headers, op=op, name=name, source=source
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
@overload
|
|
492
|
+
def push_scope(
|
|
493
|
+
self,
|
|
494
|
+
callback=None, # type: Optional[None]
|
|
495
|
+
):
|
|
496
|
+
# type: (...) -> ContextManager[Scope]
|
|
346
497
|
pass
|
|
347
498
|
|
|
348
|
-
@overload
|
|
349
|
-
def push_scope(
|
|
350
|
-
|
|
499
|
+
@overload
|
|
500
|
+
def push_scope( # noqa: F811
|
|
501
|
+
self,
|
|
502
|
+
callback, # type: Callable[[Scope], None]
|
|
503
|
+
):
|
|
504
|
+
# type: (...) -> None
|
|
351
505
|
pass
|
|
352
506
|
|
|
353
|
-
def push_scope(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
507
|
+
def push_scope( # noqa
|
|
508
|
+
self,
|
|
509
|
+
callback=None, # type: Optional[Callable[[Scope], None]]
|
|
510
|
+
continue_trace=True, # type: bool
|
|
511
|
+
):
|
|
512
|
+
# type: (...) -> Optional[ContextManager[Scope]]
|
|
357
513
|
"""
|
|
514
|
+
.. deprecated:: 2.0.0
|
|
515
|
+
This function is deprecated and will be removed in a future release.
|
|
516
|
+
|
|
517
|
+
Pushes a new layer on the scope stack.
|
|
358
518
|
|
|
519
|
+
:param callback: If provided, this method pushes a scope, calls
|
|
520
|
+
`callback`, and pops the scope again.
|
|
521
|
+
|
|
522
|
+
:returns: If no `callback` is provided, a context manager that should
|
|
523
|
+
be used to pop the scope again.
|
|
524
|
+
"""
|
|
359
525
|
if callback is not None:
|
|
360
526
|
with self.push_scope() as scope:
|
|
361
527
|
callback(scope)
|
|
362
528
|
return None
|
|
363
529
|
|
|
364
|
-
client, scope = self._stack[-1]
|
|
365
|
-
new_layer = (client, copy.copy(scope))
|
|
366
|
-
self._stack.append(new_layer)
|
|
367
|
-
|
|
368
530
|
return _ScopeManager(self)
|
|
369
531
|
|
|
370
|
-
scope = push_scope
|
|
371
|
-
|
|
372
532
|
def pop_scope_unsafe(self):
|
|
373
|
-
|
|
374
|
-
|
|
533
|
+
# type: () -> Tuple[Optional[Client], Scope]
|
|
534
|
+
"""
|
|
535
|
+
.. deprecated:: 2.0.0
|
|
536
|
+
This function is deprecated and will be removed in a future release.
|
|
537
|
+
|
|
538
|
+
Pops a scope layer from the stack.
|
|
539
|
+
|
|
540
|
+
Try to use the context manager :py:meth:`push_scope` instead.
|
|
541
|
+
"""
|
|
375
542
|
rv = self._stack.pop()
|
|
376
543
|
assert self._stack, "stack must have at least one layer"
|
|
377
544
|
return rv
|
|
378
545
|
|
|
379
|
-
@overload
|
|
380
|
-
def configure_scope(
|
|
381
|
-
|
|
546
|
+
@overload
|
|
547
|
+
def configure_scope(
|
|
548
|
+
self,
|
|
549
|
+
callback=None, # type: Optional[None]
|
|
550
|
+
):
|
|
551
|
+
# type: (...) -> ContextManager[Scope]
|
|
382
552
|
pass
|
|
383
553
|
|
|
384
|
-
@overload
|
|
385
|
-
def configure_scope(
|
|
386
|
-
|
|
554
|
+
@overload
|
|
555
|
+
def configure_scope( # noqa: F811
|
|
556
|
+
self,
|
|
557
|
+
callback, # type: Callable[[Scope], None]
|
|
558
|
+
):
|
|
559
|
+
# type: (...) -> None
|
|
387
560
|
pass
|
|
388
561
|
|
|
389
|
-
def configure_scope(
|
|
390
|
-
|
|
562
|
+
def configure_scope( # noqa
|
|
563
|
+
self,
|
|
564
|
+
callback=None, # type: Optional[Callable[[Scope], None]]
|
|
565
|
+
continue_trace=True, # type: bool
|
|
566
|
+
):
|
|
567
|
+
# type: (...) -> Optional[ContextManager[Scope]]
|
|
568
|
+
"""
|
|
569
|
+
.. deprecated:: 2.0.0
|
|
570
|
+
This function is deprecated and will be removed in a future release.
|
|
571
|
+
|
|
572
|
+
Reconfigures the scope.
|
|
573
|
+
|
|
574
|
+
:param callback: If provided, call the callback with the current scope.
|
|
575
|
+
|
|
576
|
+
:returns: If no callback is provided, returns a context manager that returns the scope.
|
|
577
|
+
"""
|
|
578
|
+
scope = get_isolation_scope()
|
|
579
|
+
|
|
580
|
+
if continue_trace:
|
|
581
|
+
scope.generate_propagation_context()
|
|
391
582
|
|
|
392
|
-
client, scope = self._stack[-1]
|
|
393
583
|
if callback is not None:
|
|
394
|
-
|
|
395
|
-
|
|
584
|
+
# TODO: used to return None when client is None. Check if this changes behavior.
|
|
585
|
+
callback(scope)
|
|
396
586
|
|
|
397
587
|
return None
|
|
398
588
|
|
|
399
589
|
@contextmanager
|
|
400
590
|
def inner():
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
else:
|
|
404
|
-
yield Scope()
|
|
591
|
+
# type: () -> Generator[Scope, None, None]
|
|
592
|
+
yield scope
|
|
405
593
|
|
|
406
594
|
return inner()
|
|
407
595
|
|
|
408
|
-
def
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
596
|
+
def start_session(
|
|
597
|
+
self,
|
|
598
|
+
session_mode="application", # type: str
|
|
599
|
+
):
|
|
600
|
+
# type: (...) -> None
|
|
601
|
+
"""
|
|
602
|
+
.. deprecated:: 2.0.0
|
|
603
|
+
This function is deprecated and will be removed in a future release.
|
|
604
|
+
Please use :py:meth:`sentry_sdk.Scope.start_session` instead.
|
|
605
|
+
|
|
606
|
+
Starts a new session.
|
|
607
|
+
"""
|
|
608
|
+
get_isolation_scope().start_session(
|
|
609
|
+
session_mode=session_mode,
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
def end_session(self):
|
|
613
|
+
# type: (...) -> None
|
|
614
|
+
"""
|
|
615
|
+
.. deprecated:: 2.0.0
|
|
616
|
+
This function is deprecated and will be removed in a future release.
|
|
617
|
+
Please use :py:meth:`sentry_sdk.Scope.end_session` instead.
|
|
618
|
+
|
|
619
|
+
Ends the current session if there is one.
|
|
620
|
+
"""
|
|
621
|
+
get_isolation_scope().end_session()
|
|
622
|
+
|
|
623
|
+
def stop_auto_session_tracking(self):
|
|
624
|
+
# type: (...) -> None
|
|
625
|
+
"""
|
|
626
|
+
.. deprecated:: 2.0.0
|
|
627
|
+
This function is deprecated and will be removed in a future release.
|
|
628
|
+
Please use :py:meth:`sentry_sdk.Scope.stop_auto_session_tracking` instead.
|
|
629
|
+
|
|
630
|
+
Stops automatic session tracking.
|
|
631
|
+
|
|
632
|
+
This temporarily session tracking for the current scope when called.
|
|
633
|
+
To resume session tracking call `resume_auto_session_tracking`.
|
|
634
|
+
"""
|
|
635
|
+
get_isolation_scope().stop_auto_session_tracking()
|
|
413
636
|
|
|
637
|
+
def resume_auto_session_tracking(self):
|
|
638
|
+
# type: (...) -> None
|
|
639
|
+
"""
|
|
640
|
+
.. deprecated:: 2.0.0
|
|
641
|
+
This function is deprecated and will be removed in a future release.
|
|
642
|
+
Please use :py:meth:`sentry_sdk.Scope.resume_auto_session_tracking` instead.
|
|
414
643
|
|
|
415
|
-
|
|
644
|
+
Resumes automatic session tracking for the current scope if
|
|
645
|
+
disabled earlier. This requires that generally automatic session
|
|
646
|
+
tracking is enabled.
|
|
647
|
+
"""
|
|
648
|
+
get_isolation_scope().resume_auto_session_tracking()
|
|
649
|
+
|
|
650
|
+
def flush(
|
|
651
|
+
self,
|
|
652
|
+
timeout=None, # type: Optional[float]
|
|
653
|
+
callback=None, # type: Optional[Callable[[int, float], None]]
|
|
654
|
+
):
|
|
655
|
+
# type: (...) -> None
|
|
656
|
+
"""
|
|
657
|
+
.. deprecated:: 2.0.0
|
|
658
|
+
This function is deprecated and will be removed in a future release.
|
|
659
|
+
Please use :py:meth:`sentry_sdk.client._Client.flush` instead.
|
|
660
|
+
|
|
661
|
+
Alias for :py:meth:`sentry_sdk.client._Client.flush`
|
|
662
|
+
"""
|
|
663
|
+
return get_client().flush(timeout=timeout, callback=callback)
|
|
664
|
+
|
|
665
|
+
def get_traceparent(self):
|
|
666
|
+
# type: () -> Optional[str]
|
|
667
|
+
"""
|
|
668
|
+
.. deprecated:: 2.0.0
|
|
669
|
+
This function is deprecated and will be removed in a future release.
|
|
670
|
+
Please use :py:meth:`sentry_sdk.Scope.get_traceparent` instead.
|
|
671
|
+
|
|
672
|
+
Returns the traceparent either from the active span or from the scope.
|
|
673
|
+
"""
|
|
674
|
+
current_scope = get_current_scope()
|
|
675
|
+
traceparent = current_scope.get_traceparent()
|
|
676
|
+
|
|
677
|
+
if traceparent is None:
|
|
678
|
+
isolation_scope = get_isolation_scope()
|
|
679
|
+
traceparent = isolation_scope.get_traceparent()
|
|
680
|
+
|
|
681
|
+
return traceparent
|
|
682
|
+
|
|
683
|
+
def get_baggage(self):
|
|
684
|
+
# type: () -> Optional[str]
|
|
685
|
+
"""
|
|
686
|
+
.. deprecated:: 2.0.0
|
|
687
|
+
This function is deprecated and will be removed in a future release.
|
|
688
|
+
Please use :py:meth:`sentry_sdk.Scope.get_baggage` instead.
|
|
689
|
+
|
|
690
|
+
Returns Baggage either from the active span or from the scope.
|
|
691
|
+
"""
|
|
692
|
+
current_scope = get_current_scope()
|
|
693
|
+
baggage = current_scope.get_baggage()
|
|
694
|
+
|
|
695
|
+
if baggage is None:
|
|
696
|
+
isolation_scope = get_isolation_scope()
|
|
697
|
+
baggage = isolation_scope.get_baggage()
|
|
698
|
+
|
|
699
|
+
if baggage is not None:
|
|
700
|
+
return baggage.serialize()
|
|
701
|
+
|
|
702
|
+
return None
|
|
703
|
+
|
|
704
|
+
def iter_trace_propagation_headers(self, span=None):
|
|
705
|
+
# type: (Optional[Span]) -> Generator[Tuple[str, str], None, None]
|
|
706
|
+
"""
|
|
707
|
+
.. deprecated:: 2.0.0
|
|
708
|
+
This function is deprecated and will be removed in a future release.
|
|
709
|
+
Please use :py:meth:`sentry_sdk.Scope.iter_trace_propagation_headers` instead.
|
|
710
|
+
|
|
711
|
+
Return HTTP headers which allow propagation of trace data. Data taken
|
|
712
|
+
from the span representing the request, if available, or the current
|
|
713
|
+
span on the scope if not.
|
|
714
|
+
"""
|
|
715
|
+
return get_current_scope().iter_trace_propagation_headers(
|
|
716
|
+
span=span,
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
def trace_propagation_meta(self, span=None):
|
|
720
|
+
# type: (Optional[Span]) -> str
|
|
721
|
+
"""
|
|
722
|
+
.. deprecated:: 2.0.0
|
|
723
|
+
This function is deprecated and will be removed in a future release.
|
|
724
|
+
Please use :py:meth:`sentry_sdk.Scope.trace_propagation_meta` instead.
|
|
725
|
+
|
|
726
|
+
Return meta tags which should be injected into HTML templates
|
|
727
|
+
to allow propagation of trace information.
|
|
728
|
+
"""
|
|
729
|
+
if span is not None:
|
|
730
|
+
logger.warning(
|
|
731
|
+
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
|
|
732
|
+
)
|
|
733
|
+
|
|
734
|
+
return get_current_scope().trace_propagation_meta(
|
|
735
|
+
span=span,
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
with _suppress_hub_deprecation_warning():
|
|
740
|
+
# Suppress deprecation warning for the Hub here, since we still always
|
|
741
|
+
# import this module.
|
|
742
|
+
GLOBAL_HUB = Hub()
|
|
416
743
|
_local.set(GLOBAL_HUB)
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
# Circular imports
|
|
747
|
+
from sentry_sdk import scope
|