|
@@ -6,11 +6,7 @@ import pytest
|
|
|
from sentry_sdk import Client, Hub, Transport
|
|
|
|
|
|
from sentry.metrics.composite_experimental import CompositeExperimentalMetricsBackend
|
|
|
-from sentry.metrics.minimetrics import (
|
|
|
- MiniMetricsMetricsBackend,
|
|
|
- before_emit_metric,
|
|
|
- have_minimetrics,
|
|
|
-)
|
|
|
+from sentry.metrics.minimetrics import MiniMetricsMetricsBackend, before_emit_metric
|
|
|
from sentry.testutils.helpers import override_options
|
|
|
|
|
|
|
|
@@ -98,7 +94,6 @@ def backend():
|
|
|
yield rv
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.enable_capture_envelope": True,
|
|
@@ -122,7 +117,6 @@ def test_incr_called_with_no_tags(backend, hub):
|
|
|
assert len(hub.client.metrics_aggregator.buckets) == 0
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.enable_capture_envelope": True,
|
|
@@ -146,7 +140,6 @@ def test_incr_called_with_no_tags_and_no_common_tags(backend, hub):
|
|
|
assert len(hub.client.metrics_aggregator.buckets) == 0
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.enable_capture_envelope": True,
|
|
@@ -167,7 +160,6 @@ def test_incr_called_with_tag_value_as_list(backend, hub):
|
|
|
assert len(hub.client.metrics_aggregator.buckets) == 0
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.enable_capture_envelope": True,
|
|
@@ -190,7 +182,6 @@ def test_gauge_as_count(backend, hub):
|
|
|
assert len(hub.client.metrics_aggregator.buckets) == 0
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.enable_capture_envelope": True,
|
|
@@ -213,7 +204,6 @@ def test_gauge(backend, hub):
|
|
|
assert len(hub.client.metrics_aggregator.buckets) == 0
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.enable_capture_envelope": True,
|
|
@@ -255,7 +245,6 @@ def test_composite_backend_does_not_recurse(hub):
|
|
|
assert len(hub.client.metrics_aggregator.buckets) == 0
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.minimetrics_sample_rate": 1.0,
|
|
@@ -276,7 +265,6 @@ def test_unit_is_correctly_propagated_for_incr(sentry_sdk, unit, expected_unit):
|
|
|
assert sentry_sdk.metrics.incr.call_args.kwargs == {**params, "unit": expected_unit}
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.minimetrics_sample_rate": 1.0,
|
|
@@ -293,7 +281,6 @@ def test_unit_is_correctly_propagated_for_timing(sentry_sdk, unit, expected_unit
|
|
|
assert sentry_sdk.metrics.distribution.call_args.kwargs == {**params, "unit": expected_unit}
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{"delightful_metrics.minimetrics_sample_rate": 1.0, "delightful_metrics.emit_gauges": True}
|
|
|
)
|
|
@@ -308,7 +295,6 @@ def test_unit_is_correctly_propagated_for_gauge(sentry_sdk, unit, expected_unit)
|
|
|
assert sentry_sdk.metrics.gauge.call_args.kwargs == {**params, "unit": expected_unit}
|
|
|
|
|
|
|
|
|
-@pytest.mark.skipif(not have_minimetrics, reason="no minimetrics")
|
|
|
@override_options(
|
|
|
{
|
|
|
"delightful_metrics.minimetrics_sample_rate": 1.0,
|
|
@@ -325,13 +311,15 @@ def test_unit_is_correctly_propagated_for_distribution(sentry_sdk, unit, expecte
|
|
|
assert sentry_sdk.metrics.distribution.call_args.kwargs == {**params, "unit": expected_unit}
|
|
|
|
|
|
|
|
|
-def test_did_you_remove_type_ignore():
|
|
|
- from importlib.metadata import version
|
|
|
-
|
|
|
- ver = tuple(map(int, version("sentry-sdk").split(".")[:2]))
|
|
|
- if ver > (1, 31):
|
|
|
- raise RuntimeError(
|
|
|
- "Released SDK version with minimetrics support. Please delete "
|
|
|
- "this test and follow up instructions in "
|
|
|
- "https://github.com/getsentry/sentry/issues/56651"
|
|
|
- )
|
|
|
+@pytest.mark.parametrize(
|
|
|
+ "unit,default,expected_result",
|
|
|
+ [
|
|
|
+ (None, None, "none"),
|
|
|
+ (None, "my_default", "my_default"),
|
|
|
+ ("second", None, "second"),
|
|
|
+ ("second", "my_default", "second"),
|
|
|
+ ],
|
|
|
+)
|
|
|
+def test_to_minimetrics_unit(unit, default, expected_result):
|
|
|
+ result = MiniMetricsMetricsBackend._to_minimetrics_unit(unit, default)
|
|
|
+ assert result == expected_result
|