Skip to content

Commit e0564ca

Browse files
committed
Merge branch 'master' into ivana/migrate-celery-to-span-first
2 parents c2d1ced + 5d26c2f commit e0564ca

12 files changed

Lines changed: 48 additions & 52 deletions

File tree

sentry_sdk/integrations/celery/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
_patch_redbeat_apply_async,
1313
_setup_celery_beat_signals,
1414
)
15-
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch, NoOpMgr
15+
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
1616
from sentry_sdk.integrations.logging import ignore_logger
1717
from sentry_sdk.traces import StreamedSpan
1818
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource
@@ -244,6 +244,14 @@ def _update_celery_task_headers(
244244
return updated_headers
245245

246246

247+
class NoOpMgr:
248+
def __enter__(self) -> None:
249+
return None
250+
251+
def __exit__(self, exc_type: "Any", exc_value: "Any", traceback: "Any") -> None:
252+
return None
253+
254+
247255
def _wrap_task_run(f: "F") -> "F":
248256
@wraps(f)
249257
def apply_async(*args: "Any", **kwargs: "Any") -> "Any":

sentry_sdk/integrations/celery/utils.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import TYPE_CHECKING, cast
33

44
if TYPE_CHECKING:
5-
from typing import Any, Tuple
5+
from typing import Tuple
66
from sentry_sdk._types import MonitorConfigScheduleUnit
77

88

@@ -29,11 +29,3 @@ def _get_humanized_interval(seconds: float) -> "Tuple[int, MonitorConfigSchedule
2929
return (interval, cast("MonitorConfigScheduleUnit", unit))
3030

3131
return (int(seconds), "second")
32-
33-
34-
class NoOpMgr:
35-
def __enter__(self) -> None:
36-
return None
37-
38-
def __exit__(self, exc_type: "Any", exc_value: "Any", traceback: "Any") -> None:
39-
return None

sentry_sdk/profiler/continuous_profiler.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,6 @@ def teardown(self) -> None:
506506
self.thread.join()
507507
self.thread = None
508508

509-
self.buffer = None
510-
511509

512510
class GeventContinuousScheduler(ContinuousScheduler):
513511
"""
@@ -580,8 +578,6 @@ def teardown(self) -> None:
580578
self.thread.join()
581579
self.thread = None
582580

583-
self.buffer = None
584-
585581

586582
PROFILE_BUFFER_SECONDS = 60
587583

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ async def test_connection_pool(sentry_init, capture_events) -> None:
485485
async def test_query_source_disabled(sentry_init, capture_events):
486486
sentry_options = {
487487
"integrations": [AsyncPGIntegration()],
488-
"enable_tracing": True,
488+
"traces_sample_rate": 1.0,
489489
"enable_db_query_source": False,
490490
"db_query_source_threshold_ms": 0,
491491
}
@@ -523,7 +523,7 @@ async def test_query_source_enabled(
523523
):
524524
sentry_options = {
525525
"integrations": [AsyncPGIntegration()],
526-
"enable_tracing": True,
526+
"traces_sample_rate": 1.0,
527527
"db_query_source_threshold_ms": 0,
528528
}
529529
if enable_db_query_source is not None:
@@ -559,7 +559,7 @@ async def test_query_source_enabled(
559559
async def test_query_source(sentry_init, capture_events):
560560
sentry_init(
561561
integrations=[AsyncPGIntegration()],
562-
enable_tracing=True,
562+
traces_sample_rate=1.0,
563563
enable_db_query_source=True,
564564
db_query_source_threshold_ms=0,
565565
)
@@ -609,7 +609,7 @@ async def test_query_source_with_module_in_search_path(sentry_init, capture_even
609609
"""
610610
sentry_init(
611611
integrations=[AsyncPGIntegration()],
612-
enable_tracing=True,
612+
traces_sample_rate=1.0,
613613
enable_db_query_source=True,
614614
db_query_source_threshold_ms=0,
615615
)
@@ -655,7 +655,7 @@ async def test_query_source_with_module_in_search_path(sentry_init, capture_even
655655
async def test_no_query_source_if_duration_too_short(sentry_init, capture_events):
656656
sentry_init(
657657
integrations=[AsyncPGIntegration()],
658-
enable_tracing=True,
658+
traces_sample_rate=1.0,
659659
enable_db_query_source=True,
660660
db_query_source_threshold_ms=100,
661661
)
@@ -700,7 +700,7 @@ def fake_record_sql_queries(*args, **kwargs):
700700
async def test_query_source_if_duration_over_threshold(sentry_init, capture_events):
701701
sentry_init(
702702
integrations=[AsyncPGIntegration()],
703-
enable_tracing=True,
703+
traces_sample_rate=1.0,
704704
enable_db_query_source=True,
705705
db_query_source_threshold_ms=100,
706706
)

tests/integrations/celery/test_celery.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def test_messaging_destination_name_default_exchange(
682682
capture_items,
683683
):
684684
celery_app = init_celery(
685-
enable_tracing=True,
685+
traces_sample_rate=1.0,
686686
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
687687
)
688688
mock_request.delivery_info = {"routing_key": routing_key, "exchange": ""}
@@ -719,7 +719,7 @@ def test_messaging_destination_name_nondefault_exchange(
719719
behavior.
720720
"""
721721
celery_app = init_celery(
722-
enable_tracing=True,
722+
traces_sample_rate=1.0,
723723
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
724724
)
725725
mock_request.delivery_info = {"routing_key": "celery", "exchange": "custom"}
@@ -744,7 +744,7 @@ def task(): ...
744744
@pytest.mark.parametrize("span_streaming", [True, False])
745745
def test_messaging_id(span_streaming, init_celery, capture_events, capture_items):
746746
celery = init_celery(
747-
enable_tracing=True,
747+
traces_sample_rate=1.0,
748748
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
749749
)
750750

@@ -768,7 +768,7 @@ def example_task(): ...
768768
@pytest.mark.parametrize("span_streaming", [True, False])
769769
def test_retry_count_zero(span_streaming, init_celery, capture_events, capture_items):
770770
celery = init_celery(
771-
enable_tracing=True,
771+
traces_sample_rate=1.0,
772772
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
773773
)
774774

@@ -797,7 +797,7 @@ def test_retry_count_nonzero(
797797
mock_request.retries = 3
798798

799799
celery = init_celery(
800-
enable_tracing=True,
800+
traces_sample_rate=1.0,
801801
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
802802
)
803803

@@ -824,7 +824,7 @@ def test_messaging_system(
824824
system, span_streaming, init_celery, capture_events, capture_items
825825
):
826826
celery = init_celery(
827-
enable_tracing=True,
827+
traces_sample_rate=1.0,
828828
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
829829
)
830830

@@ -862,7 +862,7 @@ def publish(*args, **kwargs):
862862

863863
sentry_init(
864864
integrations=[CeleryIntegration()],
865-
enable_tracing=True,
865+
traces_sample_rate=1.0,
866866
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
867867
)
868868
celery = Celery(__name__, broker=f"{system}://example.com") # noqa: E231
@@ -937,7 +937,7 @@ def tests_span_origin_consumer(
937937
span_streaming, init_celery, capture_events, capture_items
938938
):
939939
celery = init_celery(
940-
enable_tracing=True,
940+
traces_sample_rate=1.0,
941941
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
942942
)
943943
celery.conf.broker_url = "redis://example.com" # noqa: E231
@@ -977,7 +977,7 @@ def publish(*args, **kwargs):
977977

978978
sentry_init(
979979
integrations=[CeleryIntegration()],
980-
enable_tracing=True,
980+
traces_sample_rate=1.0,
981981
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
982982
)
983983
celery = Celery(__name__, broker="redis://example.com") # noqa: E231
@@ -1027,7 +1027,7 @@ def test_send_task_wrapped(
10271027
):
10281028
sentry_init(
10291029
integrations=[CeleryIntegration()],
1030-
enable_tracing=True,
1030+
traces_sample_rate=1.0,
10311031
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
10321032
)
10331033
celery = Celery(__name__, broker="redis://example.com") # noqa: E231

tests/integrations/celery/test_update_celery_task_headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_monitor_beat_tasks_with_headers(monitor_beat_tasks):
7171

7272

7373
def test_span_with_transaction(sentry_init):
74-
sentry_init(enable_tracing=True)
74+
sentry_init(traces_sample_rate=1.0)
7575
headers = {}
7676
monitor_beat_tasks = False
7777

@@ -91,7 +91,7 @@ def test_span_with_transaction(sentry_init):
9191

9292

9393
def test_span_with_transaction_custom_headers(sentry_init):
94-
sentry_init(enable_tracing=True)
94+
sentry_init(traces_sample_rate=1.0)
9595
headers = {
9696
"baggage": BAGGAGE_VALUE,
9797
"sentry-trace": SENTRY_TRACE_VALUE,

tests/integrations/graphene/test_graphene.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def graphql_server_sync():
207207
def test_graphql_span_holds_query_information(sentry_init, capture_events):
208208
sentry_init(
209209
integrations=[GrapheneIntegration(), FlaskIntegration()],
210-
enable_tracing=True,
210+
traces_sample_rate=1.0,
211211
default_integrations=False,
212212
)
213213
events = capture_events()

tests/integrations/sqlalchemy/test_sqlalchemy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def test_engine_name_not_string(sentry_init):
301301
def test_query_source_disabled(sentry_init, capture_events):
302302
sentry_options = {
303303
"integrations": [SqlalchemyIntegration()],
304-
"enable_tracing": True,
304+
"traces_sample_rate": 1.0,
305305
"enable_db_query_source": False,
306306
"db_query_source_threshold_ms": 0,
307307
}
@@ -352,7 +352,7 @@ class Person(Base):
352352
def test_query_source_enabled(sentry_init, capture_events, enable_db_query_source):
353353
sentry_options = {
354354
"integrations": [SqlalchemyIntegration()],
355-
"enable_tracing": True,
355+
"traces_sample_rate": 1.0,
356356
"db_query_source_threshold_ms": 0,
357357
}
358358
if enable_db_query_source is not None:
@@ -403,7 +403,7 @@ class Person(Base):
403403
def test_query_source(sentry_init, capture_events):
404404
sentry_init(
405405
integrations=[SqlalchemyIntegration()],
406-
enable_tracing=True,
406+
traces_sample_rate=1.0,
407407
enable_db_query_source=True,
408408
db_query_source_threshold_ms=0,
409409
)
@@ -468,7 +468,7 @@ def test_query_source_with_module_in_search_path(sentry_init, capture_events):
468468
"""
469469
sentry_init(
470470
integrations=[SqlalchemyIntegration()],
471-
enable_tracing=True,
471+
traces_sample_rate=1.0,
472472
enable_db_query_source=True,
473473
db_query_source_threshold_ms=0,
474474
)
@@ -531,7 +531,7 @@ class Person(Base):
531531
def test_no_query_source_if_duration_too_short(sentry_init, capture_events):
532532
sentry_init(
533533
integrations=[SqlalchemyIntegration()],
534-
enable_tracing=True,
534+
traces_sample_rate=1.0,
535535
enable_db_query_source=True,
536536
db_query_source_threshold_ms=100,
537537
)
@@ -597,7 +597,7 @@ def __exit__(self, type, value, traceback):
597597
def test_query_source_if_duration_over_threshold(sentry_init, capture_events):
598598
sentry_init(
599599
integrations=[SqlalchemyIntegration()],
600-
enable_tracing=True,
600+
traces_sample_rate=1.0,
601601
enable_db_query_source=True,
602602
db_query_source_threshold_ms=100,
603603
)

tests/test_basics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ def test_classmethod_instance_tracing(sentry_init, capture_events):
10921092

10931093

10941094
def test_last_event_id(sentry_init):
1095-
sentry_init(enable_tracing=True)
1095+
sentry_init(traces_sample_rate=1.0)
10961096

10971097
assert last_event_id() is None
10981098

@@ -1102,7 +1102,7 @@ def test_last_event_id(sentry_init):
11021102

11031103

11041104
def test_last_event_id_transaction(sentry_init):
1105-
sentry_init(enable_tracing=True)
1105+
sentry_init(traces_sample_rate=1.0)
11061106

11071107
assert last_event_id() is None
11081108

@@ -1113,7 +1113,7 @@ def test_last_event_id_transaction(sentry_init):
11131113

11141114

11151115
def test_last_event_id_scope(sentry_init):
1116-
sentry_init(enable_tracing=True)
1116+
sentry_init(traces_sample_rate=1.0)
11171117

11181118
# Should not crash
11191119
with isolation_scope() as scope:

tests/test_scope.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ def test_set_tags():
876876

877877

878878
def test_last_event_id(sentry_init):
879-
sentry_init(enable_tracing=True)
879+
sentry_init(traces_sample_rate=1.0)
880880

881881
assert Scope.last_event_id() is None
882882

@@ -886,7 +886,7 @@ def test_last_event_id(sentry_init):
886886

887887

888888
def test_last_event_id_transaction(sentry_init):
889-
sentry_init(enable_tracing=True)
889+
sentry_init(traces_sample_rate=1.0)
890890

891891
assert Scope.last_event_id() is None
892892

@@ -897,7 +897,7 @@ def test_last_event_id_transaction(sentry_init):
897897

898898

899899
def test_last_event_id_cleared(sentry_init):
900-
sentry_init(enable_tracing=True)
900+
sentry_init(traces_sample_rate=1.0)
901901

902902
# Make sure last_event_id is set
903903
sentry_sdk.capture_exception(Exception("test"))

0 commit comments

Comments
 (0)