Skip to content

Commit f23bdd3

Browse files
authored
fix(metrics): Turn off metrics for uWSGI (#2720)
1 parent c77a123 commit f23bdd3

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

sentry_sdk/client.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,28 @@ def _capture_envelope(envelope):
249249

250250
self.metrics_aggregator = None # type: Optional[MetricsAggregator]
251251
experiments = self.options.get("_experiments", {})
252-
if experiments.get("enable_metrics", True):
253-
from sentry_sdk.metrics import MetricsAggregator
254-
255-
self.metrics_aggregator = MetricsAggregator(
256-
capture_func=_capture_envelope,
257-
enable_code_locations=bool(
258-
experiments.get("metric_code_locations", True)
259-
),
260-
)
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+
)
261274

262275
max_request_body_size = ("always", "never", "small", "medium")
263276
if self.options["max_request_body_size"] not in max_request_body_size:

sentry_sdk/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"transport_zlib_compression_level": Optional[int],
4747
"transport_num_pools": Optional[int],
4848
"enable_metrics": Optional[bool],
49+
"force_enable_metrics": Optional[bool],
4950
"metrics_summary_sample_rate": Optional[float],
5051
"should_summarize_metric": Optional[Callable[[str, MetricTags], bool]],
5152
"before_emit_metric": Optional[Callable[[str, MetricTags], bool]],

0 commit comments

Comments
 (0)