1313except ImportError :
1414 import mock # python < 3.3
1515
16+ try :
17+ import gevent
18+ except ImportError :
19+ gevent = None
20+
21+
22+ minimum_python_37_with_gevent = pytest .mark .skipif (
23+ gevent and sys .version_info < (3 , 7 ),
24+ reason = "Require Python 3.7 or higher with gevent" ,
25+ )
26+
1627
1728def parse_metrics (bytes ):
1829 rv = []
@@ -45,6 +56,7 @@ def parse_metrics(bytes):
4556 return rv
4657
4758
59+ @minimum_python_37_with_gevent
4860@pytest .mark .forked
4961def test_incr (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
5062 sentry_init (
@@ -97,6 +109,7 @@ def test_incr(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
97109 }
98110
99111
112+ @minimum_python_37_with_gevent
100113@pytest .mark .forked
101114def test_timing (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
102115 sentry_init (
@@ -157,6 +170,7 @@ def test_timing(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
157170 )
158171
159172
173+ @minimum_python_37_with_gevent
160174@pytest .mark .forked
161175def test_timing_decorator (
162176 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -252,6 +266,7 @@ def amazing_nano():
252266 assert line .strip () == "assert amazing() == 42"
253267
254268
269+ @minimum_python_37_with_gevent
255270@pytest .mark .forked
256271def test_timing_basic (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
257272 sentry_init (
@@ -306,6 +321,7 @@ def test_timing_basic(sentry_init, capture_envelopes, maybe_monkeypatched_thread
306321 }
307322
308323
324+ @minimum_python_37_with_gevent
309325@pytest .mark .forked
310326def test_distribution (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
311327 sentry_init (
@@ -368,6 +384,7 @@ def test_distribution(sentry_init, capture_envelopes, maybe_monkeypatched_thread
368384 )
369385
370386
387+ @minimum_python_37_with_gevent
371388@pytest .mark .forked
372389def test_set (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
373390 sentry_init (
@@ -421,6 +438,7 @@ def test_set(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
421438 }
422439
423440
441+ @minimum_python_37_with_gevent
424442@pytest .mark .forked
425443def test_gauge (sentry_init , capture_envelopes , maybe_monkeypatched_threading ):
426444 sentry_init (
@@ -454,6 +472,7 @@ def test_gauge(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
454472 }
455473
456474
475+ @minimum_python_37_with_gevent
457476@pytest .mark .forked
458477def test_multiple (sentry_init , capture_envelopes ):
459478 sentry_init (
@@ -508,6 +527,7 @@ def test_multiple(sentry_init, capture_envelopes):
508527 }
509528
510529
530+ @minimum_python_37_with_gevent
511531@pytest .mark .forked
512532def test_transaction_name (
513533 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -548,6 +568,7 @@ def test_transaction_name(
548568 }
549569
550570
571+ @minimum_python_37_with_gevent
551572@pytest .mark .forked
552573@pytest .mark .parametrize ("sample_rate" , [1.0 , None ])
553574def test_metric_summaries (
@@ -658,6 +679,7 @@ def test_metric_summaries(
658679 }
659680
660681
682+ @minimum_python_37_with_gevent
661683@pytest .mark .forked
662684def test_metrics_summary_disabled (
663685 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -702,6 +724,7 @@ def test_metrics_summary_disabled(
702724 assert "_metrics_summary" not in t ["spans" ][0 ]
703725
704726
727+ @minimum_python_37_with_gevent
705728@pytest .mark .forked
706729def test_metrics_summary_filtered (
707730 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -771,6 +794,7 @@ def should_summarize_metric(key, tags):
771794 } in t ["d:foo@second" ]
772795
773796
797+ @minimum_python_37_with_gevent
774798@pytest .mark .forked
775799def test_tag_normalization (
776800 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -818,6 +842,7 @@ def test_tag_normalization(
818842 # fmt: on
819843
820844
845+ @minimum_python_37_with_gevent
821846@pytest .mark .forked
822847def test_before_emit_metric (
823848 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -861,6 +886,7 @@ def before_emit(key, tags):
861886 }
862887
863888
889+ @minimum_python_37_with_gevent
864890@pytest .mark .forked
865891def test_aggregator_flush (
866892 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -881,6 +907,7 @@ def test_aggregator_flush(
881907 assert Hub .current .client .metrics_aggregator .buckets == {}
882908
883909
910+ @minimum_python_37_with_gevent
884911@pytest .mark .forked
885912def test_tag_serialization (
886913 sentry_init , capture_envelopes , maybe_monkeypatched_threading
@@ -921,6 +948,7 @@ def test_tag_serialization(
921948 }
922949
923950
951+ @minimum_python_37_with_gevent
924952@pytest .mark .forked
925953def test_flush_recursion_protection (
926954 sentry_init , capture_envelopes , monkeypatch , maybe_monkeypatched_threading
@@ -953,11 +981,12 @@ def bad_capture_envelope(*args, **kwargs):
953981 assert m [0 ][1 ] == "counter@none"
954982
955983
984+ @minimum_python_37_with_gevent
956985@pytest .mark .forked
957986def test_flush_recursion_protection_background_flush (
958987 sentry_init , capture_envelopes , monkeypatch , maybe_monkeypatched_threading
959988):
960- monkeypatch .setattr (metrics .MetricsAggregator , "FLUSHER_SLEEP_TIME" , 0.1 )
989+ monkeypatch .setattr (metrics .MetricsAggregator , "FLUSHER_SLEEP_TIME" , 0.01 )
961990 sentry_init (
962991 release = "fun-release" ,
963992 environment = "not-fun-env" ,
@@ -984,3 +1013,29 @@ def bad_capture_envelope(*args, **kwargs):
9841013 m = parse_metrics (envelope .items [0 ].payload .get_bytes ())
9851014 assert len (m ) == 1
9861015 assert m [0 ][1 ] == "counter@none"
1016+
1017+
1018+ @pytest .mark .skipif (
1019+ not gevent or sys .version_info >= (3 , 7 ),
1020+ reason = "Python 3.6 or lower and gevent required" ,
1021+ )
1022+ @pytest .mark .forked
1023+ def test_disable_metrics_for_old_python_with_gevent (
1024+ sentry_init , capture_envelopes , maybe_monkeypatched_threading
1025+ ):
1026+ if maybe_monkeypatched_threading != "greenlet" :
1027+ pytest .skip ("Test specifically for gevent/greenlet" )
1028+
1029+ sentry_init (
1030+ release = "fun-release" ,
1031+ environment = "not-fun-env" ,
1032+ _experiments = {"enable_metrics" : True },
1033+ )
1034+ envelopes = capture_envelopes ()
1035+
1036+ metrics .incr ("counter" )
1037+
1038+ Hub .current .flush ()
1039+
1040+ assert Hub .current .client .metrics_aggregator is None
1041+ assert not envelopes
0 commit comments