sentry-sdk 2.26.1__py2.py3-none-any.whl → 3.0.0a1__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.
Potentially problematic release.
This version of sentry-sdk might be problematic. Click here for more details.
- sentry_sdk/__init__.py +4 -8
- sentry_sdk/_compat.py +0 -1
- sentry_sdk/_init_implementation.py +6 -44
- sentry_sdk/_log_batcher.py +47 -28
- sentry_sdk/_types.py +8 -64
- sentry_sdk/ai/monitoring.py +14 -10
- sentry_sdk/ai/utils.py +1 -1
- sentry_sdk/api.py +69 -163
- sentry_sdk/client.py +25 -72
- sentry_sdk/consts.py +42 -23
- sentry_sdk/debug.py +0 -10
- sentry_sdk/envelope.py +2 -10
- sentry_sdk/feature_flags.py +5 -1
- sentry_sdk/integrations/__init__.py +5 -2
- sentry_sdk/integrations/_asgi_common.py +3 -3
- sentry_sdk/integrations/_wsgi_common.py +11 -40
- sentry_sdk/integrations/aiohttp.py +104 -57
- sentry_sdk/integrations/anthropic.py +10 -7
- sentry_sdk/integrations/arq.py +24 -13
- sentry_sdk/integrations/asgi.py +103 -83
- sentry_sdk/integrations/asyncio.py +1 -0
- sentry_sdk/integrations/asyncpg.py +45 -30
- sentry_sdk/integrations/aws_lambda.py +109 -92
- sentry_sdk/integrations/boto3.py +38 -9
- sentry_sdk/integrations/bottle.py +1 -1
- sentry_sdk/integrations/celery/__init__.py +48 -38
- sentry_sdk/integrations/clickhouse_driver.py +59 -28
- sentry_sdk/integrations/cohere.py +2 -0
- sentry_sdk/integrations/django/__init__.py +25 -46
- sentry_sdk/integrations/django/asgi.py +6 -2
- sentry_sdk/integrations/django/caching.py +13 -22
- sentry_sdk/integrations/django/middleware.py +1 -0
- sentry_sdk/integrations/django/signals_handlers.py +3 -1
- sentry_sdk/integrations/django/templates.py +8 -12
- sentry_sdk/integrations/django/transactions.py +1 -6
- sentry_sdk/integrations/django/views.py +5 -2
- sentry_sdk/integrations/falcon.py +7 -25
- sentry_sdk/integrations/fastapi.py +3 -3
- sentry_sdk/integrations/flask.py +1 -1
- sentry_sdk/integrations/gcp.py +63 -38
- sentry_sdk/integrations/graphene.py +6 -13
- sentry_sdk/integrations/grpc/aio/client.py +14 -8
- sentry_sdk/integrations/grpc/aio/server.py +19 -21
- sentry_sdk/integrations/grpc/client.py +8 -6
- sentry_sdk/integrations/grpc/server.py +12 -14
- sentry_sdk/integrations/httpx.py +47 -12
- sentry_sdk/integrations/huey.py +26 -22
- sentry_sdk/integrations/huggingface_hub.py +1 -0
- sentry_sdk/integrations/langchain.py +22 -15
- sentry_sdk/integrations/launchdarkly.py +3 -3
- sentry_sdk/integrations/litestar.py +4 -2
- sentry_sdk/integrations/logging.py +12 -3
- sentry_sdk/integrations/openai.py +2 -0
- sentry_sdk/integrations/openfeature.py +3 -5
- sentry_sdk/integrations/pymongo.py +18 -25
- sentry_sdk/integrations/pyramid.py +1 -1
- sentry_sdk/integrations/quart.py +3 -3
- sentry_sdk/integrations/ray.py +23 -17
- sentry_sdk/integrations/redis/_async_common.py +30 -18
- sentry_sdk/integrations/redis/_sync_common.py +28 -18
- sentry_sdk/integrations/redis/modules/caches.py +13 -10
- sentry_sdk/integrations/redis/modules/queries.py +14 -11
- sentry_sdk/integrations/redis/rb.py +4 -4
- sentry_sdk/integrations/redis/redis.py +6 -6
- sentry_sdk/integrations/redis/redis_cluster.py +18 -16
- sentry_sdk/integrations/redis/redis_py_cluster_legacy.py +4 -4
- sentry_sdk/integrations/redis/utils.py +63 -19
- sentry_sdk/integrations/rq.py +68 -23
- sentry_sdk/integrations/rust_tracing.py +28 -43
- sentry_sdk/integrations/sanic.py +23 -13
- sentry_sdk/integrations/socket.py +9 -5
- sentry_sdk/integrations/sqlalchemy.py +8 -8
- sentry_sdk/integrations/starlette.py +11 -31
- sentry_sdk/integrations/starlite.py +4 -2
- sentry_sdk/integrations/stdlib.py +56 -9
- sentry_sdk/integrations/strawberry.py +40 -59
- sentry_sdk/integrations/threading.py +10 -26
- sentry_sdk/integrations/tornado.py +57 -18
- sentry_sdk/integrations/trytond.py +4 -1
- sentry_sdk/integrations/unleash.py +2 -3
- sentry_sdk/integrations/wsgi.py +84 -38
- sentry_sdk/opentelemetry/__init__.py +9 -0
- sentry_sdk/opentelemetry/consts.py +33 -0
- sentry_sdk/opentelemetry/contextvars_context.py +73 -0
- sentry_sdk/{integrations/opentelemetry → opentelemetry}/propagator.py +19 -28
- sentry_sdk/opentelemetry/sampler.py +326 -0
- sentry_sdk/opentelemetry/scope.py +218 -0
- sentry_sdk/opentelemetry/span_processor.py +329 -0
- sentry_sdk/opentelemetry/tracing.py +35 -0
- sentry_sdk/opentelemetry/utils.py +476 -0
- sentry_sdk/profiler/__init__.py +0 -40
- sentry_sdk/profiler/continuous_profiler.py +1 -30
- sentry_sdk/profiler/transaction_profiler.py +5 -56
- sentry_sdk/scope.py +107 -351
- sentry_sdk/sessions.py +0 -87
- sentry_sdk/tracing.py +418 -1134
- sentry_sdk/tracing_utils.py +134 -169
- sentry_sdk/transport.py +4 -104
- sentry_sdk/types.py +26 -2
- sentry_sdk/utils.py +169 -152
- {sentry_sdk-2.26.1.dist-info → sentry_sdk-3.0.0a1.dist-info}/METADATA +3 -5
- sentry_sdk-3.0.0a1.dist-info/RECORD +154 -0
- {sentry_sdk-2.26.1.dist-info → sentry_sdk-3.0.0a1.dist-info}/WHEEL +1 -1
- sentry_sdk-3.0.0a1.dist-info/entry_points.txt +2 -0
- sentry_sdk/hub.py +0 -739
- sentry_sdk/integrations/opentelemetry/__init__.py +0 -7
- sentry_sdk/integrations/opentelemetry/consts.py +0 -5
- sentry_sdk/integrations/opentelemetry/integration.py +0 -58
- sentry_sdk/integrations/opentelemetry/span_processor.py +0 -391
- sentry_sdk/metrics.py +0 -965
- sentry_sdk-2.26.1.dist-info/RECORD +0 -152
- sentry_sdk-2.26.1.dist-info/entry_points.txt +0 -2
- {sentry_sdk-2.26.1.dist-info → sentry_sdk-3.0.0a1.dist-info}/licenses/LICENSE +0 -0
- {sentry_sdk-2.26.1.dist-info → sentry_sdk-3.0.0a1.dist-info}/top_level.txt +0 -0
sentry_sdk/api.py
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import inspect
|
|
2
|
-
import warnings
|
|
3
2
|
from contextlib import contextmanager
|
|
4
3
|
|
|
5
4
|
from sentry_sdk import tracing_utils, Client
|
|
6
5
|
from sentry_sdk._init_implementation import init
|
|
7
|
-
from sentry_sdk.
|
|
8
|
-
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
|
|
9
|
-
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
|
|
6
|
+
from sentry_sdk.tracing import trace
|
|
10
7
|
from sentry_sdk.crons import monitor
|
|
11
8
|
|
|
9
|
+
# TODO-neel-potel make 2 scope strategies/impls and switch
|
|
10
|
+
from sentry_sdk.scope import Scope as BaseScope
|
|
11
|
+
from sentry_sdk.opentelemetry.scope import (
|
|
12
|
+
PotelScope as Scope,
|
|
13
|
+
new_scope,
|
|
14
|
+
isolation_scope,
|
|
15
|
+
use_scope,
|
|
16
|
+
use_isolation_scope,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
12
20
|
from typing import TYPE_CHECKING
|
|
13
21
|
|
|
14
22
|
if TYPE_CHECKING:
|
|
@@ -16,46 +24,26 @@ if TYPE_CHECKING:
|
|
|
16
24
|
|
|
17
25
|
from typing import Any
|
|
18
26
|
from typing import Dict
|
|
19
|
-
from typing import Generator
|
|
20
27
|
from typing import Optional
|
|
21
|
-
from typing import overload
|
|
22
28
|
from typing import Callable
|
|
23
29
|
from typing import TypeVar
|
|
24
|
-
from typing import ContextManager
|
|
25
30
|
from typing import Union
|
|
31
|
+
from typing import Generator
|
|
26
32
|
|
|
27
|
-
|
|
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
|
|
33
|
+
import sentry_sdk
|
|
41
34
|
|
|
42
35
|
T = TypeVar("T")
|
|
43
36
|
F = TypeVar("F", bound=Callable[..., Any])
|
|
44
|
-
else:
|
|
45
|
-
|
|
46
|
-
def overload(x):
|
|
47
|
-
# type: (T) -> T
|
|
48
|
-
return x
|
|
49
37
|
|
|
50
38
|
|
|
51
39
|
# When changing this, update __all__ in __init__.py too
|
|
52
40
|
__all__ = [
|
|
53
41
|
"init",
|
|
42
|
+
"add_attachment",
|
|
54
43
|
"add_breadcrumb",
|
|
55
44
|
"capture_event",
|
|
56
45
|
"capture_exception",
|
|
57
46
|
"capture_message",
|
|
58
|
-
"configure_scope",
|
|
59
47
|
"continue_trace",
|
|
60
48
|
"flush",
|
|
61
49
|
"get_baggage",
|
|
@@ -69,11 +57,9 @@ __all__ = [
|
|
|
69
57
|
"isolation_scope",
|
|
70
58
|
"last_event_id",
|
|
71
59
|
"new_scope",
|
|
72
|
-
"push_scope",
|
|
73
60
|
"set_context",
|
|
74
61
|
"set_extra",
|
|
75
62
|
"set_level",
|
|
76
|
-
"set_measurement",
|
|
77
63
|
"set_tag",
|
|
78
64
|
"set_tags",
|
|
79
65
|
"set_user",
|
|
@@ -81,6 +67,8 @@ __all__ = [
|
|
|
81
67
|
"start_transaction",
|
|
82
68
|
"trace",
|
|
83
69
|
"monitor",
|
|
70
|
+
"use_scope",
|
|
71
|
+
"use_isolation_scope",
|
|
84
72
|
]
|
|
85
73
|
|
|
86
74
|
|
|
@@ -104,7 +92,7 @@ def clientmethod(f):
|
|
|
104
92
|
|
|
105
93
|
@scopemethod
|
|
106
94
|
def get_client():
|
|
107
|
-
# type: () -> BaseClient
|
|
95
|
+
# type: () -> sentry_sdk.client.BaseClient
|
|
108
96
|
return Scope.get_client()
|
|
109
97
|
|
|
110
98
|
|
|
@@ -124,7 +112,7 @@ def is_initialized():
|
|
|
124
112
|
|
|
125
113
|
@scopemethod
|
|
126
114
|
def get_global_scope():
|
|
127
|
-
# type: () ->
|
|
115
|
+
# type: () -> BaseScope
|
|
128
116
|
return Scope.get_global_scope()
|
|
129
117
|
|
|
130
118
|
|
|
@@ -152,8 +140,8 @@ def last_event_id():
|
|
|
152
140
|
|
|
153
141
|
@scopemethod
|
|
154
142
|
def capture_event(
|
|
155
|
-
event, # type: Event
|
|
156
|
-
hint=None, # type: Optional[Hint]
|
|
143
|
+
event, # type: sentry_sdk._types.Event
|
|
144
|
+
hint=None, # type: Optional[sentry_sdk._types.Hint]
|
|
157
145
|
scope=None, # type: Optional[Any]
|
|
158
146
|
**scope_kwargs, # type: Any
|
|
159
147
|
):
|
|
@@ -164,7 +152,7 @@ def capture_event(
|
|
|
164
152
|
@scopemethod
|
|
165
153
|
def capture_message(
|
|
166
154
|
message, # type: str
|
|
167
|
-
level=None, # type: Optional[LogLevelStr]
|
|
155
|
+
level=None, # type: Optional[sentry_sdk._types.LogLevelStr]
|
|
168
156
|
scope=None, # type: Optional[Any]
|
|
169
157
|
**scope_kwargs, # type: Any
|
|
170
158
|
):
|
|
@@ -176,7 +164,7 @@ def capture_message(
|
|
|
176
164
|
|
|
177
165
|
@scopemethod
|
|
178
166
|
def capture_exception(
|
|
179
|
-
error=None, # type: Optional[Union[BaseException, ExcInfo]]
|
|
167
|
+
error=None, # type: Optional[Union[BaseException, sentry_sdk._types.ExcInfo]]
|
|
180
168
|
scope=None, # type: Optional[Any]
|
|
181
169
|
**scope_kwargs, # type: Any
|
|
182
170
|
):
|
|
@@ -185,108 +173,27 @@ def capture_exception(
|
|
|
185
173
|
|
|
186
174
|
|
|
187
175
|
@scopemethod
|
|
188
|
-
def
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
# type:
|
|
194
|
-
return get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
@overload
|
|
198
|
-
def configure_scope():
|
|
199
|
-
# type: () -> ContextManager[Scope]
|
|
200
|
-
pass
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
@overload
|
|
204
|
-
def configure_scope( # noqa: F811
|
|
205
|
-
callback, # type: Callable[[Scope], None]
|
|
176
|
+
def add_attachment(
|
|
177
|
+
bytes=None, # type: Union[None, bytes, Callable[[], bytes]]
|
|
178
|
+
filename=None, # type: Optional[str]
|
|
179
|
+
path=None, # type: Optional[str]
|
|
180
|
+
content_type=None, # type: Optional[str]
|
|
181
|
+
add_to_transactions=False, # type: bool
|
|
206
182
|
):
|
|
207
183
|
# type: (...) -> None
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def configure_scope( # noqa: F811
|
|
212
|
-
callback=None, # type: Optional[Callable[[Scope], None]]
|
|
213
|
-
):
|
|
214
|
-
# type: (...) -> Optional[ContextManager[Scope]]
|
|
215
|
-
"""
|
|
216
|
-
Reconfigures the scope.
|
|
217
|
-
|
|
218
|
-
:param callback: If provided, call the callback with the current scope.
|
|
219
|
-
|
|
220
|
-
:returns: If no callback is provided, returns a context manager that returns the scope.
|
|
221
|
-
"""
|
|
222
|
-
warnings.warn(
|
|
223
|
-
"sentry_sdk.configure_scope is deprecated and will be removed in the next major version. "
|
|
224
|
-
"Please consult our migration guide to learn how to migrate to the new API: "
|
|
225
|
-
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-configuring",
|
|
226
|
-
DeprecationWarning,
|
|
227
|
-
stacklevel=2,
|
|
184
|
+
return get_isolation_scope().add_attachment(
|
|
185
|
+
bytes, filename, path, content_type, add_to_transactions
|
|
228
186
|
)
|
|
229
187
|
|
|
230
|
-
scope = get_isolation_scope()
|
|
231
|
-
scope.generate_propagation_context()
|
|
232
|
-
|
|
233
|
-
if callback is not None:
|
|
234
|
-
# TODO: used to return None when client is None. Check if this changes behavior.
|
|
235
|
-
callback(scope)
|
|
236
|
-
|
|
237
|
-
return None
|
|
238
|
-
|
|
239
|
-
@contextmanager
|
|
240
|
-
def inner():
|
|
241
|
-
# type: () -> Generator[Scope, None, None]
|
|
242
|
-
yield scope
|
|
243
|
-
|
|
244
|
-
return inner()
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
@overload
|
|
248
|
-
def push_scope():
|
|
249
|
-
# type: () -> ContextManager[Scope]
|
|
250
|
-
pass
|
|
251
|
-
|
|
252
188
|
|
|
253
|
-
@
|
|
254
|
-
def
|
|
255
|
-
|
|
189
|
+
@scopemethod
|
|
190
|
+
def add_breadcrumb(
|
|
191
|
+
crumb=None, # type: Optional[sentry_sdk._types.Breadcrumb]
|
|
192
|
+
hint=None, # type: Optional[sentry_sdk._types.BreadcrumbHint]
|
|
193
|
+
**kwargs, # type: Any
|
|
256
194
|
):
|
|
257
195
|
# type: (...) -> None
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
def push_scope( # noqa: F811
|
|
262
|
-
callback=None, # type: Optional[Callable[[Scope], None]]
|
|
263
|
-
):
|
|
264
|
-
# type: (...) -> Optional[ContextManager[Scope]]
|
|
265
|
-
"""
|
|
266
|
-
Pushes a new layer on the scope stack.
|
|
267
|
-
|
|
268
|
-
:param callback: If provided, this method pushes a scope, calls
|
|
269
|
-
`callback`, and pops the scope again.
|
|
270
|
-
|
|
271
|
-
:returns: If no `callback` is provided, a context manager that should
|
|
272
|
-
be used to pop the scope again.
|
|
273
|
-
"""
|
|
274
|
-
warnings.warn(
|
|
275
|
-
"sentry_sdk.push_scope is deprecated and will be removed in the next major version. "
|
|
276
|
-
"Please consult our migration guide to learn how to migrate to the new API: "
|
|
277
|
-
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-pushing",
|
|
278
|
-
DeprecationWarning,
|
|
279
|
-
stacklevel=2,
|
|
280
|
-
)
|
|
281
|
-
|
|
282
|
-
if callback is not None:
|
|
283
|
-
with warnings.catch_warnings():
|
|
284
|
-
warnings.simplefilter("ignore", DeprecationWarning)
|
|
285
|
-
with push_scope() as scope:
|
|
286
|
-
callback(scope)
|
|
287
|
-
return None
|
|
288
|
-
|
|
289
|
-
return _ScopeManager()
|
|
196
|
+
return get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
|
|
290
197
|
|
|
291
198
|
|
|
292
199
|
@scopemethod
|
|
@@ -321,7 +228,7 @@ def set_user(value):
|
|
|
321
228
|
|
|
322
229
|
@scopemethod
|
|
323
230
|
def set_level(value):
|
|
324
|
-
# type: (LogLevelStr) -> None
|
|
231
|
+
# type: (sentry_sdk._types.LogLevelStr) -> None
|
|
325
232
|
return get_isolation_scope().set_level(value)
|
|
326
233
|
|
|
327
234
|
|
|
@@ -334,23 +241,33 @@ def flush(
|
|
|
334
241
|
return get_client().flush(timeout=timeout, callback=callback)
|
|
335
242
|
|
|
336
243
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
244
|
+
def start_span(**kwargs):
|
|
245
|
+
# type: (Any) -> sentry_sdk.tracing.Span
|
|
246
|
+
"""
|
|
247
|
+
Start and return a span.
|
|
248
|
+
|
|
249
|
+
This is the entry point to manual tracing instrumentation.
|
|
250
|
+
|
|
251
|
+
A tree structure can be built by adding child spans to the span.
|
|
252
|
+
To start a new child span within the span, call the `start_child()` method.
|
|
253
|
+
|
|
254
|
+
When used as a context manager, spans are automatically finished at the end
|
|
255
|
+
of the `with` block. If not using context managers, call the `finish()`
|
|
256
|
+
method.
|
|
257
|
+
"""
|
|
342
258
|
return get_current_scope().start_span(**kwargs)
|
|
343
259
|
|
|
344
260
|
|
|
345
|
-
@scopemethod
|
|
346
261
|
def start_transaction(
|
|
347
|
-
transaction=None, # type: Optional[
|
|
348
|
-
|
|
349
|
-
custom_sampling_context=None, # type: Optional[SamplingContext]
|
|
350
|
-
**kwargs, # type: Unpack[TransactionKwargs]
|
|
262
|
+
transaction=None, # type: Optional[sentry_sdk.tracing.Span]
|
|
263
|
+
**kwargs, # type: Any
|
|
351
264
|
):
|
|
352
|
-
# type: (...) ->
|
|
265
|
+
# type: (...) -> sentry_sdk.tracing.Span
|
|
353
266
|
"""
|
|
267
|
+
.. deprecated:: 3.0.0
|
|
268
|
+
This function is deprecated and will be removed in a future release.
|
|
269
|
+
Use :py:meth:`sentry_sdk.start_span` instead.
|
|
270
|
+
|
|
354
271
|
Start and return a transaction on the current scope.
|
|
355
272
|
|
|
356
273
|
Start an existing transaction if given, otherwise create and start a new
|
|
@@ -374,27 +291,18 @@ def start_transaction(
|
|
|
374
291
|
|
|
375
292
|
:param transaction: The transaction to start. If omitted, we create and
|
|
376
293
|
start a new transaction.
|
|
377
|
-
:param instrumenter: This parameter is meant for internal use only. It
|
|
378
|
-
will be removed in the next major version.
|
|
379
|
-
:param custom_sampling_context: The transaction's custom sampling context.
|
|
380
294
|
:param kwargs: Optional keyword arguments to be passed to the Transaction
|
|
381
295
|
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
|
|
382
296
|
available arguments.
|
|
383
297
|
"""
|
|
384
|
-
return
|
|
385
|
-
transaction,
|
|
298
|
+
return start_span(
|
|
299
|
+
span=transaction,
|
|
300
|
+
**kwargs,
|
|
386
301
|
)
|
|
387
302
|
|
|
388
303
|
|
|
389
|
-
def set_measurement(name, value, unit=""):
|
|
390
|
-
# type: (str, float, MeasurementUnit) -> None
|
|
391
|
-
transaction = get_current_scope().transaction
|
|
392
|
-
if transaction is not None:
|
|
393
|
-
transaction.set_measurement(name, value, unit)
|
|
394
|
-
|
|
395
|
-
|
|
396
304
|
def get_current_span(scope=None):
|
|
397
|
-
# type: (Optional[Scope]) -> Optional[Span]
|
|
305
|
+
# type: (Optional[Scope]) -> Optional[sentry_sdk.tracing.Span]
|
|
398
306
|
"""
|
|
399
307
|
Returns the currently active span if there is one running, otherwise `None`
|
|
400
308
|
"""
|
|
@@ -421,13 +329,11 @@ def get_baggage():
|
|
|
421
329
|
return None
|
|
422
330
|
|
|
423
331
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
)
|
|
427
|
-
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], str) -> Transaction
|
|
332
|
+
@contextmanager
|
|
333
|
+
def continue_trace(environ_or_headers):
|
|
334
|
+
# type: (Dict[str, Any]) -> Generator[None, None, None]
|
|
428
335
|
"""
|
|
429
|
-
Sets the propagation context from environment or headers
|
|
336
|
+
Sets the propagation context from environment or headers to continue an incoming trace.
|
|
430
337
|
"""
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
)
|
|
338
|
+
with get_isolation_scope().continue_trace(environ_or_headers):
|
|
339
|
+
yield
|
sentry_sdk/client.py
CHANGED
|
@@ -6,9 +6,8 @@ from collections.abc import Mapping
|
|
|
6
6
|
from datetime import datetime, timezone
|
|
7
7
|
from importlib import import_module
|
|
8
8
|
from typing import TYPE_CHECKING, List, Dict, cast, overload
|
|
9
|
-
import warnings
|
|
10
9
|
|
|
11
|
-
from sentry_sdk._compat import
|
|
10
|
+
from sentry_sdk._compat import check_uwsgi_thread_support
|
|
12
11
|
from sentry_sdk.utils import (
|
|
13
12
|
AnnotatedValue,
|
|
14
13
|
ContextVar,
|
|
@@ -20,7 +19,6 @@ from sentry_sdk.utils import (
|
|
|
20
19
|
get_type_name,
|
|
21
20
|
get_default_release,
|
|
22
21
|
handle_in_app,
|
|
23
|
-
is_gevent,
|
|
24
22
|
logger,
|
|
25
23
|
)
|
|
26
24
|
from sentry_sdk.serializer import serialize
|
|
@@ -30,14 +28,14 @@ from sentry_sdk.consts import (
|
|
|
30
28
|
SPANDATA,
|
|
31
29
|
DEFAULT_MAX_VALUE_LENGTH,
|
|
32
30
|
DEFAULT_OPTIONS,
|
|
33
|
-
INSTRUMENTER,
|
|
34
31
|
VERSION,
|
|
35
32
|
ClientConstructor,
|
|
36
33
|
)
|
|
37
|
-
from sentry_sdk.integrations import
|
|
34
|
+
from sentry_sdk.integrations import setup_integrations
|
|
38
35
|
from sentry_sdk.integrations.dedupe import DedupeIntegration
|
|
39
36
|
from sentry_sdk.sessions import SessionFlusher
|
|
40
37
|
from sentry_sdk.envelope import Envelope
|
|
38
|
+
|
|
41
39
|
from sentry_sdk.profiler.continuous_profiler import setup_continuous_profiler
|
|
42
40
|
from sentry_sdk.profiler.transaction_profiler import (
|
|
43
41
|
has_profiling_enabled,
|
|
@@ -59,7 +57,6 @@ if TYPE_CHECKING:
|
|
|
59
57
|
|
|
60
58
|
from sentry_sdk._types import Event, Hint, SDKInfo, Log
|
|
61
59
|
from sentry_sdk.integrations import Integration
|
|
62
|
-
from sentry_sdk.metrics import MetricsAggregator
|
|
63
60
|
from sentry_sdk.scope import Scope
|
|
64
61
|
from sentry_sdk.session import Session
|
|
65
62
|
from sentry_sdk.spotlight import SpotlightClient
|
|
@@ -115,9 +112,6 @@ def _get_options(*args, **kwargs):
|
|
|
115
112
|
if rv["server_name"] is None and hasattr(socket, "gethostname"):
|
|
116
113
|
rv["server_name"] = socket.gethostname()
|
|
117
114
|
|
|
118
|
-
if rv["instrumenter"] is None:
|
|
119
|
-
rv["instrumenter"] = INSTRUMENTER.SENTRY
|
|
120
|
-
|
|
121
115
|
if rv["project_root"] is None:
|
|
122
116
|
try:
|
|
123
117
|
project_root = os.getcwd()
|
|
@@ -126,9 +120,6 @@ def _get_options(*args, **kwargs):
|
|
|
126
120
|
|
|
127
121
|
rv["project_root"] = project_root
|
|
128
122
|
|
|
129
|
-
if rv["enable_tracing"] is True and rv["traces_sample_rate"] is None:
|
|
130
|
-
rv["traces_sample_rate"] = 1.0
|
|
131
|
-
|
|
132
123
|
if rv["event_scrubber"] is None:
|
|
133
124
|
rv["event_scrubber"] = EventScrubber(
|
|
134
125
|
send_default_pii=(
|
|
@@ -142,24 +133,9 @@ def _get_options(*args, **kwargs):
|
|
|
142
133
|
)
|
|
143
134
|
rv["socket_options"] = None
|
|
144
135
|
|
|
145
|
-
if rv["enable_tracing"] is not None:
|
|
146
|
-
warnings.warn(
|
|
147
|
-
"The `enable_tracing` parameter is deprecated. Please use `traces_sample_rate` instead.",
|
|
148
|
-
DeprecationWarning,
|
|
149
|
-
stacklevel=2,
|
|
150
|
-
)
|
|
151
|
-
|
|
152
136
|
return rv
|
|
153
137
|
|
|
154
138
|
|
|
155
|
-
try:
|
|
156
|
-
# Python 3.6+
|
|
157
|
-
module_not_found_error = ModuleNotFoundError
|
|
158
|
-
except Exception:
|
|
159
|
-
# Older Python versions
|
|
160
|
-
module_not_found_error = ImportError # type: ignore
|
|
161
|
-
|
|
162
|
-
|
|
163
139
|
class BaseClient:
|
|
164
140
|
"""
|
|
165
141
|
.. versionadded:: 2.0.0
|
|
@@ -177,7 +153,6 @@ class BaseClient:
|
|
|
177
153
|
|
|
178
154
|
self.transport = None # type: Optional[Transport]
|
|
179
155
|
self.monitor = None # type: Optional[Monitor]
|
|
180
|
-
self.metrics_aggregator = None # type: Optional[MetricsAggregator]
|
|
181
156
|
self.log_batcher = None # type: Optional[LogBatcher]
|
|
182
157
|
|
|
183
158
|
def __getstate__(self, *args, **kwargs):
|
|
@@ -303,7 +278,7 @@ class _Client(BaseClient):
|
|
|
303
278
|
function_obj = getattr(module_obj, function_name)
|
|
304
279
|
setattr(module_obj, function_name, trace(function_obj))
|
|
305
280
|
logger.debug("Enabled tracing for %s", function_qualname)
|
|
306
|
-
except
|
|
281
|
+
except ModuleNotFoundError:
|
|
307
282
|
try:
|
|
308
283
|
# Try to import a class
|
|
309
284
|
# ex: "mymodule.submodule.MyClassName.member_function"
|
|
@@ -356,26 +331,7 @@ class _Client(BaseClient):
|
|
|
356
331
|
|
|
357
332
|
self.session_flusher = SessionFlusher(capture_func=_capture_envelope)
|
|
358
333
|
|
|
359
|
-
self.metrics_aggregator = None # type: Optional[MetricsAggregator]
|
|
360
334
|
experiments = self.options.get("_experiments", {})
|
|
361
|
-
if experiments.get("enable_metrics", True):
|
|
362
|
-
# Context vars are not working correctly on Python <=3.6
|
|
363
|
-
# with gevent.
|
|
364
|
-
metrics_supported = not is_gevent() or PY37
|
|
365
|
-
if metrics_supported:
|
|
366
|
-
from sentry_sdk.metrics import MetricsAggregator
|
|
367
|
-
|
|
368
|
-
self.metrics_aggregator = MetricsAggregator(
|
|
369
|
-
capture_func=_capture_envelope,
|
|
370
|
-
enable_code_locations=bool(
|
|
371
|
-
experiments.get("metric_code_locations", True)
|
|
372
|
-
),
|
|
373
|
-
)
|
|
374
|
-
else:
|
|
375
|
-
logger.info(
|
|
376
|
-
"Metrics not supported on Python 3.6 and lower with gevent."
|
|
377
|
-
)
|
|
378
|
-
|
|
379
335
|
self.log_batcher = None
|
|
380
336
|
if experiments.get("enable_logs", False):
|
|
381
337
|
from sentry_sdk._log_batcher import LogBatcher
|
|
@@ -390,19 +346,6 @@ class _Client(BaseClient):
|
|
|
390
346
|
)
|
|
391
347
|
)
|
|
392
348
|
|
|
393
|
-
if self.options["_experiments"].get("otel_powered_performance", False):
|
|
394
|
-
logger.debug(
|
|
395
|
-
"[OTel] Enabling experimental OTel-powered performance monitoring."
|
|
396
|
-
)
|
|
397
|
-
self.options["instrumenter"] = INSTRUMENTER.OTEL
|
|
398
|
-
if (
|
|
399
|
-
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration"
|
|
400
|
-
not in _DEFAULT_INTEGRATIONS
|
|
401
|
-
):
|
|
402
|
-
_DEFAULT_INTEGRATIONS.append(
|
|
403
|
-
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration",
|
|
404
|
-
)
|
|
405
|
-
|
|
406
349
|
self.integrations = setup_integrations(
|
|
407
350
|
self.options["integrations"],
|
|
408
351
|
with_defaults=self.options["default_integrations"],
|
|
@@ -450,6 +393,13 @@ class _Client(BaseClient):
|
|
|
450
393
|
except Exception as e:
|
|
451
394
|
logger.debug("Can not set up continuous profiler. (%s)", e)
|
|
452
395
|
|
|
396
|
+
from sentry_sdk.opentelemetry.tracing import (
|
|
397
|
+
patch_readable_span,
|
|
398
|
+
setup_sentry_tracing,
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
patch_readable_span()
|
|
402
|
+
setup_sentry_tracing()
|
|
453
403
|
finally:
|
|
454
404
|
_client_init_debug.set(old_debug)
|
|
455
405
|
|
|
@@ -457,7 +407,6 @@ class _Client(BaseClient):
|
|
|
457
407
|
|
|
458
408
|
if (
|
|
459
409
|
self.monitor
|
|
460
|
-
or self.metrics_aggregator
|
|
461
410
|
or self.log_batcher
|
|
462
411
|
or has_profiling_enabled(self.options)
|
|
463
412
|
or isinstance(self.transport, BaseHttpTransport)
|
|
@@ -524,7 +473,7 @@ class _Client(BaseClient):
|
|
|
524
473
|
)
|
|
525
474
|
return None
|
|
526
475
|
|
|
527
|
-
event = event_
|
|
476
|
+
event = event_ # type: Optional[Event] # type: ignore[no-redef]
|
|
528
477
|
spans_delta = spans_before - len(
|
|
529
478
|
cast(List[Dict[str, object]], event.get("spans", []))
|
|
530
479
|
)
|
|
@@ -621,7 +570,7 @@ class _Client(BaseClient):
|
|
|
621
570
|
and event is not None
|
|
622
571
|
and event.get("type") != "transaction"
|
|
623
572
|
):
|
|
624
|
-
new_event = None
|
|
573
|
+
new_event = None # type: Optional[Event]
|
|
625
574
|
with capture_internal_exceptions():
|
|
626
575
|
new_event = before_send(event, hint or {})
|
|
627
576
|
if new_event is None:
|
|
@@ -638,7 +587,7 @@ class _Client(BaseClient):
|
|
|
638
587
|
if event.get("exception"):
|
|
639
588
|
DedupeIntegration.reset_last_seen()
|
|
640
589
|
|
|
641
|
-
event = new_event
|
|
590
|
+
event = new_event # type: Optional[Event] # type: ignore[no-redef]
|
|
642
591
|
|
|
643
592
|
before_send_transaction = self.options["before_send_transaction"]
|
|
644
593
|
if (
|
|
@@ -662,13 +611,15 @@ class _Client(BaseClient):
|
|
|
662
611
|
quantity=spans_before + 1, # +1 for the transaction itself
|
|
663
612
|
)
|
|
664
613
|
else:
|
|
665
|
-
spans_delta = spans_before - len(
|
|
614
|
+
spans_delta = spans_before - len(
|
|
615
|
+
cast(List[Dict[str, object]], new_event.get("spans", []))
|
|
616
|
+
)
|
|
666
617
|
if spans_delta > 0 and self.transport is not None:
|
|
667
618
|
self.transport.record_lost_event(
|
|
668
619
|
reason="before_send", data_category="span", quantity=spans_delta
|
|
669
620
|
)
|
|
670
621
|
|
|
671
|
-
event = new_event
|
|
622
|
+
event = new_event # type: Optional[Event] # type: ignore[no-redef]
|
|
672
623
|
|
|
673
624
|
return event
|
|
674
625
|
|
|
@@ -915,7 +866,7 @@ class _Client(BaseClient):
|
|
|
915
866
|
log["attributes"]["sentry.trace.parent_span_id"] = span.span_id
|
|
916
867
|
|
|
917
868
|
if log.get("trace_id") is None:
|
|
918
|
-
transaction = current_scope.
|
|
869
|
+
transaction = current_scope.root_span
|
|
919
870
|
propagation_context = isolation_scope.get_active_propagation_context()
|
|
920
871
|
if transaction is not None:
|
|
921
872
|
log["trace_id"] = transaction.trace_id
|
|
@@ -987,13 +938,15 @@ class _Client(BaseClient):
|
|
|
987
938
|
"""
|
|
988
939
|
if self.transport is not None:
|
|
989
940
|
self.flush(timeout=timeout, callback=callback)
|
|
941
|
+
|
|
990
942
|
self.session_flusher.kill()
|
|
991
|
-
|
|
992
|
-
self.metrics_aggregator.kill()
|
|
943
|
+
|
|
993
944
|
if self.log_batcher is not None:
|
|
994
945
|
self.log_batcher.kill()
|
|
946
|
+
|
|
995
947
|
if self.monitor:
|
|
996
948
|
self.monitor.kill()
|
|
949
|
+
|
|
997
950
|
self.transport.kill()
|
|
998
951
|
self.transport = None
|
|
999
952
|
|
|
@@ -1014,10 +967,10 @@ class _Client(BaseClient):
|
|
|
1014
967
|
if timeout is None:
|
|
1015
968
|
timeout = self.options["shutdown_timeout"]
|
|
1016
969
|
self.session_flusher.flush()
|
|
1017
|
-
|
|
1018
|
-
self.metrics_aggregator.flush()
|
|
970
|
+
|
|
1019
971
|
if self.log_batcher is not None:
|
|
1020
972
|
self.log_batcher.flush()
|
|
973
|
+
|
|
1021
974
|
self.transport.flush(timeout=timeout, callback=callback)
|
|
1022
975
|
|
|
1023
976
|
def __enter__(self):
|