sentry-sdk 3.0.0a2__py2.py3-none-any.whl → 3.0.0a4__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 -0
- sentry_sdk/_compat.py +5 -12
- sentry_sdk/_init_implementation.py +7 -7
- sentry_sdk/_log_batcher.py +17 -29
- sentry_sdk/_lru_cache.py +7 -9
- sentry_sdk/_queue.py +2 -4
- sentry_sdk/_types.py +9 -16
- sentry_sdk/_werkzeug.py +5 -7
- sentry_sdk/ai/monitoring.py +45 -33
- sentry_sdk/ai/utils.py +8 -5
- sentry_sdk/api.py +91 -87
- sentry_sdk/attachments.py +10 -12
- sentry_sdk/client.py +119 -159
- sentry_sdk/consts.py +432 -223
- sentry_sdk/crons/api.py +16 -17
- sentry_sdk/crons/decorator.py +25 -27
- sentry_sdk/debug.py +4 -6
- sentry_sdk/envelope.py +46 -112
- sentry_sdk/feature_flags.py +9 -15
- sentry_sdk/integrations/__init__.py +24 -19
- sentry_sdk/integrations/_asgi_common.py +16 -18
- sentry_sdk/integrations/_wsgi_common.py +22 -33
- sentry_sdk/integrations/aiohttp.py +33 -31
- sentry_sdk/integrations/anthropic.py +43 -38
- sentry_sdk/integrations/argv.py +3 -4
- sentry_sdk/integrations/ariadne.py +16 -18
- sentry_sdk/integrations/arq.py +20 -29
- sentry_sdk/integrations/asgi.py +63 -37
- sentry_sdk/integrations/asyncio.py +15 -17
- sentry_sdk/integrations/asyncpg.py +1 -1
- sentry_sdk/integrations/atexit.py +6 -10
- sentry_sdk/integrations/aws_lambda.py +26 -36
- sentry_sdk/integrations/beam.py +10 -18
- sentry_sdk/integrations/boto3.py +20 -18
- sentry_sdk/integrations/bottle.py +25 -34
- sentry_sdk/integrations/celery/__init__.py +40 -59
- sentry_sdk/integrations/celery/beat.py +22 -26
- sentry_sdk/integrations/celery/utils.py +15 -17
- sentry_sdk/integrations/chalice.py +8 -10
- sentry_sdk/integrations/clickhouse_driver.py +22 -32
- sentry_sdk/integrations/cloud_resource_context.py +9 -16
- sentry_sdk/integrations/cohere.py +19 -25
- sentry_sdk/integrations/dedupe.py +5 -8
- sentry_sdk/integrations/django/__init__.py +69 -74
- sentry_sdk/integrations/django/asgi.py +25 -33
- sentry_sdk/integrations/django/caching.py +24 -20
- sentry_sdk/integrations/django/middleware.py +18 -21
- sentry_sdk/integrations/django/signals_handlers.py +12 -11
- sentry_sdk/integrations/django/templates.py +21 -18
- sentry_sdk/integrations/django/transactions.py +16 -11
- sentry_sdk/integrations/django/views.py +8 -12
- sentry_sdk/integrations/dramatiq.py +21 -21
- sentry_sdk/integrations/excepthook.py +10 -10
- sentry_sdk/integrations/executing.py +3 -4
- sentry_sdk/integrations/falcon.py +27 -42
- sentry_sdk/integrations/fastapi.py +13 -16
- sentry_sdk/integrations/flask.py +31 -38
- sentry_sdk/integrations/gcp.py +13 -16
- sentry_sdk/integrations/gnu_backtrace.py +7 -20
- sentry_sdk/integrations/gql.py +16 -17
- sentry_sdk/integrations/graphene.py +14 -13
- sentry_sdk/integrations/grpc/__init__.py +3 -2
- sentry_sdk/integrations/grpc/aio/client.py +2 -2
- sentry_sdk/integrations/grpc/aio/server.py +15 -14
- sentry_sdk/integrations/grpc/client.py +21 -11
- sentry_sdk/integrations/grpc/consts.py +2 -0
- sentry_sdk/integrations/grpc/server.py +12 -8
- sentry_sdk/integrations/httpx.py +11 -14
- sentry_sdk/integrations/huey.py +14 -21
- sentry_sdk/integrations/huggingface_hub.py +17 -17
- sentry_sdk/integrations/langchain.py +204 -114
- sentry_sdk/integrations/launchdarkly.py +13 -10
- sentry_sdk/integrations/litestar.py +40 -38
- sentry_sdk/integrations/logging.py +29 -36
- sentry_sdk/integrations/loguru.py +16 -20
- sentry_sdk/integrations/modules.py +3 -4
- sentry_sdk/integrations/openai.py +421 -204
- sentry_sdk/integrations/openai_agents/__init__.py +49 -0
- sentry_sdk/integrations/openai_agents/consts.py +1 -0
- sentry_sdk/integrations/openai_agents/patches/__init__.py +4 -0
- sentry_sdk/integrations/openai_agents/patches/agent_run.py +152 -0
- sentry_sdk/integrations/openai_agents/patches/models.py +52 -0
- sentry_sdk/integrations/openai_agents/patches/runner.py +42 -0
- sentry_sdk/integrations/openai_agents/patches/tools.py +84 -0
- sentry_sdk/integrations/openai_agents/spans/__init__.py +5 -0
- sentry_sdk/integrations/openai_agents/spans/agent_workflow.py +20 -0
- sentry_sdk/integrations/openai_agents/spans/ai_client.py +46 -0
- sentry_sdk/integrations/openai_agents/spans/execute_tool.py +47 -0
- sentry_sdk/integrations/openai_agents/spans/handoff.py +24 -0
- sentry_sdk/integrations/openai_agents/spans/invoke_agent.py +41 -0
- sentry_sdk/integrations/openai_agents/utils.py +153 -0
- sentry_sdk/integrations/openfeature.py +12 -8
- sentry_sdk/integrations/pure_eval.py +6 -10
- sentry_sdk/integrations/pymongo.py +14 -18
- sentry_sdk/integrations/pyramid.py +31 -36
- sentry_sdk/integrations/quart.py +23 -28
- sentry_sdk/integrations/ray.py +73 -64
- sentry_sdk/integrations/redis/__init__.py +7 -4
- sentry_sdk/integrations/redis/_async_common.py +18 -12
- sentry_sdk/integrations/redis/_sync_common.py +16 -15
- sentry_sdk/integrations/redis/modules/caches.py +17 -8
- sentry_sdk/integrations/redis/modules/queries.py +9 -8
- sentry_sdk/integrations/redis/rb.py +3 -2
- sentry_sdk/integrations/redis/redis.py +4 -4
- sentry_sdk/integrations/redis/redis_cluster.py +10 -8
- sentry_sdk/integrations/redis/redis_py_cluster_legacy.py +3 -2
- sentry_sdk/integrations/redis/utils.py +21 -22
- sentry_sdk/integrations/rq.py +13 -16
- sentry_sdk/integrations/rust_tracing.py +10 -7
- sentry_sdk/integrations/sanic.py +34 -46
- sentry_sdk/integrations/serverless.py +22 -27
- sentry_sdk/integrations/socket.py +29 -17
- sentry_sdk/integrations/spark/__init__.py +1 -0
- sentry_sdk/integrations/spark/spark_driver.py +45 -83
- sentry_sdk/integrations/spark/spark_worker.py +7 -11
- sentry_sdk/integrations/sqlalchemy.py +22 -19
- sentry_sdk/integrations/starlette.py +89 -93
- sentry_sdk/integrations/starlite.py +31 -37
- sentry_sdk/integrations/statsig.py +5 -4
- sentry_sdk/integrations/stdlib.py +32 -28
- sentry_sdk/integrations/strawberry.py +63 -50
- sentry_sdk/integrations/sys_exit.py +7 -11
- sentry_sdk/integrations/threading.py +13 -15
- sentry_sdk/integrations/tornado.py +28 -32
- sentry_sdk/integrations/trytond.py +4 -3
- sentry_sdk/integrations/typer.py +8 -6
- sentry_sdk/integrations/unleash.py +5 -4
- sentry_sdk/integrations/wsgi.py +47 -46
- sentry_sdk/logger.py +13 -9
- sentry_sdk/monitor.py +16 -28
- sentry_sdk/opentelemetry/consts.py +11 -4
- sentry_sdk/opentelemetry/contextvars_context.py +17 -15
- sentry_sdk/opentelemetry/propagator.py +38 -21
- sentry_sdk/opentelemetry/sampler.py +51 -34
- sentry_sdk/opentelemetry/scope.py +46 -37
- sentry_sdk/opentelemetry/span_processor.py +43 -59
- sentry_sdk/opentelemetry/tracing.py +32 -12
- sentry_sdk/opentelemetry/utils.py +180 -196
- sentry_sdk/profiler/continuous_profiler.py +108 -97
- sentry_sdk/profiler/transaction_profiler.py +70 -97
- sentry_sdk/profiler/utils.py +11 -15
- sentry_sdk/scope.py +251 -264
- sentry_sdk/scrubber.py +22 -26
- sentry_sdk/serializer.py +48 -65
- sentry_sdk/session.py +44 -61
- sentry_sdk/sessions.py +35 -49
- sentry_sdk/spotlight.py +15 -21
- sentry_sdk/tracing.py +118 -184
- sentry_sdk/tracing_utils.py +103 -123
- sentry_sdk/transport.py +131 -157
- sentry_sdk/utils.py +278 -309
- sentry_sdk/worker.py +16 -28
- {sentry_sdk-3.0.0a2.dist-info → sentry_sdk-3.0.0a4.dist-info}/METADATA +1 -1
- sentry_sdk-3.0.0a4.dist-info/RECORD +168 -0
- sentry_sdk-3.0.0a2.dist-info/RECORD +0 -154
- {sentry_sdk-3.0.0a2.dist-info → sentry_sdk-3.0.0a4.dist-info}/WHEEL +0 -0
- {sentry_sdk-3.0.0a2.dist-info → sentry_sdk-3.0.0a4.dist-info}/entry_points.txt +0 -0
- {sentry_sdk-3.0.0a2.dist-info → sentry_sdk-3.0.0a4.dist-info}/licenses/LICENSE +0 -0
- {sentry_sdk-3.0.0a2.dist-info → sentry_sdk-3.0.0a4.dist-info}/top_level.txt +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
from functools import wraps
|
|
2
3
|
|
|
3
4
|
import grpc
|
|
@@ -130,10 +131,10 @@ def _wrap_async_server(func: Callable[P, AsyncServer]) -> Callable[P, AsyncServe
|
|
|
130
131
|
**kwargs: P.kwargs,
|
|
131
132
|
) -> Server:
|
|
132
133
|
server_interceptor = AsyncServerInterceptor()
|
|
133
|
-
interceptors = [
|
|
134
|
+
interceptors: Sequence[grpc.ServerInterceptor] = [
|
|
134
135
|
server_interceptor,
|
|
135
136
|
*(interceptors or []),
|
|
136
|
-
]
|
|
137
|
+
]
|
|
137
138
|
|
|
138
139
|
try:
|
|
139
140
|
# We prefer interceptors as a list because of compatibility with
|
|
@@ -51,7 +51,7 @@ class SentryUnaryUnaryClientInterceptor(ClientInterceptor, UnaryUnaryClientInter
|
|
|
51
51
|
op=OP.GRPC_CLIENT,
|
|
52
52
|
name="unary unary call to %s" % method,
|
|
53
53
|
origin=SPAN_ORIGIN,
|
|
54
|
-
|
|
54
|
+
only_as_child_span=True,
|
|
55
55
|
) as span:
|
|
56
56
|
span.set_attribute("type", "unary unary")
|
|
57
57
|
span.set_attribute("method", method)
|
|
@@ -84,7 +84,7 @@ class SentryUnaryStreamClientInterceptor(
|
|
|
84
84
|
op=OP.GRPC_CLIENT,
|
|
85
85
|
name="unary stream call to %s" % method,
|
|
86
86
|
origin=SPAN_ORIGIN,
|
|
87
|
-
|
|
87
|
+
only_as_child_span=True,
|
|
88
88
|
) as span:
|
|
89
89
|
span.set_attribute("type", "unary stream")
|
|
90
90
|
span.set_attribute("method", method)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import sentry_sdk
|
|
2
3
|
from sentry_sdk.consts import OP
|
|
3
4
|
from sentry_sdk.integrations import DidNotEnable
|
|
@@ -21,14 +22,19 @@ except ImportError:
|
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class ServerInterceptor(grpc.aio.ServerInterceptor): # type: ignore
|
|
24
|
-
def __init__(
|
|
25
|
-
|
|
25
|
+
def __init__(
|
|
26
|
+
self: ServerInterceptor,
|
|
27
|
+
find_name: Callable[[ServicerContext], str] | None = None,
|
|
28
|
+
) -> None:
|
|
26
29
|
self._find_method_name = find_name or self._find_name
|
|
27
30
|
|
|
28
31
|
super().__init__()
|
|
29
32
|
|
|
30
|
-
async def intercept_service(
|
|
31
|
-
|
|
33
|
+
async def intercept_service(
|
|
34
|
+
self: ServerInterceptor,
|
|
35
|
+
continuation: Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]],
|
|
36
|
+
handler_call_details: HandlerCallDetails,
|
|
37
|
+
) -> Optional[Awaitable[RpcMethodHandler]]:
|
|
32
38
|
self._handler_call_details = handler_call_details
|
|
33
39
|
handler = await continuation(handler_call_details)
|
|
34
40
|
if handler is None:
|
|
@@ -37,8 +43,7 @@ class ServerInterceptor(grpc.aio.ServerInterceptor): # type: ignore
|
|
|
37
43
|
if not handler.request_streaming and not handler.response_streaming:
|
|
38
44
|
handler_factory = grpc.unary_unary_rpc_method_handler
|
|
39
45
|
|
|
40
|
-
async def wrapped(request, context):
|
|
41
|
-
# type: (Any, ServicerContext) -> Any
|
|
46
|
+
async def wrapped(request: Any, context: ServicerContext) -> Any:
|
|
42
47
|
name = self._find_method_name(context)
|
|
43
48
|
if not name:
|
|
44
49
|
return await handler(request, context)
|
|
@@ -66,24 +71,21 @@ class ServerInterceptor(grpc.aio.ServerInterceptor): # type: ignore
|
|
|
66
71
|
elif not handler.request_streaming and handler.response_streaming:
|
|
67
72
|
handler_factory = grpc.unary_stream_rpc_method_handler
|
|
68
73
|
|
|
69
|
-
async def wrapped(request, context): # type: ignore
|
|
70
|
-
# type: (Any, ServicerContext) -> Any
|
|
74
|
+
async def wrapped(request: Any, context: ServicerContext) -> Any: # type: ignore
|
|
71
75
|
async for r in handler.unary_stream(request, context):
|
|
72
76
|
yield r
|
|
73
77
|
|
|
74
78
|
elif handler.request_streaming and not handler.response_streaming:
|
|
75
79
|
handler_factory = grpc.stream_unary_rpc_method_handler
|
|
76
80
|
|
|
77
|
-
async def wrapped(request, context):
|
|
78
|
-
# type: (Any, ServicerContext) -> Any
|
|
81
|
+
async def wrapped(request: Any, context: ServicerContext) -> Any:
|
|
79
82
|
response = handler.stream_unary(request, context)
|
|
80
83
|
return await response
|
|
81
84
|
|
|
82
85
|
elif handler.request_streaming and handler.response_streaming:
|
|
83
86
|
handler_factory = grpc.stream_stream_rpc_method_handler
|
|
84
87
|
|
|
85
|
-
async def wrapped(request, context): # type: ignore
|
|
86
|
-
# type: (Any, ServicerContext) -> Any
|
|
88
|
+
async def wrapped(request: Any, context: ServicerContext) -> Any: # type: ignore
|
|
87
89
|
async for r in handler.stream_stream(request, context):
|
|
88
90
|
yield r
|
|
89
91
|
|
|
@@ -93,6 +95,5 @@ class ServerInterceptor(grpc.aio.ServerInterceptor): # type: ignore
|
|
|
93
95
|
response_serializer=handler.response_serializer,
|
|
94
96
|
)
|
|
95
97
|
|
|
96
|
-
def _find_name(self, context):
|
|
97
|
-
# type: (ServicerContext) -> str
|
|
98
|
+
def _find_name(self, context: ServicerContext) -> str:
|
|
98
99
|
return self._handler_call_details.method
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import sentry_sdk
|
|
2
3
|
from sentry_sdk.consts import OP
|
|
3
4
|
from sentry_sdk.integrations import DidNotEnable
|
|
@@ -23,15 +24,19 @@ class ClientInterceptor(
|
|
|
23
24
|
):
|
|
24
25
|
_is_intercepted = False
|
|
25
26
|
|
|
26
|
-
def intercept_unary_unary(
|
|
27
|
-
|
|
27
|
+
def intercept_unary_unary(
|
|
28
|
+
self: ClientInterceptor,
|
|
29
|
+
continuation: Callable[[ClientCallDetails, Message], _UnaryOutcome],
|
|
30
|
+
client_call_details: ClientCallDetails,
|
|
31
|
+
request: Message,
|
|
32
|
+
) -> _UnaryOutcome:
|
|
28
33
|
method = client_call_details.method
|
|
29
34
|
|
|
30
35
|
with sentry_sdk.start_span(
|
|
31
36
|
op=OP.GRPC_CLIENT,
|
|
32
37
|
name="unary unary call to %s" % method,
|
|
33
38
|
origin=SPAN_ORIGIN,
|
|
34
|
-
|
|
39
|
+
only_as_child_span=True,
|
|
35
40
|
) as span:
|
|
36
41
|
span.set_attribute("type", "unary unary")
|
|
37
42
|
span.set_attribute("method", method)
|
|
@@ -45,15 +50,21 @@ class ClientInterceptor(
|
|
|
45
50
|
|
|
46
51
|
return response
|
|
47
52
|
|
|
48
|
-
def intercept_unary_stream(
|
|
49
|
-
|
|
53
|
+
def intercept_unary_stream(
|
|
54
|
+
self: ClientInterceptor,
|
|
55
|
+
continuation: Callable[
|
|
56
|
+
[ClientCallDetails, Message], Union[Iterable[Any], UnaryStreamCall]
|
|
57
|
+
],
|
|
58
|
+
client_call_details: ClientCallDetails,
|
|
59
|
+
request: Message,
|
|
60
|
+
) -> Union[Iterator[Message], Call]:
|
|
50
61
|
method = client_call_details.method
|
|
51
62
|
|
|
52
63
|
with sentry_sdk.start_span(
|
|
53
64
|
op=OP.GRPC_CLIENT,
|
|
54
65
|
name="unary stream call to %s" % method,
|
|
55
66
|
origin=SPAN_ORIGIN,
|
|
56
|
-
|
|
67
|
+
only_as_child_span=True,
|
|
57
68
|
) as span:
|
|
58
69
|
span.set_attribute("type", "unary stream")
|
|
59
70
|
span.set_attribute("method", method)
|
|
@@ -62,17 +73,16 @@ class ClientInterceptor(
|
|
|
62
73
|
client_call_details
|
|
63
74
|
)
|
|
64
75
|
|
|
65
|
-
response = continuation(
|
|
66
|
-
client_call_details, request
|
|
67
|
-
) # type: UnaryStreamCall
|
|
76
|
+
response: UnaryStreamCall = continuation(client_call_details, request)
|
|
68
77
|
# Setting code on unary-stream leads to execution getting stuck
|
|
69
78
|
# span.set_attribute("code", response.code().name)
|
|
70
79
|
|
|
71
80
|
return response
|
|
72
81
|
|
|
73
82
|
@staticmethod
|
|
74
|
-
def _update_client_call_details_metadata_from_scope(
|
|
75
|
-
|
|
83
|
+
def _update_client_call_details_metadata_from_scope(
|
|
84
|
+
client_call_details: ClientCallDetails,
|
|
85
|
+
) -> ClientCallDetails:
|
|
76
86
|
metadata = (
|
|
77
87
|
list(client_call_details.metadata) if client_call_details.metadata else []
|
|
78
88
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import sentry_sdk
|
|
2
3
|
from sentry_sdk.consts import OP
|
|
3
4
|
from sentry_sdk.integrations import DidNotEnable
|
|
@@ -18,20 +19,24 @@ except ImportError:
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
class ServerInterceptor(grpc.ServerInterceptor): # type: ignore
|
|
21
|
-
def __init__(
|
|
22
|
-
|
|
22
|
+
def __init__(
|
|
23
|
+
self: ServerInterceptor,
|
|
24
|
+
find_name: Optional[Callable[[ServicerContext], str]] = None,
|
|
25
|
+
) -> None:
|
|
23
26
|
self._find_method_name = find_name or ServerInterceptor._find_name
|
|
24
27
|
|
|
25
28
|
super().__init__()
|
|
26
29
|
|
|
27
|
-
def intercept_service(
|
|
28
|
-
|
|
30
|
+
def intercept_service(
|
|
31
|
+
self: ServerInterceptor,
|
|
32
|
+
continuation: Callable[[HandlerCallDetails], RpcMethodHandler],
|
|
33
|
+
handler_call_details: HandlerCallDetails,
|
|
34
|
+
) -> RpcMethodHandler:
|
|
29
35
|
handler = continuation(handler_call_details)
|
|
30
36
|
if not handler or not handler.unary_unary:
|
|
31
37
|
return handler
|
|
32
38
|
|
|
33
|
-
def behavior(request, context):
|
|
34
|
-
# type: (Message, ServicerContext) -> Message
|
|
39
|
+
def behavior(request: Message, context: ServicerContext) -> Message:
|
|
35
40
|
with sentry_sdk.isolation_scope():
|
|
36
41
|
name = self._find_method_name(context)
|
|
37
42
|
|
|
@@ -59,6 +64,5 @@ class ServerInterceptor(grpc.ServerInterceptor): # type: ignore
|
|
|
59
64
|
)
|
|
60
65
|
|
|
61
66
|
@staticmethod
|
|
62
|
-
def _find_name(context):
|
|
63
|
-
# type: (ServicerContext) -> str
|
|
67
|
+
def _find_name(context: ServicerContext) -> str:
|
|
64
68
|
return context._rpc_event.call_details.method.decode()
|
sentry_sdk/integrations/httpx.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import sentry_sdk
|
|
2
3
|
from sentry_sdk.consts import OP, SPANDATA, BAGGAGE_HEADER_NAME
|
|
3
4
|
from sentry_sdk.integrations import Integration, DidNotEnable
|
|
@@ -32,8 +33,7 @@ class HttpxIntegration(Integration):
|
|
|
32
33
|
origin = f"auto.http.{identifier}"
|
|
33
34
|
|
|
34
35
|
@staticmethod
|
|
35
|
-
def setup_once():
|
|
36
|
-
# type: () -> None
|
|
36
|
+
def setup_once() -> None:
|
|
37
37
|
"""
|
|
38
38
|
httpx has its own transport layer and can be customized when needed,
|
|
39
39
|
so patch Client.send and AsyncClient.send to support both synchronous and async interfaces.
|
|
@@ -42,13 +42,11 @@ class HttpxIntegration(Integration):
|
|
|
42
42
|
_install_httpx_async_client()
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
def _install_httpx_client():
|
|
46
|
-
# type: () -> None
|
|
45
|
+
def _install_httpx_client() -> None:
|
|
47
46
|
real_send = Client.send
|
|
48
47
|
|
|
49
48
|
@ensure_integration_enabled(HttpxIntegration, real_send)
|
|
50
|
-
def send(self, request, **kwargs):
|
|
51
|
-
# type: (Client, Request, **Any) -> Response
|
|
49
|
+
def send(self: Client, request: Request, **kwargs: Any) -> Response:
|
|
52
50
|
parsed_url = None
|
|
53
51
|
with capture_internal_exceptions():
|
|
54
52
|
parsed_url = parse_url(str(request.url), sanitize=False)
|
|
@@ -61,7 +59,7 @@ def _install_httpx_client():
|
|
|
61
59
|
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
|
|
62
60
|
),
|
|
63
61
|
origin=HttpxIntegration.origin,
|
|
64
|
-
|
|
62
|
+
only_as_child_span=True,
|
|
65
63
|
) as span:
|
|
66
64
|
data = {
|
|
67
65
|
SPANDATA.HTTP_METHOD: request.method,
|
|
@@ -112,12 +110,10 @@ def _install_httpx_client():
|
|
|
112
110
|
Client.send = send
|
|
113
111
|
|
|
114
112
|
|
|
115
|
-
def _install_httpx_async_client():
|
|
116
|
-
# type: () -> None
|
|
113
|
+
def _install_httpx_async_client() -> None:
|
|
117
114
|
real_send = AsyncClient.send
|
|
118
115
|
|
|
119
|
-
async def send(self, request, **kwargs):
|
|
120
|
-
# type: (AsyncClient, Request, **Any) -> Response
|
|
116
|
+
async def send(self: AsyncClient, request: Request, **kwargs: Any) -> Response:
|
|
121
117
|
if sentry_sdk.get_client().get_integration(HttpxIntegration) is None:
|
|
122
118
|
return await real_send(self, request, **kwargs)
|
|
123
119
|
|
|
@@ -133,7 +129,7 @@ def _install_httpx_async_client():
|
|
|
133
129
|
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
|
|
134
130
|
),
|
|
135
131
|
origin=HttpxIntegration.origin,
|
|
136
|
-
|
|
132
|
+
only_as_child_span=True,
|
|
137
133
|
) as span:
|
|
138
134
|
data = {
|
|
139
135
|
SPANDATA.HTTP_METHOD: request.method,
|
|
@@ -184,8 +180,9 @@ def _install_httpx_async_client():
|
|
|
184
180
|
AsyncClient.send = send
|
|
185
181
|
|
|
186
182
|
|
|
187
|
-
def _add_sentry_baggage_to_headers(
|
|
188
|
-
|
|
183
|
+
def _add_sentry_baggage_to_headers(
|
|
184
|
+
headers: MutableMapping[str, str], sentry_baggage: str
|
|
185
|
+
) -> None:
|
|
189
186
|
"""Add the Sentry baggage to the headers.
|
|
190
187
|
|
|
191
188
|
This function directly mutates the provided headers. The provided sentry_baggage
|
sentry_sdk/integrations/huey.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
import sys
|
|
2
3
|
from datetime import datetime
|
|
3
4
|
|
|
@@ -45,24 +46,21 @@ class HueyIntegration(Integration):
|
|
|
45
46
|
origin = f"auto.queue.{identifier}"
|
|
46
47
|
|
|
47
48
|
@staticmethod
|
|
48
|
-
def setup_once():
|
|
49
|
-
# type: () -> None
|
|
49
|
+
def setup_once() -> None:
|
|
50
50
|
patch_enqueue()
|
|
51
51
|
patch_execute()
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
def patch_enqueue():
|
|
55
|
-
# type: () -> None
|
|
54
|
+
def patch_enqueue() -> None:
|
|
56
55
|
old_enqueue = Huey.enqueue
|
|
57
56
|
|
|
58
57
|
@ensure_integration_enabled(HueyIntegration, old_enqueue)
|
|
59
|
-
def _sentry_enqueue(self, task):
|
|
60
|
-
# type: (Huey, Task) -> Optional[Union[Result, ResultGroup]]
|
|
58
|
+
def _sentry_enqueue(self: Huey, task: Task) -> Optional[Union[Result, ResultGroup]]:
|
|
61
59
|
with sentry_sdk.start_span(
|
|
62
60
|
op=OP.QUEUE_SUBMIT_HUEY,
|
|
63
61
|
name=task.name,
|
|
64
62
|
origin=HueyIntegration.origin,
|
|
65
|
-
|
|
63
|
+
only_as_child_span=True,
|
|
66
64
|
):
|
|
67
65
|
if not isinstance(task, PeriodicTask):
|
|
68
66
|
# Attach trace propagation data to task kwargs. We do
|
|
@@ -77,10 +75,8 @@ def patch_enqueue():
|
|
|
77
75
|
Huey.enqueue = _sentry_enqueue
|
|
78
76
|
|
|
79
77
|
|
|
80
|
-
def _make_event_processor(task):
|
|
81
|
-
|
|
82
|
-
def event_processor(event, hint):
|
|
83
|
-
# type: (Event, Hint) -> Optional[Event]
|
|
78
|
+
def _make_event_processor(task: Any) -> EventProcessor:
|
|
79
|
+
def event_processor(event: Event, hint: Hint) -> Optional[Event]:
|
|
84
80
|
|
|
85
81
|
with capture_internal_exceptions():
|
|
86
82
|
tags = event.setdefault("tags", {})
|
|
@@ -107,8 +103,7 @@ def _make_event_processor(task):
|
|
|
107
103
|
return event_processor
|
|
108
104
|
|
|
109
105
|
|
|
110
|
-
def _capture_exception(exc_info):
|
|
111
|
-
# type: (ExcInfo) -> None
|
|
106
|
+
def _capture_exception(exc_info: ExcInfo) -> None:
|
|
112
107
|
scope = sentry_sdk.get_current_scope()
|
|
113
108
|
|
|
114
109
|
if scope.root_span is not None:
|
|
@@ -126,12 +121,10 @@ def _capture_exception(exc_info):
|
|
|
126
121
|
scope.capture_event(event, hint=hint)
|
|
127
122
|
|
|
128
123
|
|
|
129
|
-
def _wrap_task_execute(func):
|
|
130
|
-
# type: (F) -> F
|
|
124
|
+
def _wrap_task_execute(func: F) -> F:
|
|
131
125
|
|
|
132
126
|
@ensure_integration_enabled(HueyIntegration, func)
|
|
133
|
-
def _sentry_execute(*args, **kwargs):
|
|
134
|
-
# type: (*Any, **Any) -> Any
|
|
127
|
+
def _sentry_execute(*args: Any, **kwargs: Any) -> Any:
|
|
135
128
|
try:
|
|
136
129
|
result = func(*args, **kwargs)
|
|
137
130
|
except Exception:
|
|
@@ -148,13 +141,13 @@ def _wrap_task_execute(func):
|
|
|
148
141
|
return _sentry_execute # type: ignore
|
|
149
142
|
|
|
150
143
|
|
|
151
|
-
def patch_execute():
|
|
152
|
-
# type: () -> None
|
|
144
|
+
def patch_execute() -> None:
|
|
153
145
|
old_execute = Huey._execute
|
|
154
146
|
|
|
155
147
|
@ensure_integration_enabled(HueyIntegration, old_execute)
|
|
156
|
-
def _sentry_execute(
|
|
157
|
-
|
|
148
|
+
def _sentry_execute(
|
|
149
|
+
self: Huey, task: Task, timestamp: Optional[datetime] = None
|
|
150
|
+
) -> Any:
|
|
158
151
|
with sentry_sdk.isolation_scope() as scope:
|
|
159
152
|
with capture_internal_exceptions():
|
|
160
153
|
scope._name = "huey"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
1
2
|
from functools import wraps
|
|
2
3
|
|
|
3
4
|
from sentry_sdk import consts
|
|
@@ -27,13 +28,11 @@ class HuggingfaceHubIntegration(Integration):
|
|
|
27
28
|
identifier = "huggingface_hub"
|
|
28
29
|
origin = f"auto.ai.{identifier}"
|
|
29
30
|
|
|
30
|
-
def __init__(self, include_prompts=True):
|
|
31
|
-
# type: (HuggingfaceHubIntegration, bool) -> None
|
|
31
|
+
def __init__(self: HuggingfaceHubIntegration, include_prompts: bool = True) -> None:
|
|
32
32
|
self.include_prompts = include_prompts
|
|
33
33
|
|
|
34
34
|
@staticmethod
|
|
35
|
-
def setup_once():
|
|
36
|
-
# type: () -> None
|
|
35
|
+
def setup_once() -> None:
|
|
37
36
|
huggingface_hub.inference._client.InferenceClient.text_generation = (
|
|
38
37
|
_wrap_text_generation(
|
|
39
38
|
huggingface_hub.inference._client.InferenceClient.text_generation
|
|
@@ -41,8 +40,7 @@ class HuggingfaceHubIntegration(Integration):
|
|
|
41
40
|
)
|
|
42
41
|
|
|
43
42
|
|
|
44
|
-
def _capture_exception(exc):
|
|
45
|
-
# type: (Any) -> None
|
|
43
|
+
def _capture_exception(exc: Any) -> None:
|
|
46
44
|
event, hint = event_from_exception(
|
|
47
45
|
exc,
|
|
48
46
|
client_options=sentry_sdk.get_client().options,
|
|
@@ -51,11 +49,9 @@ def _capture_exception(exc):
|
|
|
51
49
|
sentry_sdk.capture_event(event, hint=hint)
|
|
52
50
|
|
|
53
51
|
|
|
54
|
-
def _wrap_text_generation(f):
|
|
55
|
-
# type: (Callable[..., Any]) -> Callable[..., Any]
|
|
52
|
+
def _wrap_text_generation(f: Callable[..., Any]) -> Callable[..., Any]:
|
|
56
53
|
@wraps(f)
|
|
57
|
-
def new_text_generation(*args, **kwargs):
|
|
58
|
-
# type: (*Any, **Any) -> Any
|
|
54
|
+
def new_text_generation(*args: Any, **kwargs: Any) -> Any:
|
|
59
55
|
integration = sentry_sdk.get_client().get_integration(HuggingfaceHubIntegration)
|
|
60
56
|
if integration is None:
|
|
61
57
|
return f(*args, **kwargs)
|
|
@@ -77,7 +73,7 @@ def _wrap_text_generation(f):
|
|
|
77
73
|
op=consts.OP.HUGGINGFACE_HUB_CHAT_COMPLETIONS_CREATE,
|
|
78
74
|
name="Text Generation",
|
|
79
75
|
origin=HuggingfaceHubIntegration.origin,
|
|
80
|
-
|
|
76
|
+
only_as_child_span=True,
|
|
81
77
|
)
|
|
82
78
|
span.__enter__()
|
|
83
79
|
try:
|
|
@@ -112,7 +108,10 @@ def _wrap_text_generation(f):
|
|
|
112
108
|
[res.generated_text],
|
|
113
109
|
)
|
|
114
110
|
if res.details is not None and res.details.generated_tokens > 0:
|
|
115
|
-
record_token_usage(
|
|
111
|
+
record_token_usage(
|
|
112
|
+
span,
|
|
113
|
+
total_tokens=res.details.generated_tokens,
|
|
114
|
+
)
|
|
116
115
|
span.__exit__(None, None, None)
|
|
117
116
|
return res
|
|
118
117
|
|
|
@@ -124,8 +123,7 @@ def _wrap_text_generation(f):
|
|
|
124
123
|
|
|
125
124
|
if kwargs.get("details", False):
|
|
126
125
|
# res is Iterable[TextGenerationStreamOutput]
|
|
127
|
-
def new_details_iterator():
|
|
128
|
-
# type: () -> Iterable[ChatCompletionStreamOutput]
|
|
126
|
+
def new_details_iterator() -> Iterable[ChatCompletionStreamOutput]:
|
|
129
127
|
with capture_internal_exceptions():
|
|
130
128
|
tokens_used = 0
|
|
131
129
|
data_buf: list[str] = []
|
|
@@ -146,15 +144,17 @@ def _wrap_text_generation(f):
|
|
|
146
144
|
span, SPANDATA.AI_RESPONSES, "".join(data_buf)
|
|
147
145
|
)
|
|
148
146
|
if tokens_used > 0:
|
|
149
|
-
record_token_usage(
|
|
147
|
+
record_token_usage(
|
|
148
|
+
span,
|
|
149
|
+
total_tokens=tokens_used,
|
|
150
|
+
)
|
|
150
151
|
span.__exit__(None, None, None)
|
|
151
152
|
|
|
152
153
|
return new_details_iterator()
|
|
153
154
|
else:
|
|
154
155
|
# res is Iterable[str]
|
|
155
156
|
|
|
156
|
-
def new_iterator():
|
|
157
|
-
# type: () -> Iterable[str]
|
|
157
|
+
def new_iterator() -> Iterable[str]:
|
|
158
158
|
data_buf: list[str] = []
|
|
159
159
|
with capture_internal_exceptions():
|
|
160
160
|
for s in res:
|