|
4 | 4 | import random
|
5 | 5 | import socket
|
6 | 6 |
|
7 |
| -from sentry_sdk._compat import datetime_utcnow, string_types, text_type, iteritems |
| 7 | +from sentry_sdk._compat import ( |
| 8 | + datetime_utcnow, |
| 9 | + string_types, |
| 10 | + text_type, |
| 11 | + iteritems, |
| 12 | + check_uwsgi_thread_support, |
| 13 | +) |
8 | 14 | from sentry_sdk.utils import (
|
9 | 15 | capture_internal_exceptions,
|
10 | 16 | current_stacktrace,
|
|
18 | 24 | )
|
19 | 25 | from sentry_sdk.serializer import serialize
|
20 | 26 | from sentry_sdk.tracing import trace, has_tracing_enabled
|
21 |
| -from sentry_sdk.transport import make_transport |
| 27 | +from sentry_sdk.transport import HttpTransport, make_transport |
22 | 28 | from sentry_sdk.consts import (
|
23 | 29 | DEFAULT_MAX_VALUE_LENGTH,
|
24 | 30 | DEFAULT_OPTIONS,
|
@@ -249,28 +255,15 @@ def _capture_envelope(envelope):
|
249 | 255 |
|
250 | 256 | self.metrics_aggregator = None # type: Optional[MetricsAggregator]
|
251 | 257 | experiments = self.options.get("_experiments", {})
|
252 |
| - if experiments.get("enable_metrics", True) or experiments.get( |
253 |
| - "force_enable_metrics", False |
254 |
| - ): |
255 |
| - try: |
256 |
| - import uwsgi # type: ignore |
257 |
| - except ImportError: |
258 |
| - uwsgi = None |
259 |
| - |
260 |
| - if uwsgi is not None and not experiments.get( |
261 |
| - "force_enable_metrics", False |
262 |
| - ): |
263 |
| - logger.warning("Metrics currently not supported with uWSGI.") |
264 |
| - |
265 |
| - else: |
266 |
| - from sentry_sdk.metrics import MetricsAggregator |
267 |
| - |
268 |
| - self.metrics_aggregator = MetricsAggregator( |
269 |
| - capture_func=_capture_envelope, |
270 |
| - enable_code_locations=bool( |
271 |
| - experiments.get("metric_code_locations", True) |
272 |
| - ), |
273 |
| - ) |
| 258 | + if experiments.get("enable_metrics", True): |
| 259 | + from sentry_sdk.metrics import MetricsAggregator |
| 260 | + |
| 261 | + self.metrics_aggregator = MetricsAggregator( |
| 262 | + capture_func=_capture_envelope, |
| 263 | + enable_code_locations=bool( |
| 264 | + experiments.get("metric_code_locations", True) |
| 265 | + ), |
| 266 | + ) |
274 | 267 |
|
275 | 268 | max_request_body_size = ("always", "never", "small", "medium")
|
276 | 269 | if self.options["max_request_body_size"] not in max_request_body_size:
|
@@ -316,6 +309,16 @@ def _capture_envelope(envelope):
|
316 | 309 |
|
317 | 310 | self._setup_instrumentation(self.options.get("functions_to_trace", []))
|
318 | 311 |
|
| 312 | + if ( |
| 313 | + self.monitor |
| 314 | + or self.metrics_aggregator |
| 315 | + or has_profiling_enabled(self.options) |
| 316 | + or isinstance(self.transport, HttpTransport) |
| 317 | + ): |
| 318 | + # If we have anything on that could spawn a background thread, we |
| 319 | + # need to check if it's safe to use them. |
| 320 | + check_uwsgi_thread_support() |
| 321 | + |
319 | 322 | @property
|
320 | 323 | def dsn(self):
|
321 | 324 | # type: () -> Optional[str]
|
|
0 commit comments