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/monitor.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
from threading import Thread, Lock
|
|
4
|
+
|
|
5
|
+
import sentry_sdk
|
|
6
|
+
from sentry_sdk.utils import logger
|
|
7
|
+
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
MAX_DOWNSAMPLE_FACTOR = 10
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Monitor:
|
|
18
|
+
"""
|
|
19
|
+
Performs health checks in a separate thread once every interval seconds
|
|
20
|
+
and updates the internal state. Other parts of the SDK only read this state
|
|
21
|
+
and act accordingly.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
name = "sentry.monitor"
|
|
25
|
+
|
|
26
|
+
def __init__(self, transport, interval=10):
|
|
27
|
+
# type: (sentry_sdk.transport.Transport, float) -> None
|
|
28
|
+
self.transport = transport # type: sentry_sdk.transport.Transport
|
|
29
|
+
self.interval = interval # type: float
|
|
30
|
+
|
|
31
|
+
self._healthy = True
|
|
32
|
+
self._downsample_factor = 0 # type: int
|
|
33
|
+
|
|
34
|
+
self._thread = None # type: Optional[Thread]
|
|
35
|
+
self._thread_lock = Lock()
|
|
36
|
+
self._thread_for_pid = None # type: Optional[int]
|
|
37
|
+
self._running = True
|
|
38
|
+
|
|
39
|
+
def _ensure_running(self):
|
|
40
|
+
# type: () -> None
|
|
41
|
+
"""
|
|
42
|
+
Check that the monitor has an active thread to run in, or create one if not.
|
|
43
|
+
|
|
44
|
+
Note that this might fail (e.g. in Python 3.12 it's not possible to
|
|
45
|
+
spawn new threads at interpreter shutdown). In that case self._running
|
|
46
|
+
will be False after running this function.
|
|
47
|
+
"""
|
|
48
|
+
if self._thread_for_pid == os.getpid() and self._thread is not None:
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
with self._thread_lock:
|
|
52
|
+
if self._thread_for_pid == os.getpid() and self._thread is not None:
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
def _thread():
|
|
56
|
+
# type: (...) -> None
|
|
57
|
+
while self._running:
|
|
58
|
+
time.sleep(self.interval)
|
|
59
|
+
if self._running:
|
|
60
|
+
self.run()
|
|
61
|
+
|
|
62
|
+
thread = Thread(name=self.name, target=_thread)
|
|
63
|
+
thread.daemon = True
|
|
64
|
+
try:
|
|
65
|
+
thread.start()
|
|
66
|
+
except RuntimeError:
|
|
67
|
+
# Unfortunately at this point the interpreter is in a state that no
|
|
68
|
+
# longer allows us to spawn a thread and we have to bail.
|
|
69
|
+
self._running = False
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
self._thread = thread
|
|
73
|
+
self._thread_for_pid = os.getpid()
|
|
74
|
+
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
def run(self):
|
|
78
|
+
# type: () -> None
|
|
79
|
+
self.check_health()
|
|
80
|
+
self.set_downsample_factor()
|
|
81
|
+
|
|
82
|
+
def set_downsample_factor(self):
|
|
83
|
+
# type: () -> None
|
|
84
|
+
if self._healthy:
|
|
85
|
+
if self._downsample_factor > 0:
|
|
86
|
+
logger.debug(
|
|
87
|
+
"[Monitor] health check positive, reverting to normal sampling"
|
|
88
|
+
)
|
|
89
|
+
self._downsample_factor = 0
|
|
90
|
+
else:
|
|
91
|
+
if self.downsample_factor < MAX_DOWNSAMPLE_FACTOR:
|
|
92
|
+
self._downsample_factor += 1
|
|
93
|
+
logger.debug(
|
|
94
|
+
"[Monitor] health check negative, downsampling with a factor of %d",
|
|
95
|
+
self._downsample_factor,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def check_health(self):
|
|
99
|
+
# type: () -> None
|
|
100
|
+
"""
|
|
101
|
+
Perform the actual health checks,
|
|
102
|
+
currently only checks if the transport is rate-limited.
|
|
103
|
+
TODO: augment in the future with more checks.
|
|
104
|
+
"""
|
|
105
|
+
self._healthy = self.transport.is_healthy()
|
|
106
|
+
|
|
107
|
+
def is_healthy(self):
|
|
108
|
+
# type: () -> bool
|
|
109
|
+
self._ensure_running()
|
|
110
|
+
return self._healthy
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def downsample_factor(self):
|
|
114
|
+
# type: () -> int
|
|
115
|
+
self._ensure_running()
|
|
116
|
+
return self._downsample_factor
|
|
117
|
+
|
|
118
|
+
def kill(self):
|
|
119
|
+
# type: () -> None
|
|
120
|
+
self._running = False
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from sentry_sdk.profiler.continuous_profiler import (
|
|
2
|
+
start_profile_session,
|
|
3
|
+
start_profiler,
|
|
4
|
+
stop_profile_session,
|
|
5
|
+
stop_profiler,
|
|
6
|
+
)
|
|
7
|
+
from sentry_sdk.profiler.transaction_profiler import (
|
|
8
|
+
MAX_PROFILE_DURATION_NS,
|
|
9
|
+
PROFILE_MINIMUM_SAMPLES,
|
|
10
|
+
Profile,
|
|
11
|
+
Scheduler,
|
|
12
|
+
ThreadScheduler,
|
|
13
|
+
GeventScheduler,
|
|
14
|
+
has_profiling_enabled,
|
|
15
|
+
setup_profiler,
|
|
16
|
+
teardown_profiler,
|
|
17
|
+
)
|
|
18
|
+
from sentry_sdk.profiler.utils import (
|
|
19
|
+
DEFAULT_SAMPLING_FREQUENCY,
|
|
20
|
+
MAX_STACK_DEPTH,
|
|
21
|
+
get_frame_name,
|
|
22
|
+
extract_frame,
|
|
23
|
+
extract_stack,
|
|
24
|
+
frame_id,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"start_profile_session", # TODO: Deprecate this in favor of `start_profiler`
|
|
29
|
+
"start_profiler",
|
|
30
|
+
"stop_profile_session", # TODO: Deprecate this in favor of `stop_profiler`
|
|
31
|
+
"stop_profiler",
|
|
32
|
+
# DEPRECATED: The following was re-exported for backwards compatibility. It
|
|
33
|
+
# will be removed from sentry_sdk.profiler in a future release.
|
|
34
|
+
"MAX_PROFILE_DURATION_NS",
|
|
35
|
+
"PROFILE_MINIMUM_SAMPLES",
|
|
36
|
+
"Profile",
|
|
37
|
+
"Scheduler",
|
|
38
|
+
"ThreadScheduler",
|
|
39
|
+
"GeventScheduler",
|
|
40
|
+
"has_profiling_enabled",
|
|
41
|
+
"setup_profiler",
|
|
42
|
+
"teardown_profiler",
|
|
43
|
+
"DEFAULT_SAMPLING_FREQUENCY",
|
|
44
|
+
"MAX_STACK_DEPTH",
|
|
45
|
+
"get_frame_name",
|
|
46
|
+
"extract_frame",
|
|
47
|
+
"extract_stack",
|
|
48
|
+
"frame_id",
|
|
49
|
+
]
|