Skip to content

Commit

Permalink
fix(metrics): Turn off metrics for uWSGI (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Feb 9, 2024
1 parent c77a123 commit f23bdd3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
31 changes: 22 additions & 9 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,28 @@ def _capture_envelope(envelope):

self.metrics_aggregator = None # type: Optional[MetricsAggregator]
experiments = self.options.get("_experiments", {})
if experiments.get("enable_metrics", True):
from sentry_sdk.metrics import MetricsAggregator

self.metrics_aggregator = MetricsAggregator(
capture_func=_capture_envelope,
enable_code_locations=bool(
experiments.get("metric_code_locations", True)
),
)
if experiments.get("enable_metrics", True) or experiments.get(
"force_enable_metrics", False
):
try:
import uwsgi # type: ignore
except ImportError:
uwsgi = None

if uwsgi is not None and not experiments.get(
"force_enable_metrics", False
):
logger.warning("Metrics currently not supported with uWSGI.")

else:
from sentry_sdk.metrics import MetricsAggregator

self.metrics_aggregator = MetricsAggregator(
capture_func=_capture_envelope,
enable_code_locations=bool(
experiments.get("metric_code_locations", True)
),
)

max_request_body_size = ("always", "never", "small", "medium")
if self.options["max_request_body_size"] not in max_request_body_size:
Expand Down
1 change: 1 addition & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"transport_zlib_compression_level": Optional[int],
"transport_num_pools": Optional[int],
"enable_metrics": Optional[bool],
"force_enable_metrics": Optional[bool],
"metrics_summary_sample_rate": Optional[float],
"should_summarize_metric": Optional[Callable[[str, MetricTags], bool]],
"before_emit_metric": Optional[Callable[[str, MetricTags], bool]],
Expand Down

0 comments on commit f23bdd3

Please sign in to comment.