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/api.py
CHANGED
|
@@ -1,139 +1,555 @@
|
|
|
1
1
|
import inspect
|
|
2
|
+
import warnings
|
|
2
3
|
from contextlib import contextmanager
|
|
3
4
|
|
|
4
|
-
from sentry_sdk
|
|
5
|
-
from sentry_sdk.
|
|
5
|
+
from sentry_sdk import tracing_utils, Client
|
|
6
|
+
from sentry_sdk._init_implementation import init
|
|
7
|
+
from sentry_sdk.consts import INSTRUMENTER
|
|
8
|
+
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
|
|
9
|
+
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
|
|
10
|
+
from sentry_sdk.crons import monitor
|
|
6
11
|
|
|
12
|
+
from typing import TYPE_CHECKING
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from collections.abc import Mapping
|
|
7
16
|
|
|
8
|
-
if False:
|
|
9
17
|
from typing import Any
|
|
18
|
+
from typing import Dict
|
|
19
|
+
from typing import Generator
|
|
10
20
|
from typing import Optional
|
|
11
21
|
from typing import overload
|
|
12
22
|
from typing import Callable
|
|
13
|
-
from
|
|
23
|
+
from typing import TypeVar
|
|
24
|
+
from typing import ContextManager
|
|
25
|
+
from typing import Union
|
|
26
|
+
|
|
27
|
+
from typing_extensions import Unpack
|
|
28
|
+
|
|
29
|
+
from sentry_sdk.client import BaseClient
|
|
30
|
+
from sentry_sdk._types import (
|
|
31
|
+
Event,
|
|
32
|
+
Hint,
|
|
33
|
+
Breadcrumb,
|
|
34
|
+
BreadcrumbHint,
|
|
35
|
+
ExcInfo,
|
|
36
|
+
MeasurementUnit,
|
|
37
|
+
LogLevelStr,
|
|
38
|
+
SamplingContext,
|
|
39
|
+
)
|
|
40
|
+
from sentry_sdk.tracing import Span, TransactionKwargs
|
|
41
|
+
|
|
42
|
+
T = TypeVar("T")
|
|
43
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
14
44
|
else:
|
|
15
45
|
|
|
16
46
|
def overload(x):
|
|
47
|
+
# type: (T) -> T
|
|
17
48
|
return x
|
|
18
49
|
|
|
19
50
|
|
|
20
|
-
__all__
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
# When changing this, update __all__ in __init__.py too
|
|
52
|
+
__all__ = [
|
|
53
|
+
"init",
|
|
54
|
+
"add_attachment",
|
|
55
|
+
"add_breadcrumb",
|
|
56
|
+
"capture_event",
|
|
57
|
+
"capture_exception",
|
|
58
|
+
"capture_message",
|
|
59
|
+
"configure_scope",
|
|
60
|
+
"continue_trace",
|
|
61
|
+
"flush",
|
|
62
|
+
"get_baggage",
|
|
63
|
+
"get_client",
|
|
64
|
+
"get_global_scope",
|
|
65
|
+
"get_isolation_scope",
|
|
66
|
+
"get_current_scope",
|
|
67
|
+
"get_current_span",
|
|
68
|
+
"get_traceparent",
|
|
69
|
+
"is_initialized",
|
|
70
|
+
"isolation_scope",
|
|
71
|
+
"last_event_id",
|
|
72
|
+
"new_scope",
|
|
73
|
+
"push_scope",
|
|
74
|
+
"set_context",
|
|
75
|
+
"set_extra",
|
|
76
|
+
"set_level",
|
|
77
|
+
"set_measurement",
|
|
78
|
+
"set_tag",
|
|
79
|
+
"set_tags",
|
|
80
|
+
"set_user",
|
|
81
|
+
"start_span",
|
|
82
|
+
"start_transaction",
|
|
83
|
+
"trace",
|
|
84
|
+
"monitor",
|
|
85
|
+
"start_session",
|
|
86
|
+
"end_session",
|
|
87
|
+
"set_transaction_name",
|
|
88
|
+
"update_current_span",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def scopemethod(f):
|
|
93
|
+
# type: (F) -> F
|
|
94
|
+
f.__doc__ = "%s\n\n%s" % (
|
|
95
|
+
"Alias for :py:meth:`sentry_sdk.Scope.%s`" % f.__name__,
|
|
96
|
+
inspect.getdoc(getattr(Scope, f.__name__)),
|
|
97
|
+
)
|
|
25
98
|
return f
|
|
26
99
|
|
|
27
100
|
|
|
28
|
-
def
|
|
101
|
+
def clientmethod(f):
|
|
102
|
+
# type: (F) -> F
|
|
29
103
|
f.__doc__ = "%s\n\n%s" % (
|
|
30
|
-
"Alias for
|
|
31
|
-
inspect.getdoc(getattr(
|
|
104
|
+
"Alias for :py:meth:`sentry_sdk.Client.%s`" % f.__name__,
|
|
105
|
+
inspect.getdoc(getattr(Client, f.__name__)),
|
|
32
106
|
)
|
|
33
|
-
return
|
|
107
|
+
return f
|
|
34
108
|
|
|
35
109
|
|
|
36
|
-
@
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return hub.capture_event(event, hint)
|
|
110
|
+
@scopemethod
|
|
111
|
+
def get_client():
|
|
112
|
+
# type: () -> BaseClient
|
|
113
|
+
return Scope.get_client()
|
|
41
114
|
|
|
42
115
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if hub is not None:
|
|
48
|
-
return hub.capture_message(message, level)
|
|
49
|
-
return None
|
|
116
|
+
def is_initialized():
|
|
117
|
+
# type: () -> bool
|
|
118
|
+
"""
|
|
119
|
+
.. versionadded:: 2.0.0
|
|
50
120
|
|
|
121
|
+
Returns whether Sentry has been initialized or not.
|
|
51
122
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
123
|
+
If a client is available and the client is active
|
|
124
|
+
(meaning it is configured to send data) then
|
|
125
|
+
Sentry is initialized.
|
|
126
|
+
"""
|
|
127
|
+
return get_client().is_active()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@scopemethod
|
|
131
|
+
def get_global_scope():
|
|
132
|
+
# type: () -> Scope
|
|
133
|
+
return Scope.get_global_scope()
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@scopemethod
|
|
137
|
+
def get_isolation_scope():
|
|
138
|
+
# type: () -> Scope
|
|
139
|
+
return Scope.get_isolation_scope()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@scopemethod
|
|
143
|
+
def get_current_scope():
|
|
144
|
+
# type: () -> Scope
|
|
145
|
+
return Scope.get_current_scope()
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@scopemethod
|
|
149
|
+
def last_event_id():
|
|
150
|
+
# type: () -> Optional[str]
|
|
151
|
+
"""
|
|
152
|
+
See :py:meth:`sentry_sdk.Scope.last_event_id` documentation regarding
|
|
153
|
+
this method's limitations.
|
|
154
|
+
"""
|
|
155
|
+
return Scope.last_event_id()
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@scopemethod
|
|
159
|
+
def capture_event(
|
|
160
|
+
event, # type: Event
|
|
161
|
+
hint=None, # type: Optional[Hint]
|
|
162
|
+
scope=None, # type: Optional[Any]
|
|
163
|
+
**scope_kwargs, # type: Any
|
|
164
|
+
):
|
|
165
|
+
# type: (...) -> Optional[str]
|
|
166
|
+
return get_current_scope().capture_event(event, hint, scope=scope, **scope_kwargs)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@scopemethod
|
|
170
|
+
def capture_message(
|
|
171
|
+
message, # type: str
|
|
172
|
+
level=None, # type: Optional[LogLevelStr]
|
|
173
|
+
scope=None, # type: Optional[Any]
|
|
174
|
+
**scope_kwargs, # type: Any
|
|
175
|
+
):
|
|
176
|
+
# type: (...) -> Optional[str]
|
|
177
|
+
return get_current_scope().capture_message(
|
|
178
|
+
message, level, scope=scope, **scope_kwargs
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@scopemethod
|
|
183
|
+
def capture_exception(
|
|
184
|
+
error=None, # type: Optional[Union[BaseException, ExcInfo]]
|
|
185
|
+
scope=None, # type: Optional[Any]
|
|
186
|
+
**scope_kwargs, # type: Any
|
|
187
|
+
):
|
|
188
|
+
# type: (...) -> Optional[str]
|
|
189
|
+
return get_current_scope().capture_exception(error, scope=scope, **scope_kwargs)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@scopemethod
|
|
193
|
+
def add_attachment(
|
|
194
|
+
bytes=None, # type: Union[None, bytes, Callable[[], bytes]]
|
|
195
|
+
filename=None, # type: Optional[str]
|
|
196
|
+
path=None, # type: Optional[str]
|
|
197
|
+
content_type=None, # type: Optional[str]
|
|
198
|
+
add_to_transactions=False, # type: bool
|
|
199
|
+
):
|
|
200
|
+
# type: (...) -> None
|
|
201
|
+
return get_isolation_scope().add_attachment(
|
|
202
|
+
bytes, filename, path, content_type, add_to_transactions
|
|
203
|
+
)
|
|
59
204
|
|
|
60
205
|
|
|
61
|
-
@
|
|
62
|
-
def add_breadcrumb(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
206
|
+
@scopemethod
|
|
207
|
+
def add_breadcrumb(
|
|
208
|
+
crumb=None, # type: Optional[Breadcrumb]
|
|
209
|
+
hint=None, # type: Optional[BreadcrumbHint]
|
|
210
|
+
**kwargs, # type: Any
|
|
211
|
+
):
|
|
212
|
+
# type: (...) -> None
|
|
213
|
+
return get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
|
|
66
214
|
|
|
67
215
|
|
|
68
|
-
@overload
|
|
216
|
+
@overload
|
|
69
217
|
def configure_scope():
|
|
70
218
|
# type: () -> ContextManager[Scope]
|
|
71
219
|
pass
|
|
72
220
|
|
|
73
221
|
|
|
74
|
-
@overload
|
|
75
|
-
def configure_scope(
|
|
76
|
-
# type:
|
|
222
|
+
@overload
|
|
223
|
+
def configure_scope( # noqa: F811
|
|
224
|
+
callback, # type: Callable[[Scope], None]
|
|
225
|
+
):
|
|
226
|
+
# type: (...) -> None
|
|
77
227
|
pass
|
|
78
228
|
|
|
79
229
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
230
|
+
def configure_scope( # noqa: F811
|
|
231
|
+
callback=None, # type: Optional[Callable[[Scope], None]]
|
|
232
|
+
):
|
|
233
|
+
# type: (...) -> Optional[ContextManager[Scope]]
|
|
234
|
+
"""
|
|
235
|
+
Reconfigures the scope.
|
|
86
236
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
237
|
+
:param callback: If provided, call the callback with the current scope.
|
|
238
|
+
|
|
239
|
+
:returns: If no callback is provided, returns a context manager that returns the scope.
|
|
240
|
+
"""
|
|
241
|
+
warnings.warn(
|
|
242
|
+
"sentry_sdk.configure_scope is deprecated and will be removed in the next major version. "
|
|
243
|
+
"Please consult our migration guide to learn how to migrate to the new API: "
|
|
244
|
+
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-configuring",
|
|
245
|
+
DeprecationWarning,
|
|
246
|
+
stacklevel=2,
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
scope = get_isolation_scope()
|
|
250
|
+
scope.generate_propagation_context()
|
|
251
|
+
|
|
252
|
+
if callback is not None:
|
|
253
|
+
# TODO: used to return None when client is None. Check if this changes behavior.
|
|
254
|
+
callback(scope)
|
|
90
255
|
|
|
91
|
-
return inner()
|
|
92
|
-
else:
|
|
93
|
-
# returned if user provided callback
|
|
94
256
|
return None
|
|
95
257
|
|
|
258
|
+
@contextmanager
|
|
259
|
+
def inner():
|
|
260
|
+
# type: () -> Generator[Scope, None, None]
|
|
261
|
+
yield scope
|
|
262
|
+
|
|
263
|
+
return inner()
|
|
264
|
+
|
|
96
265
|
|
|
97
|
-
@overload
|
|
266
|
+
@overload
|
|
98
267
|
def push_scope():
|
|
99
268
|
# type: () -> ContextManager[Scope]
|
|
100
269
|
pass
|
|
101
270
|
|
|
102
271
|
|
|
103
|
-
@overload
|
|
104
|
-
def push_scope(
|
|
105
|
-
# type:
|
|
272
|
+
@overload
|
|
273
|
+
def push_scope( # noqa: F811
|
|
274
|
+
callback, # type: Callable[[Scope], None]
|
|
275
|
+
):
|
|
276
|
+
# type: (...) -> None
|
|
106
277
|
pass
|
|
107
278
|
|
|
108
279
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
280
|
+
def push_scope( # noqa: F811
|
|
281
|
+
callback=None, # type: Optional[Callable[[Scope], None]]
|
|
282
|
+
):
|
|
283
|
+
# type: (...) -> Optional[ContextManager[Scope]]
|
|
284
|
+
"""
|
|
285
|
+
Pushes a new layer on the scope stack.
|
|
286
|
+
|
|
287
|
+
:param callback: If provided, this method pushes a scope, calls
|
|
288
|
+
`callback`, and pops the scope again.
|
|
289
|
+
|
|
290
|
+
:returns: If no `callback` is provided, a context manager that should
|
|
291
|
+
be used to pop the scope again.
|
|
292
|
+
"""
|
|
293
|
+
warnings.warn(
|
|
294
|
+
"sentry_sdk.push_scope is deprecated and will be removed in the next major version. "
|
|
295
|
+
"Please consult our migration guide to learn how to migrate to the new API: "
|
|
296
|
+
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-pushing",
|
|
297
|
+
DeprecationWarning,
|
|
298
|
+
stacklevel=2,
|
|
299
|
+
)
|
|
119
300
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
301
|
+
if callback is not None:
|
|
302
|
+
with warnings.catch_warnings():
|
|
303
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
|
304
|
+
with push_scope() as scope:
|
|
305
|
+
callback(scope)
|
|
123
306
|
return None
|
|
124
307
|
|
|
308
|
+
return _ScopeManager()
|
|
125
309
|
|
|
126
|
-
@hubmethod
|
|
127
|
-
def flush(timeout=None, callback=None):
|
|
128
|
-
hub = Hub.current
|
|
129
|
-
if hub is not None:
|
|
130
|
-
return hub.flush(timeout=timeout, callback=callback)
|
|
131
310
|
|
|
311
|
+
@scopemethod
|
|
312
|
+
def set_tag(key, value):
|
|
313
|
+
# type: (str, Any) -> None
|
|
314
|
+
return get_isolation_scope().set_tag(key, value)
|
|
132
315
|
|
|
133
|
-
|
|
134
|
-
|
|
316
|
+
|
|
317
|
+
@scopemethod
|
|
318
|
+
def set_tags(tags):
|
|
319
|
+
# type: (Mapping[str, object]) -> None
|
|
320
|
+
return get_isolation_scope().set_tags(tags)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@scopemethod
|
|
324
|
+
def set_context(key, value):
|
|
325
|
+
# type: (str, Dict[str, Any]) -> None
|
|
326
|
+
return get_isolation_scope().set_context(key, value)
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
@scopemethod
|
|
330
|
+
def set_extra(key, value):
|
|
331
|
+
# type: (str, Any) -> None
|
|
332
|
+
return get_isolation_scope().set_extra(key, value)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
@scopemethod
|
|
336
|
+
def set_user(value):
|
|
337
|
+
# type: (Optional[Dict[str, Any]]) -> None
|
|
338
|
+
return get_isolation_scope().set_user(value)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
@scopemethod
|
|
342
|
+
def set_level(value):
|
|
343
|
+
# type: (LogLevelStr) -> None
|
|
344
|
+
return get_isolation_scope().set_level(value)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
@clientmethod
|
|
348
|
+
def flush(
|
|
349
|
+
timeout=None, # type: Optional[float]
|
|
350
|
+
callback=None, # type: Optional[Callable[[int, float], None]]
|
|
351
|
+
):
|
|
352
|
+
# type: (...) -> None
|
|
353
|
+
return get_client().flush(timeout=timeout, callback=callback)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
@scopemethod
|
|
357
|
+
def start_span(
|
|
358
|
+
**kwargs, # type: Any
|
|
359
|
+
):
|
|
360
|
+
# type: (...) -> Span
|
|
361
|
+
return get_current_scope().start_span(**kwargs)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
@scopemethod
|
|
365
|
+
def start_transaction(
|
|
366
|
+
transaction=None, # type: Optional[Transaction]
|
|
367
|
+
instrumenter=INSTRUMENTER.SENTRY, # type: str
|
|
368
|
+
custom_sampling_context=None, # type: Optional[SamplingContext]
|
|
369
|
+
**kwargs, # type: Unpack[TransactionKwargs]
|
|
370
|
+
):
|
|
371
|
+
# type: (...) -> Union[Transaction, NoOpSpan]
|
|
372
|
+
"""
|
|
373
|
+
Start and return a transaction on the current scope.
|
|
374
|
+
|
|
375
|
+
Start an existing transaction if given, otherwise create and start a new
|
|
376
|
+
transaction with kwargs.
|
|
377
|
+
|
|
378
|
+
This is the entry point to manual tracing instrumentation.
|
|
379
|
+
|
|
380
|
+
A tree structure can be built by adding child spans to the transaction,
|
|
381
|
+
and child spans to other spans. To start a new child span within the
|
|
382
|
+
transaction or any span, call the respective `.start_child()` method.
|
|
383
|
+
|
|
384
|
+
Every child span must be finished before the transaction is finished,
|
|
385
|
+
otherwise the unfinished spans are discarded.
|
|
386
|
+
|
|
387
|
+
When used as context managers, spans and transactions are automatically
|
|
388
|
+
finished at the end of the `with` block. If not using context managers,
|
|
389
|
+
call the `.finish()` method.
|
|
390
|
+
|
|
391
|
+
When the transaction is finished, it will be sent to Sentry with all its
|
|
392
|
+
finished child spans.
|
|
393
|
+
|
|
394
|
+
:param transaction: The transaction to start. If omitted, we create and
|
|
395
|
+
start a new transaction.
|
|
396
|
+
:param instrumenter: This parameter is meant for internal use only. It
|
|
397
|
+
will be removed in the next major version.
|
|
398
|
+
:param custom_sampling_context: The transaction's custom sampling context.
|
|
399
|
+
:param kwargs: Optional keyword arguments to be passed to the Transaction
|
|
400
|
+
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
|
|
401
|
+
available arguments.
|
|
402
|
+
"""
|
|
403
|
+
return get_current_scope().start_transaction(
|
|
404
|
+
transaction, instrumenter, custom_sampling_context, **kwargs
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def set_measurement(name, value, unit=""):
|
|
409
|
+
# type: (str, float, MeasurementUnit) -> None
|
|
410
|
+
"""
|
|
411
|
+
.. deprecated:: 2.28.0
|
|
412
|
+
This function is deprecated and will be removed in the next major release.
|
|
413
|
+
"""
|
|
414
|
+
transaction = get_current_scope().transaction
|
|
415
|
+
if transaction is not None:
|
|
416
|
+
transaction.set_measurement(name, value, unit)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def get_current_span(scope=None):
|
|
420
|
+
# type: (Optional[Scope]) -> Optional[Span]
|
|
421
|
+
"""
|
|
422
|
+
Returns the currently active span if there is one running, otherwise `None`
|
|
423
|
+
"""
|
|
424
|
+
return tracing_utils.get_current_span(scope)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def get_traceparent():
|
|
428
|
+
# type: () -> Optional[str]
|
|
429
|
+
"""
|
|
430
|
+
Returns the traceparent either from the active span or from the scope.
|
|
431
|
+
"""
|
|
432
|
+
return get_current_scope().get_traceparent()
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def get_baggage():
|
|
135
436
|
# type: () -> Optional[str]
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
437
|
+
"""
|
|
438
|
+
Returns Baggage either from the active span or from the scope.
|
|
439
|
+
"""
|
|
440
|
+
baggage = get_current_scope().get_baggage()
|
|
441
|
+
if baggage is not None:
|
|
442
|
+
return baggage.serialize()
|
|
443
|
+
|
|
139
444
|
return None
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def continue_trace(
|
|
448
|
+
environ_or_headers, op=None, name=None, source=None, origin="manual"
|
|
449
|
+
):
|
|
450
|
+
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], str) -> Transaction
|
|
451
|
+
"""
|
|
452
|
+
Sets the propagation context from environment or headers and returns a transaction.
|
|
453
|
+
"""
|
|
454
|
+
return get_isolation_scope().continue_trace(
|
|
455
|
+
environ_or_headers, op, name, source, origin
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
@scopemethod
|
|
460
|
+
def start_session(
|
|
461
|
+
session_mode="application", # type: str
|
|
462
|
+
):
|
|
463
|
+
# type: (...) -> None
|
|
464
|
+
return get_isolation_scope().start_session(session_mode=session_mode)
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
@scopemethod
|
|
468
|
+
def end_session():
|
|
469
|
+
# type: () -> None
|
|
470
|
+
return get_isolation_scope().end_session()
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
@scopemethod
|
|
474
|
+
def set_transaction_name(name, source=None):
|
|
475
|
+
# type: (str, Optional[str]) -> None
|
|
476
|
+
return get_current_scope().set_transaction_name(name, source)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def update_current_span(op=None, name=None, attributes=None, data=None):
|
|
480
|
+
# type: (Optional[str], Optional[str], Optional[dict[str, Union[str, int, float, bool]]], Optional[dict[str, Any]]) -> None
|
|
481
|
+
"""
|
|
482
|
+
Update the current active span with the provided parameters.
|
|
483
|
+
|
|
484
|
+
This function allows you to modify properties of the currently active span.
|
|
485
|
+
If no span is currently active, this function will do nothing.
|
|
486
|
+
|
|
487
|
+
:param op: The operation name for the span. This is a high-level description
|
|
488
|
+
of what the span represents (e.g., "http.client", "db.query").
|
|
489
|
+
You can use predefined constants from :py:class:`sentry_sdk.consts.OP`
|
|
490
|
+
or provide your own string. If not provided, the span's operation will
|
|
491
|
+
remain unchanged.
|
|
492
|
+
:type op: str or None
|
|
493
|
+
|
|
494
|
+
:param name: The human-readable name/description for the span. This provides
|
|
495
|
+
more specific details about what the span represents (e.g., "GET /api/users",
|
|
496
|
+
"SELECT * FROM users"). If not provided, the span's name will remain unchanged.
|
|
497
|
+
:type name: str or None
|
|
498
|
+
|
|
499
|
+
:param data: A dictionary of key-value pairs to add as data to the span. This
|
|
500
|
+
data will be merged with any existing span data. If not provided,
|
|
501
|
+
no data will be added.
|
|
502
|
+
|
|
503
|
+
.. deprecated:: 2.35.0
|
|
504
|
+
Use ``attributes`` instead. The ``data`` parameter will be removed
|
|
505
|
+
in a future version.
|
|
506
|
+
:type data: dict[str, Union[str, int, float, bool]] or None
|
|
507
|
+
|
|
508
|
+
:param attributes: A dictionary of key-value pairs to add as attributes to the span.
|
|
509
|
+
Attribute values must be strings, integers, floats, or booleans. These
|
|
510
|
+
attributes will be merged with any existing span data. If not provided,
|
|
511
|
+
no attributes will be added.
|
|
512
|
+
:type attributes: dict[str, Union[str, int, float, bool]] or None
|
|
513
|
+
|
|
514
|
+
:returns: None
|
|
515
|
+
|
|
516
|
+
.. versionadded:: 2.35.0
|
|
517
|
+
|
|
518
|
+
Example::
|
|
519
|
+
|
|
520
|
+
import sentry_sdk
|
|
521
|
+
from sentry_sdk.consts import OP
|
|
522
|
+
|
|
523
|
+
sentry_sdk.update_current_span(
|
|
524
|
+
op=OP.FUNCTION,
|
|
525
|
+
name="process_user_data",
|
|
526
|
+
attributes={"user_id": 123, "batch_size": 50}
|
|
527
|
+
)
|
|
528
|
+
"""
|
|
529
|
+
current_span = get_current_span()
|
|
530
|
+
|
|
531
|
+
if current_span is None:
|
|
532
|
+
return
|
|
533
|
+
|
|
534
|
+
if op is not None:
|
|
535
|
+
current_span.op = op
|
|
536
|
+
|
|
537
|
+
if name is not None:
|
|
538
|
+
# internally it is still description
|
|
539
|
+
current_span.description = name
|
|
540
|
+
|
|
541
|
+
if data is not None and attributes is not None:
|
|
542
|
+
raise ValueError(
|
|
543
|
+
"Cannot provide both `data` and `attributes`. Please use only `attributes`."
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
if data is not None:
|
|
547
|
+
warnings.warn(
|
|
548
|
+
"The `data` parameter is deprecated. Please use `attributes` instead.",
|
|
549
|
+
DeprecationWarning,
|
|
550
|
+
stacklevel=2,
|
|
551
|
+
)
|
|
552
|
+
attributes = data
|
|
553
|
+
|
|
554
|
+
if attributes is not None:
|
|
555
|
+
current_span.update_data(attributes)
|