sentry-sdk 3.0.0a1__py2.py3-none-any.whl → 3.0.0a3__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.

Files changed (157) hide show
  1. sentry_sdk/__init__.py +2 -0
  2. sentry_sdk/_compat.py +5 -12
  3. sentry_sdk/_init_implementation.py +7 -7
  4. sentry_sdk/_log_batcher.py +17 -29
  5. sentry_sdk/_lru_cache.py +7 -9
  6. sentry_sdk/_queue.py +2 -4
  7. sentry_sdk/_types.py +11 -18
  8. sentry_sdk/_werkzeug.py +5 -7
  9. sentry_sdk/ai/monitoring.py +44 -31
  10. sentry_sdk/ai/utils.py +3 -4
  11. sentry_sdk/api.py +75 -87
  12. sentry_sdk/attachments.py +10 -12
  13. sentry_sdk/client.py +137 -155
  14. sentry_sdk/consts.py +430 -174
  15. sentry_sdk/crons/api.py +16 -17
  16. sentry_sdk/crons/decorator.py +25 -27
  17. sentry_sdk/debug.py +4 -6
  18. sentry_sdk/envelope.py +46 -112
  19. sentry_sdk/feature_flags.py +9 -15
  20. sentry_sdk/integrations/__init__.py +24 -19
  21. sentry_sdk/integrations/_asgi_common.py +15 -18
  22. sentry_sdk/integrations/_wsgi_common.py +22 -33
  23. sentry_sdk/integrations/aiohttp.py +32 -30
  24. sentry_sdk/integrations/anthropic.py +42 -37
  25. sentry_sdk/integrations/argv.py +3 -4
  26. sentry_sdk/integrations/ariadne.py +16 -18
  27. sentry_sdk/integrations/arq.py +21 -29
  28. sentry_sdk/integrations/asgi.py +63 -37
  29. sentry_sdk/integrations/asyncio.py +14 -16
  30. sentry_sdk/integrations/atexit.py +6 -10
  31. sentry_sdk/integrations/aws_lambda.py +26 -36
  32. sentry_sdk/integrations/beam.py +10 -18
  33. sentry_sdk/integrations/boto3.py +18 -16
  34. sentry_sdk/integrations/bottle.py +25 -34
  35. sentry_sdk/integrations/celery/__init__.py +41 -61
  36. sentry_sdk/integrations/celery/beat.py +23 -27
  37. sentry_sdk/integrations/celery/utils.py +15 -17
  38. sentry_sdk/integrations/chalice.py +8 -10
  39. sentry_sdk/integrations/clickhouse_driver.py +21 -31
  40. sentry_sdk/integrations/cloud_resource_context.py +9 -16
  41. sentry_sdk/integrations/cohere.py +27 -33
  42. sentry_sdk/integrations/dedupe.py +5 -8
  43. sentry_sdk/integrations/django/__init__.py +57 -72
  44. sentry_sdk/integrations/django/asgi.py +26 -34
  45. sentry_sdk/integrations/django/caching.py +23 -19
  46. sentry_sdk/integrations/django/middleware.py +17 -20
  47. sentry_sdk/integrations/django/signals_handlers.py +11 -10
  48. sentry_sdk/integrations/django/templates.py +19 -16
  49. sentry_sdk/integrations/django/transactions.py +16 -11
  50. sentry_sdk/integrations/django/views.py +6 -10
  51. sentry_sdk/integrations/dramatiq.py +21 -21
  52. sentry_sdk/integrations/excepthook.py +10 -10
  53. sentry_sdk/integrations/executing.py +3 -4
  54. sentry_sdk/integrations/falcon.py +27 -42
  55. sentry_sdk/integrations/fastapi.py +13 -16
  56. sentry_sdk/integrations/flask.py +31 -38
  57. sentry_sdk/integrations/gcp.py +13 -16
  58. sentry_sdk/integrations/gnu_backtrace.py +4 -6
  59. sentry_sdk/integrations/gql.py +16 -17
  60. sentry_sdk/integrations/graphene.py +13 -12
  61. sentry_sdk/integrations/grpc/__init__.py +19 -1
  62. sentry_sdk/integrations/grpc/aio/server.py +15 -14
  63. sentry_sdk/integrations/grpc/client.py +19 -9
  64. sentry_sdk/integrations/grpc/consts.py +2 -0
  65. sentry_sdk/integrations/grpc/server.py +12 -8
  66. sentry_sdk/integrations/httpx.py +9 -12
  67. sentry_sdk/integrations/huey.py +13 -20
  68. sentry_sdk/integrations/huggingface_hub.py +18 -18
  69. sentry_sdk/integrations/langchain.py +203 -113
  70. sentry_sdk/integrations/launchdarkly.py +13 -10
  71. sentry_sdk/integrations/litestar.py +37 -35
  72. sentry_sdk/integrations/logging.py +52 -65
  73. sentry_sdk/integrations/loguru.py +127 -57
  74. sentry_sdk/integrations/modules.py +3 -4
  75. sentry_sdk/integrations/openai.py +100 -88
  76. sentry_sdk/integrations/openai_agents/__init__.py +49 -0
  77. sentry_sdk/integrations/openai_agents/consts.py +1 -0
  78. sentry_sdk/integrations/openai_agents/patches/__init__.py +4 -0
  79. sentry_sdk/integrations/openai_agents/patches/agent_run.py +152 -0
  80. sentry_sdk/integrations/openai_agents/patches/models.py +52 -0
  81. sentry_sdk/integrations/openai_agents/patches/runner.py +42 -0
  82. sentry_sdk/integrations/openai_agents/patches/tools.py +84 -0
  83. sentry_sdk/integrations/openai_agents/spans/__init__.py +5 -0
  84. sentry_sdk/integrations/openai_agents/spans/agent_workflow.py +20 -0
  85. sentry_sdk/integrations/openai_agents/spans/ai_client.py +46 -0
  86. sentry_sdk/integrations/openai_agents/spans/execute_tool.py +47 -0
  87. sentry_sdk/integrations/openai_agents/spans/handoff.py +24 -0
  88. sentry_sdk/integrations/openai_agents/spans/invoke_agent.py +41 -0
  89. sentry_sdk/integrations/openai_agents/utils.py +201 -0
  90. sentry_sdk/integrations/openfeature.py +11 -6
  91. sentry_sdk/integrations/pure_eval.py +6 -10
  92. sentry_sdk/integrations/pymongo.py +13 -17
  93. sentry_sdk/integrations/pyramid.py +31 -36
  94. sentry_sdk/integrations/quart.py +23 -28
  95. sentry_sdk/integrations/ray.py +73 -64
  96. sentry_sdk/integrations/redis/__init__.py +7 -4
  97. sentry_sdk/integrations/redis/_async_common.py +25 -12
  98. sentry_sdk/integrations/redis/_sync_common.py +19 -13
  99. sentry_sdk/integrations/redis/modules/caches.py +17 -8
  100. sentry_sdk/integrations/redis/modules/queries.py +9 -8
  101. sentry_sdk/integrations/redis/rb.py +3 -2
  102. sentry_sdk/integrations/redis/redis.py +4 -4
  103. sentry_sdk/integrations/redis/redis_cluster.py +21 -13
  104. sentry_sdk/integrations/redis/redis_py_cluster_legacy.py +3 -2
  105. sentry_sdk/integrations/redis/utils.py +23 -24
  106. sentry_sdk/integrations/rq.py +13 -16
  107. sentry_sdk/integrations/rust_tracing.py +9 -6
  108. sentry_sdk/integrations/sanic.py +34 -46
  109. sentry_sdk/integrations/serverless.py +22 -27
  110. sentry_sdk/integrations/socket.py +27 -15
  111. sentry_sdk/integrations/spark/__init__.py +1 -0
  112. sentry_sdk/integrations/spark/spark_driver.py +45 -83
  113. sentry_sdk/integrations/spark/spark_worker.py +7 -11
  114. sentry_sdk/integrations/sqlalchemy.py +22 -19
  115. sentry_sdk/integrations/starlette.py +86 -90
  116. sentry_sdk/integrations/starlite.py +28 -34
  117. sentry_sdk/integrations/statsig.py +5 -4
  118. sentry_sdk/integrations/stdlib.py +28 -24
  119. sentry_sdk/integrations/strawberry.py +62 -49
  120. sentry_sdk/integrations/sys_exit.py +7 -11
  121. sentry_sdk/integrations/threading.py +12 -14
  122. sentry_sdk/integrations/tornado.py +28 -32
  123. sentry_sdk/integrations/trytond.py +4 -3
  124. sentry_sdk/integrations/typer.py +8 -6
  125. sentry_sdk/integrations/unleash.py +5 -4
  126. sentry_sdk/integrations/wsgi.py +47 -46
  127. sentry_sdk/logger.py +41 -10
  128. sentry_sdk/monitor.py +16 -28
  129. sentry_sdk/opentelemetry/consts.py +11 -4
  130. sentry_sdk/opentelemetry/contextvars_context.py +26 -16
  131. sentry_sdk/opentelemetry/propagator.py +38 -21
  132. sentry_sdk/opentelemetry/sampler.py +51 -34
  133. sentry_sdk/opentelemetry/scope.py +36 -37
  134. sentry_sdk/opentelemetry/span_processor.py +48 -58
  135. sentry_sdk/opentelemetry/tracing.py +58 -14
  136. sentry_sdk/opentelemetry/utils.py +186 -194
  137. sentry_sdk/profiler/continuous_profiler.py +108 -97
  138. sentry_sdk/profiler/transaction_profiler.py +70 -97
  139. sentry_sdk/profiler/utils.py +11 -15
  140. sentry_sdk/scope.py +251 -273
  141. sentry_sdk/scrubber.py +22 -26
  142. sentry_sdk/serializer.py +40 -54
  143. sentry_sdk/session.py +44 -61
  144. sentry_sdk/sessions.py +35 -49
  145. sentry_sdk/spotlight.py +15 -21
  146. sentry_sdk/tracing.py +121 -187
  147. sentry_sdk/tracing_utils.py +104 -122
  148. sentry_sdk/transport.py +131 -157
  149. sentry_sdk/utils.py +232 -309
  150. sentry_sdk/worker.py +16 -28
  151. {sentry_sdk-3.0.0a1.dist-info → sentry_sdk-3.0.0a3.dist-info}/METADATA +3 -3
  152. sentry_sdk-3.0.0a3.dist-info/RECORD +168 -0
  153. {sentry_sdk-3.0.0a1.dist-info → sentry_sdk-3.0.0a3.dist-info}/WHEEL +1 -1
  154. sentry_sdk-3.0.0a1.dist-info/RECORD +0 -154
  155. {sentry_sdk-3.0.0a1.dist-info → sentry_sdk-3.0.0a3.dist-info}/entry_points.txt +0 -0
  156. {sentry_sdk-3.0.0a1.dist-info → sentry_sdk-3.0.0a3.dist-info}/licenses/LICENSE +0 -0
  157. {sentry_sdk-3.0.0a1.dist-info → sentry_sdk-3.0.0a3.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import os
2
3
  import subprocess
3
4
  import sys
@@ -34,25 +35,23 @@ if TYPE_CHECKING:
34
35
  from sentry_sdk._types import Event, Hint
35
36
 
36
37
 
37
- _RUNTIME_CONTEXT = {
38
+ _RUNTIME_CONTEXT: dict[str, object] = {
38
39
  "name": platform.python_implementation(),
39
40
  "version": "%s.%s.%s" % (sys.version_info[:3]),
40
41
  "build": sys.version,
41
- } # type: dict[str, object]
42
+ }
42
43
 
43
44
 
44
45
  class StdlibIntegration(Integration):
45
46
  identifier = "stdlib"
46
47
 
47
48
  @staticmethod
48
- def setup_once():
49
- # type: () -> None
49
+ def setup_once() -> None:
50
50
  _install_httplib()
51
51
  _install_subprocess()
52
52
 
53
53
  @add_global_event_processor
54
- def add_python_runtime_context(event, hint):
55
- # type: (Event, Hint) -> Optional[Event]
54
+ def add_python_runtime_context(event: Event, hint: Hint) -> Optional[Event]:
56
55
  if sentry_sdk.get_client().get_integration(StdlibIntegration) is not None:
57
56
  contexts = event.setdefault("contexts", {})
58
57
  if isinstance(contexts, dict) and "runtime" not in contexts:
@@ -61,13 +60,13 @@ class StdlibIntegration(Integration):
61
60
  return event
62
61
 
63
62
 
64
- def _install_httplib():
65
- # type: () -> None
63
+ def _install_httplib() -> None:
66
64
  real_putrequest = HTTPConnection.putrequest
67
65
  real_getresponse = HTTPConnection.getresponse
68
66
 
69
- def putrequest(self, method, url, *args, **kwargs):
70
- # type: (HTTPConnection, str, str, *Any, **Any) -> Any
67
+ def putrequest(
68
+ self: HTTPConnection, method: str, url: str, *args: Any, **kwargs: Any
69
+ ) -> Any:
71
70
  host = self.host
72
71
  port = self.port
73
72
  default_port = self.default_port
@@ -134,8 +133,7 @@ def _install_httplib():
134
133
 
135
134
  return rv
136
135
 
137
- def getresponse(self, *args, **kwargs):
138
- # type: (HTTPConnection, *Any, **Any) -> Any
136
+ def getresponse(self: HTTPConnection, *args: Any, **kwargs: Any) -> Any:
139
137
  span = getattr(self, "_sentrysdk_span", None)
140
138
 
141
139
  if span is None:
@@ -167,8 +165,13 @@ def _install_httplib():
167
165
  HTTPConnection.getresponse = getresponse # type: ignore[method-assign]
168
166
 
169
167
 
170
- def _init_argument(args, kwargs, name, position, setdefault_callback=None):
171
- # type: (List[Any], Dict[Any, Any], str, int, Optional[Callable[[Any], Any]]) -> Any
168
+ def _init_argument(
169
+ args: List[Any],
170
+ kwargs: Dict[Any, Any],
171
+ name: str,
172
+ position: int,
173
+ setdefault_callback: Optional[Callable[[Any], Any]] = None,
174
+ ) -> Any:
172
175
  """
173
176
  given (*args, **kwargs) of a function call, retrieve (and optionally set a
174
177
  default for) an argument by either name or position.
@@ -198,13 +201,13 @@ def _init_argument(args, kwargs, name, position, setdefault_callback=None):
198
201
  return rv
199
202
 
200
203
 
201
- def _install_subprocess():
202
- # type: () -> None
204
+ def _install_subprocess() -> None:
203
205
  old_popen_init = subprocess.Popen.__init__
204
206
 
205
207
  @ensure_integration_enabled(StdlibIntegration, old_popen_init)
206
- def sentry_patched_popen_init(self, *a, **kw):
207
- # type: (subprocess.Popen[Any], *Any, **Any) -> None
208
+ def sentry_patched_popen_init(
209
+ self: subprocess.Popen[Any], *a: Any, **kw: Any
210
+ ) -> None:
208
211
  # Convert from tuple to list to be able to set values.
209
212
  a = list(a)
210
213
 
@@ -279,8 +282,9 @@ def _install_subprocess():
279
282
  old_popen_wait = subprocess.Popen.wait
280
283
 
281
284
  @ensure_integration_enabled(StdlibIntegration, old_popen_wait)
282
- def sentry_patched_popen_wait(self, *a, **kw):
283
- # type: (subprocess.Popen[Any], *Any, **Any) -> Any
285
+ def sentry_patched_popen_wait(
286
+ self: subprocess.Popen[Any], *a: Any, **kw: Any
287
+ ) -> Any:
284
288
  with sentry_sdk.start_span(
285
289
  op=OP.SUBPROCESS_WAIT,
286
290
  origin="auto.subprocess.stdlib.subprocess",
@@ -294,8 +298,9 @@ def _install_subprocess():
294
298
  old_popen_communicate = subprocess.Popen.communicate
295
299
 
296
300
  @ensure_integration_enabled(StdlibIntegration, old_popen_communicate)
297
- def sentry_patched_popen_communicate(self, *a, **kw):
298
- # type: (subprocess.Popen[Any], *Any, **Any) -> Any
301
+ def sentry_patched_popen_communicate(
302
+ self: subprocess.Popen[Any], *a: Any, **kw: Any
303
+ ) -> Any:
299
304
  with sentry_sdk.start_span(
300
305
  op=OP.SUBPROCESS_COMMUNICATE,
301
306
  origin="auto.subprocess.stdlib.subprocess",
@@ -307,6 +312,5 @@ def _install_subprocess():
307
312
  subprocess.Popen.communicate = sentry_patched_popen_communicate # type: ignore
308
313
 
309
314
 
310
- def get_subprocess_traceparent_headers():
311
- # type: () -> EnvironHeaders
315
+ def get_subprocess_traceparent_headers() -> EnvironHeaders:
312
316
  return EnvironHeaders(os.environ, prefix="SUBPROCESS_")
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import functools
2
3
  import hashlib
3
4
  from inspect import isawaitable
@@ -62,8 +63,7 @@ class StrawberryIntegration(Integration):
62
63
  identifier = "strawberry"
63
64
  origin = f"auto.graphql.{identifier}"
64
65
 
65
- def __init__(self, async_execution=None):
66
- # type: (Optional[bool]) -> None
66
+ def __init__(self, async_execution: Optional[bool] = None) -> None:
67
67
  if async_execution not in (None, False, True):
68
68
  raise ValueError(
69
69
  'Invalid value for async_execution: "{}" (must be bool)'.format(
@@ -73,8 +73,7 @@ class StrawberryIntegration(Integration):
73
73
  self.async_execution = async_execution
74
74
 
75
75
  @staticmethod
76
- def setup_once():
77
- # type: () -> None
76
+ def setup_once() -> None:
78
77
  version = package_version("strawberry-graphql")
79
78
  _check_minimum_version(StrawberryIntegration, version, "strawberry-graphql")
80
79
 
@@ -82,13 +81,11 @@ class StrawberryIntegration(Integration):
82
81
  _patch_views()
83
82
 
84
83
 
85
- def _patch_schema_init():
86
- # type: () -> None
84
+ def _patch_schema_init() -> None:
87
85
  old_schema_init = Schema.__init__
88
86
 
89
87
  @functools.wraps(old_schema_init)
90
- def _sentry_patched_schema_init(self, *args, **kwargs):
91
- # type: (Schema, Any, Any) -> None
88
+ def _sentry_patched_schema_init(self: Schema, *args: Any, **kwargs: Any) -> None:
92
89
  integration = sentry_sdk.get_client().get_integration(StrawberryIntegration)
93
90
  if integration is None:
94
91
  return old_schema_init(self, *args, **kwargs)
@@ -121,17 +118,15 @@ def _patch_schema_init():
121
118
 
122
119
  class SentryAsyncExtension(SchemaExtension):
123
120
  def __init__(
124
- self,
121
+ self: Any,
125
122
  *,
126
- execution_context=None,
127
- ):
128
- # type: (Any, Optional[ExecutionContext]) -> None
123
+ execution_context: Optional[ExecutionContext] = None,
124
+ ) -> None:
129
125
  if execution_context:
130
126
  self.execution_context = execution_context
131
127
 
132
128
  @cached_property
133
- def _resource_name(self):
134
- # type: () -> str
129
+ def _resource_name(self) -> str:
135
130
  query_hash = self.hash_query(self.execution_context.query) # type: ignore
136
131
 
137
132
  if self.execution_context.operation_name:
@@ -139,12 +134,10 @@ class SentryAsyncExtension(SchemaExtension):
139
134
 
140
135
  return query_hash
141
136
 
142
- def hash_query(self, query):
143
- # type: (str) -> str
137
+ def hash_query(self, query: str) -> str:
144
138
  return hashlib.md5(query.encode("utf-8")).hexdigest()
145
139
 
146
- def on_operation(self):
147
- # type: () -> Generator[None, None, None]
140
+ def on_operation(self) -> Generator[None, None, None]:
148
141
  self._operation_name = self.execution_context.operation_name
149
142
 
150
143
  operation_type = "query"
@@ -205,8 +198,7 @@ class SentryAsyncExtension(SchemaExtension):
205
198
  if root_span:
206
199
  root_span.op = op
207
200
 
208
- def on_validate(self):
209
- # type: () -> Generator[None, None, None]
201
+ def on_validate(self) -> Generator[None, None, None]:
210
202
  with sentry_sdk.start_span(
211
203
  op=OP.GRAPHQL_VALIDATE,
212
204
  name="validation",
@@ -214,8 +206,7 @@ class SentryAsyncExtension(SchemaExtension):
214
206
  ):
215
207
  yield
216
208
 
217
- def on_parse(self):
218
- # type: () -> Generator[None, None, None]
209
+ def on_parse(self) -> Generator[None, None, None]:
219
210
  with sentry_sdk.start_span(
220
211
  op=OP.GRAPHQL_PARSE,
221
212
  name="parsing",
@@ -223,12 +214,21 @@ class SentryAsyncExtension(SchemaExtension):
223
214
  ):
224
215
  yield
225
216
 
226
- def should_skip_tracing(self, _next, info):
227
- # type: (Callable[[Any, GraphQLResolveInfo, Any, Any], Any], GraphQLResolveInfo) -> bool
217
+ def should_skip_tracing(
218
+ self,
219
+ _next: Callable[[Any, GraphQLResolveInfo, Any, Any], Any],
220
+ info: GraphQLResolveInfo,
221
+ ) -> bool:
228
222
  return strawberry_should_skip_tracing(_next, info)
229
223
 
230
- async def _resolve(self, _next, root, info, *args, **kwargs):
231
- # type: (Callable[[Any, GraphQLResolveInfo, Any, Any], Any], Any, GraphQLResolveInfo, str, Any) -> Any
224
+ async def _resolve(
225
+ self,
226
+ _next: Callable[[Any, GraphQLResolveInfo, Any, Any], Any],
227
+ root: Any,
228
+ info: GraphQLResolveInfo,
229
+ *args: str,
230
+ **kwargs: Any,
231
+ ) -> Any:
232
232
  result = _next(root, info, *args, **kwargs)
233
233
 
234
234
  if isawaitable(result):
@@ -236,8 +236,14 @@ class SentryAsyncExtension(SchemaExtension):
236
236
 
237
237
  return result
238
238
 
239
- async def resolve(self, _next, root, info, *args, **kwargs):
240
- # type: (Callable[[Any, GraphQLResolveInfo, Any, Any], Any], Any, GraphQLResolveInfo, str, Any) -> Any
239
+ async def resolve(
240
+ self,
241
+ _next: Callable[[Any, GraphQLResolveInfo, Any, Any], Any],
242
+ root: Any,
243
+ info: GraphQLResolveInfo,
244
+ *args: str,
245
+ **kwargs: Any,
246
+ ) -> Any:
241
247
  if self.should_skip_tracing(_next, info):
242
248
  return await self._resolve(_next, root, info, *args, **kwargs)
243
249
 
@@ -257,8 +263,14 @@ class SentryAsyncExtension(SchemaExtension):
257
263
 
258
264
 
259
265
  class SentrySyncExtension(SentryAsyncExtension):
260
- def resolve(self, _next, root, info, *args, **kwargs):
261
- # type: (Callable[[Any, Any, Any, Any], Any], Any, GraphQLResolveInfo, str, Any) -> Any
266
+ def resolve(
267
+ self,
268
+ _next: Callable[[Any, Any, Any, Any], Any],
269
+ root: Any,
270
+ info: GraphQLResolveInfo,
271
+ *args: str,
272
+ **kwargs: Any,
273
+ ) -> Any:
262
274
  if self.should_skip_tracing(_next, info):
263
275
  return _next(root, info, *args, **kwargs)
264
276
 
@@ -277,24 +289,26 @@ class SentrySyncExtension(SentryAsyncExtension):
277
289
  return _next(root, info, *args, **kwargs)
278
290
 
279
291
 
280
- def _patch_views():
281
- # type: () -> None
292
+ def _patch_views() -> None:
282
293
  old_async_view_handle_errors = async_base_view.AsyncBaseHTTPView._handle_errors
283
294
  old_sync_view_handle_errors = sync_base_view.SyncBaseHTTPView._handle_errors
284
295
 
285
- def _sentry_patched_async_view_handle_errors(self, errors, response_data):
286
- # type: (Any, List[GraphQLError], GraphQLHTTPResponse) -> None
296
+ def _sentry_patched_async_view_handle_errors(
297
+ self: Any, errors: List[GraphQLError], response_data: GraphQLHTTPResponse
298
+ ) -> None:
287
299
  old_async_view_handle_errors(self, errors, response_data)
288
300
  _sentry_patched_handle_errors(self, errors, response_data)
289
301
 
290
- def _sentry_patched_sync_view_handle_errors(self, errors, response_data):
291
- # type: (Any, List[GraphQLError], GraphQLHTTPResponse) -> None
302
+ def _sentry_patched_sync_view_handle_errors(
303
+ self: Any, errors: List[GraphQLError], response_data: GraphQLHTTPResponse
304
+ ) -> None:
292
305
  old_sync_view_handle_errors(self, errors, response_data)
293
306
  _sentry_patched_handle_errors(self, errors, response_data)
294
307
 
295
308
  @ensure_integration_enabled(StrawberryIntegration)
296
- def _sentry_patched_handle_errors(self, errors, response_data):
297
- # type: (Any, List[GraphQLError], GraphQLHTTPResponse) -> None
309
+ def _sentry_patched_handle_errors(
310
+ self: Any, errors: List[GraphQLError], response_data: GraphQLHTTPResponse
311
+ ) -> None:
298
312
  if not errors:
299
313
  return
300
314
 
@@ -322,18 +336,18 @@ def _patch_views():
322
336
  )
323
337
 
324
338
 
325
- def _make_request_event_processor(execution_context):
326
- # type: (ExecutionContext) -> EventProcessor
339
+ def _make_request_event_processor(
340
+ execution_context: ExecutionContext,
341
+ ) -> EventProcessor:
327
342
 
328
- def inner(event, hint):
329
- # type: (Event, dict[str, Any]) -> Event
343
+ def inner(event: Event, hint: dict[str, Any]) -> Event:
330
344
  with capture_internal_exceptions():
331
345
  if should_send_default_pii():
332
346
  request_data = event.setdefault("request", {})
333
347
  request_data["api_target"] = "graphql"
334
348
 
335
349
  if not request_data.get("data"):
336
- data = {"query": execution_context.query} # type: dict[str, Any]
350
+ data: dict[str, Any] = {"query": execution_context.query}
337
351
  if execution_context.variables:
338
352
  data["variables"] = execution_context.variables
339
353
  if execution_context.operation_name:
@@ -352,11 +366,11 @@ def _make_request_event_processor(execution_context):
352
366
  return inner
353
367
 
354
368
 
355
- def _make_response_event_processor(response_data):
356
- # type: (GraphQLHTTPResponse) -> EventProcessor
369
+ def _make_response_event_processor(
370
+ response_data: GraphQLHTTPResponse,
371
+ ) -> EventProcessor:
357
372
 
358
- def inner(event, hint):
359
- # type: (Event, dict[str, Any]) -> Event
373
+ def inner(event: Event, hint: dict[str, Any]) -> Event:
360
374
  with capture_internal_exceptions():
361
375
  if should_send_default_pii():
362
376
  contexts = event.setdefault("contexts", {})
@@ -367,8 +381,7 @@ def _make_response_event_processor(response_data):
367
381
  return inner
368
382
 
369
383
 
370
- def _guess_if_using_async(extensions):
371
- # type: (List[SchemaExtension]) -> bool
384
+ def _guess_if_using_async(extensions: List[SchemaExtension]) -> bool:
372
385
  return bool(
373
386
  {"starlette", "starlite", "litestar", "fastapi"} & set(_get_installed_modules())
374
387
  )
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import functools
2
3
  import sys
3
4
 
@@ -24,23 +25,19 @@ class SysExitIntegration(Integration):
24
25
 
25
26
  identifier = "sys_exit"
26
27
 
27
- def __init__(self, *, capture_successful_exits=False):
28
- # type: (bool) -> None
28
+ def __init__(self, *, capture_successful_exits: bool = False) -> None:
29
29
  self._capture_successful_exits = capture_successful_exits
30
30
 
31
31
  @staticmethod
32
- def setup_once():
33
- # type: () -> None
32
+ def setup_once() -> None:
34
33
  SysExitIntegration._patch_sys_exit()
35
34
 
36
35
  @staticmethod
37
- def _patch_sys_exit():
38
- # type: () -> None
39
- old_exit = sys.exit # type: Callable[[Union[str, int, None]], NoReturn]
36
+ def _patch_sys_exit() -> None:
37
+ old_exit: Callable[[Union[str, int, None]], NoReturn] = sys.exit
40
38
 
41
39
  @functools.wraps(old_exit)
42
- def sentry_patched_exit(__status=0):
43
- # type: (Union[str, int, None]) -> NoReturn
40
+ def sentry_patched_exit(__status: Union[str, int, None] = 0) -> NoReturn:
44
41
  # @ensure_integration_enabled ensures that this is non-None
45
42
  integration = sentry_sdk.get_client().get_integration(SysExitIntegration)
46
43
  if integration is None:
@@ -60,8 +57,7 @@ class SysExitIntegration(Integration):
60
57
  sys.exit = sentry_patched_exit
61
58
 
62
59
 
63
- def _capture_exception(exc):
64
- # type: (SystemExit) -> None
60
+ def _capture_exception(exc: SystemExit) -> None:
65
61
  event, hint = event_from_exception(
66
62
  exc,
67
63
  client_options=sentry_sdk.get_client().options,
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import sys
2
3
  import warnings
3
4
  from functools import wraps
@@ -28,13 +29,11 @@ if TYPE_CHECKING:
28
29
  class ThreadingIntegration(Integration):
29
30
  identifier = "threading"
30
31
 
31
- def __init__(self, propagate_scope=True):
32
- # type: (bool) -> None
32
+ def __init__(self, propagate_scope: bool = True) -> None:
33
33
  self.propagate_scope = propagate_scope
34
34
 
35
35
  @staticmethod
36
- def setup_once():
37
- # type: () -> None
36
+ def setup_once() -> None:
38
37
  old_start = Thread.start
39
38
 
40
39
  try:
@@ -47,8 +46,7 @@ class ThreadingIntegration(Integration):
47
46
  channels_version = None
48
47
 
49
48
  @wraps(old_start)
50
- def sentry_start(self, *a, **kw):
51
- # type: (Thread, *Any, **Any) -> Any
49
+ def sentry_start(self: Thread, *a: Any, **kw: Any) -> Any:
52
50
  integration = sentry_sdk.get_client().get_integration(ThreadingIntegration)
53
51
  if integration is None:
54
52
  return old_start(self, *a, **kw)
@@ -98,13 +96,14 @@ class ThreadingIntegration(Integration):
98
96
  Thread.start = sentry_start # type: ignore
99
97
 
100
98
 
101
- def _wrap_run(isolation_scope_to_use, current_scope_to_use, old_run_func):
102
- # type: (sentry_sdk.Scope, sentry_sdk.Scope, F) -> F
99
+ def _wrap_run(
100
+ isolation_scope_to_use: sentry_sdk.Scope,
101
+ current_scope_to_use: sentry_sdk.Scope,
102
+ old_run_func: F,
103
+ ) -> F:
103
104
  @wraps(old_run_func)
104
- def run(*a, **kw):
105
- # type: (*Any, **Any) -> Any
106
- def _run_old_run_func():
107
- # type: () -> Any
105
+ def run(*a: Any, **kw: Any) -> Any:
106
+ def _run_old_run_func() -> Any:
108
107
  try:
109
108
  self = current_thread()
110
109
  return old_run_func(self, *a, **kw)
@@ -118,8 +117,7 @@ def _wrap_run(isolation_scope_to_use, current_scope_to_use, old_run_func):
118
117
  return run # type: ignore
119
118
 
120
119
 
121
- def _capture_exception():
122
- # type: () -> ExcInfo
120
+ def _capture_exception() -> ExcInfo:
123
121
  exc_info = sys.exc_info()
124
122
 
125
123
  client = sentry_sdk.get_client()
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import weakref
2
3
  import contextlib
3
4
  from inspect import iscoroutinefunction
@@ -56,8 +57,7 @@ class TornadoIntegration(Integration):
56
57
  origin = f"auto.http.{identifier}"
57
58
 
58
59
  @staticmethod
59
- def setup_once():
60
- # type: () -> None
60
+ def setup_once() -> None:
61
61
  _check_minimum_version(TornadoIntegration, TORNADO_VERSION)
62
62
 
63
63
  if not HAS_REAL_CONTEXTVARS:
@@ -77,16 +77,18 @@ class TornadoIntegration(Integration):
77
77
  if awaitable:
78
78
  # Starting Tornado 6 RequestHandler._execute method is a standard Python coroutine (async/await)
79
79
  # In that case our method should be a coroutine function too
80
- async def sentry_execute_request_handler(self, *args, **kwargs):
81
- # type: (RequestHandler, *Any, **Any) -> Any
80
+ async def sentry_execute_request_handler(
81
+ self: RequestHandler, *args: Any, **kwargs: Any
82
+ ) -> Any:
82
83
  with _handle_request_impl(self):
83
84
  return await old_execute(self, *args, **kwargs)
84
85
 
85
86
  else:
86
87
 
87
88
  @coroutine # type: ignore
88
- def sentry_execute_request_handler(self, *args, **kwargs): # type: ignore
89
- # type: (RequestHandler, *Any, **Any) -> Any
89
+ def sentry_execute_request_handler(
90
+ self: RequestHandler, *args: Any, **kwargs: Any
91
+ ) -> Any:
90
92
  with _handle_request_impl(self):
91
93
  result = yield from old_execute(self, *args, **kwargs)
92
94
  return result
@@ -95,8 +97,14 @@ class TornadoIntegration(Integration):
95
97
 
96
98
  old_log_exception = RequestHandler.log_exception
97
99
 
98
- def sentry_log_exception(self, ty, value, tb, *args, **kwargs):
99
- # type: (Any, type, BaseException, Any, *Any, **Any) -> Optional[Any]
100
+ def sentry_log_exception(
101
+ self: Any,
102
+ ty: type,
103
+ value: BaseException,
104
+ tb: Any,
105
+ *args: Any,
106
+ **kwargs: Any,
107
+ ) -> Optional[Any]:
100
108
  _capture_exception(ty, value, tb)
101
109
  return old_log_exception(self, ty, value, tb, *args, **kwargs)
102
110
 
@@ -104,8 +112,7 @@ class TornadoIntegration(Integration):
104
112
 
105
113
 
106
114
  @contextlib.contextmanager
107
- def _handle_request_impl(self):
108
- # type: (RequestHandler) -> Generator[None, None, None]
115
+ def _handle_request_impl(self: RequestHandler) -> Generator[None, None, None]:
109
116
  integration = sentry_sdk.get_client().get_integration(TornadoIntegration)
110
117
 
111
118
  if integration is None:
@@ -136,8 +143,7 @@ def _handle_request_impl(self):
136
143
 
137
144
 
138
145
  @ensure_integration_enabled(TornadoIntegration)
139
- def _capture_exception(ty, value, tb):
140
- # type: (type, BaseException, Any) -> None
146
+ def _capture_exception(ty: type, value: BaseException, tb: Any) -> None:
141
147
  if isinstance(value, HTTPError):
142
148
  return
143
149
 
@@ -150,10 +156,8 @@ def _capture_exception(ty, value, tb):
150
156
  sentry_sdk.capture_event(event, hint=hint)
151
157
 
152
158
 
153
- def _make_event_processor(weak_handler):
154
- # type: (Callable[[], RequestHandler]) -> EventProcessor
155
- def tornado_processor(event, hint):
156
- # type: (Event, dict[str, Any]) -> Event
159
+ def _make_event_processor(weak_handler: Callable[[], RequestHandler]) -> EventProcessor:
160
+ def tornado_processor(event: Event, hint: dict[str, Any]) -> Event:
157
161
  handler = weak_handler()
158
162
  if handler is None:
159
163
  return event
@@ -192,42 +196,34 @@ def _make_event_processor(weak_handler):
192
196
 
193
197
 
194
198
  class TornadoRequestExtractor(RequestExtractor):
195
- def content_length(self):
196
- # type: () -> int
199
+ def content_length(self) -> int:
197
200
  if self.request.body is None:
198
201
  return 0
199
202
  return len(self.request.body)
200
203
 
201
- def cookies(self):
202
- # type: () -> Dict[str, str]
204
+ def cookies(self) -> Dict[str, str]:
203
205
  return {k: v.value for k, v in self.request.cookies.items()}
204
206
 
205
- def raw_data(self):
206
- # type: () -> bytes
207
+ def raw_data(self) -> bytes:
207
208
  return self.request.body
208
209
 
209
- def form(self):
210
- # type: () -> Dict[str, Any]
210
+ def form(self) -> Dict[str, Any]:
211
211
  return {
212
212
  k: [v.decode("latin1", "replace") for v in vs]
213
213
  for k, vs in self.request.body_arguments.items()
214
214
  }
215
215
 
216
- def is_json(self):
217
- # type: () -> bool
216
+ def is_json(self) -> bool:
218
217
  return _is_json_content_type(self.request.headers.get("content-type"))
219
218
 
220
- def files(self):
221
- # type: () -> Dict[str, Any]
219
+ def files(self) -> Dict[str, Any]:
222
220
  return {k: v[0] for k, v in self.request.files.items() if v}
223
221
 
224
- def size_of_file(self, file):
225
- # type: (Any) -> int
222
+ def size_of_file(self, file: Any) -> int:
226
223
  return len(file.body or ())
227
224
 
228
225
 
229
- def _prepopulate_attributes(request):
230
- # type: (HTTPServerRequest) -> dict[str, Any]
226
+ def _prepopulate_attributes(request: HTTPServerRequest) -> dict[str, Any]:
231
227
  # https://www.tornadoweb.org/en/stable/httputil.html#tornado.httputil.HTTPServerRequest
232
228
  attributes = {}
233
229
 
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import sentry_sdk
2
3
  from sentry_sdk.integrations import _check_minimum_version, Integration
3
4
  from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
@@ -15,11 +16,11 @@ class TrytondWSGIIntegration(Integration):
15
16
  identifier = "trytond_wsgi"
16
17
  origin = f"auto.http.{identifier}"
17
18
 
18
- def __init__(self): # type: () -> None
19
+ def __init__(self) -> None:
19
20
  pass
20
21
 
21
22
  @staticmethod
22
- def setup_once(): # type: () -> None
23
+ def setup_once() -> None:
23
24
  _check_minimum_version(TrytondWSGIIntegration, trytond_version)
24
25
 
25
26
  app.wsgi_app = SentryWsgiMiddleware(
@@ -28,7 +29,7 @@ class TrytondWSGIIntegration(Integration):
28
29
  )
29
30
 
30
31
  @ensure_integration_enabled(TrytondWSGIIntegration)
31
- def error_handler(e): # type: (Exception) -> None
32
+ def error_handler(e: Exception) -> None:
32
33
  if isinstance(e, TrytonException):
33
34
  return
34
35
  else:
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import sentry_sdk
2
3
  from sentry_sdk.utils import (
3
4
  capture_internal_exceptions,
@@ -30,15 +31,16 @@ class TyperIntegration(Integration):
30
31
  identifier = "typer"
31
32
 
32
33
  @staticmethod
33
- def setup_once():
34
- # type: () -> None
34
+ def setup_once() -> None:
35
35
  typer.main.except_hook = _make_excepthook(typer.main.except_hook) # type: ignore
36
36
 
37
37
 
38
- def _make_excepthook(old_excepthook):
39
- # type: (Excepthook) -> Excepthook
40
- def sentry_sdk_excepthook(type_, value, traceback):
41
- # type: (Type[BaseException], BaseException, Optional[TracebackType]) -> None
38
+ def _make_excepthook(old_excepthook: Excepthook) -> Excepthook:
39
+ def sentry_sdk_excepthook(
40
+ type_: Type[BaseException],
41
+ value: BaseException,
42
+ traceback: Optional[TracebackType],
43
+ ) -> None:
42
44
  integration = sentry_sdk.get_client().get_integration(TyperIntegration)
43
45
 
44
46
  # Note: If we replace this with ensure_integration_enabled then