Skip to content

Commit aabbaef

Browse files
authored
Merge branch 'master' into ep/db-exploration-73s
2 parents 8714e09 + 047a516 commit aabbaef

11 files changed

Lines changed: 65 additions & 72 deletions

File tree

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/integrations/grpc/aio/server.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,32 @@ async def intercept_service(
4343
handler_factory = grpc.unary_unary_rpc_method_handler
4444

4545
async def wrapped(request: "Any", context: "ServicerContext") -> "Any":
46-
name = self._find_method_name(context)
47-
if not name:
48-
return await handler(request, context)
49-
50-
# What if the headers are empty?
51-
transaction = sentry_sdk.continue_trace(
52-
dict(context.invocation_metadata()),
53-
op=OP.GRPC_SERVER,
54-
name=name,
55-
source=TransactionSource.CUSTOM,
56-
origin=SPAN_ORIGIN,
57-
)
58-
59-
with sentry_sdk.start_transaction(transaction=transaction):
60-
try:
61-
return await handler.unary_unary(request, context)
62-
except AbortError:
63-
raise
64-
except Exception as exc:
65-
event, hint = event_from_exception(
66-
exc,
67-
mechanism={"type": "grpc", "handled": False},
68-
)
69-
sentry_sdk.capture_event(event, hint=hint)
70-
raise
46+
with sentry_sdk.isolation_scope():
47+
name = self._find_method_name(context)
48+
if not name:
49+
return await handler(request, context)
50+
51+
# What if the headers are empty?
52+
transaction = sentry_sdk.continue_trace(
53+
dict(context.invocation_metadata()),
54+
op=OP.GRPC_SERVER,
55+
name=name,
56+
source=TransactionSource.CUSTOM,
57+
origin=SPAN_ORIGIN,
58+
)
59+
60+
with sentry_sdk.start_transaction(transaction=transaction):
61+
try:
62+
return await handler.unary_unary(request, context)
63+
except AbortError:
64+
raise
65+
except Exception as exc:
66+
event, hint = event_from_exception(
67+
exc,
68+
mechanism={"type": "grpc", "handled": False},
69+
)
70+
sentry_sdk.capture_event(event, hint=hint)
71+
raise
7172

7273
elif not handler.request_streaming and handler.response_streaming:
7374
handler_factory = grpc.unary_stream_rpc_method_handler

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ async def test_connection_pool(sentry_init, capture_events) -> None:
486486
async def test_query_source_disabled(sentry_init, capture_events):
487487
sentry_options = {
488488
"integrations": [AsyncPGIntegration()],
489-
"enable_tracing": True,
489+
"traces_sample_rate": 1.0,
490490
"enable_db_query_source": False,
491491
"db_query_source_threshold_ms": 0,
492492
}
@@ -524,7 +524,7 @@ async def test_query_source_enabled(
524524
):
525525
sentry_options = {
526526
"integrations": [AsyncPGIntegration()],
527-
"enable_tracing": True,
527+
"traces_sample_rate": 1.0,
528528
"db_query_source_threshold_ms": 0,
529529
}
530530
if enable_db_query_source is not None:
@@ -560,7 +560,7 @@ async def test_query_source_enabled(
560560
async def test_query_source(sentry_init, capture_events):
561561
sentry_init(
562562
integrations=[AsyncPGIntegration()],
563-
enable_tracing=True,
563+
traces_sample_rate=1.0,
564564
enable_db_query_source=True,
565565
db_query_source_threshold_ms=0,
566566
)
@@ -610,7 +610,7 @@ async def test_query_source_with_module_in_search_path(sentry_init, capture_even
610610
"""
611611
sentry_init(
612612
integrations=[AsyncPGIntegration()],
613-
enable_tracing=True,
613+
traces_sample_rate=1.0,
614614
enable_db_query_source=True,
615615
db_query_source_threshold_ms=0,
616616
)
@@ -656,7 +656,7 @@ async def test_query_source_with_module_in_search_path(sentry_init, capture_even
656656
async def test_no_query_source_if_duration_too_short(sentry_init, capture_events):
657657
sentry_init(
658658
integrations=[AsyncPGIntegration()],
659-
enable_tracing=True,
659+
traces_sample_rate=1.0,
660660
enable_db_query_source=True,
661661
db_query_source_threshold_ms=100,
662662
)
@@ -701,7 +701,7 @@ def fake_record_sql_queries(*args, **kwargs):
701701
async def test_query_source_if_duration_over_threshold(sentry_init, capture_events):
702702
sentry_init(
703703
integrations=[AsyncPGIntegration()],
704-
enable_tracing=True,
704+
traces_sample_rate=1.0,
705705
enable_db_query_source=True,
706706
db_query_source_threshold_ms=100,
707707
)

tests/integrations/celery/test_celery.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def example_task():
606606
def test_messaging_destination_name_default_exchange(
607607
mock_request, routing_key, init_celery, capture_events
608608
):
609-
celery_app = init_celery(enable_tracing=True)
609+
celery_app = init_celery(traces_sample_rate=1.0)
610610
events = capture_events()
611611
mock_request.delivery_info = {"routing_key": routing_key, "exchange": ""}
612612

@@ -630,7 +630,7 @@ def test_messaging_destination_name_nondefault_exchange(
630630
that the routing key is the queue name. Other exchanges may not guarantee this
631631
behavior.
632632
"""
633-
celery_app = init_celery(enable_tracing=True)
633+
celery_app = init_celery(traces_sample_rate=1.0)
634634
events = capture_events()
635635
mock_request.delivery_info = {"routing_key": "celery", "exchange": "custom"}
636636

@@ -645,7 +645,7 @@ def task(): ...
645645

646646

647647
def test_messaging_id(init_celery, capture_events):
648-
celery = init_celery(enable_tracing=True)
648+
celery = init_celery(traces_sample_rate=1.0)
649649
events = capture_events()
650650

651651
@celery.task
@@ -659,7 +659,7 @@ def example_task(): ...
659659

660660

661661
def test_retry_count_zero(init_celery, capture_events):
662-
celery = init_celery(enable_tracing=True)
662+
celery = init_celery(traces_sample_rate=1.0)
663663
events = capture_events()
664664

665665
@celery.task()
@@ -676,7 +676,7 @@ def task(): ...
676676
def test_retry_count_nonzero(mock_request, init_celery, capture_events):
677677
mock_request.retries = 3
678678

679-
celery = init_celery(enable_tracing=True)
679+
celery = init_celery(traces_sample_rate=1.0)
680680
events = capture_events()
681681

682682
@celery.task()
@@ -691,7 +691,7 @@ def task(): ...
691691

692692
@pytest.mark.parametrize("system", ("redis", "amqp"))
693693
def test_messaging_system(system, init_celery, capture_events):
694-
celery = init_celery(enable_tracing=True)
694+
celery = init_celery(traces_sample_rate=1.0)
695695
events = capture_events()
696696

697697
# Does not need to be a real URL, since we use always eager
@@ -716,7 +716,7 @@ def publish(*args, **kwargs):
716716

717717
monkeypatch.setattr(kombu.messaging.Producer, "_publish", publish)
718718

719-
sentry_init(integrations=[CeleryIntegration()], enable_tracing=True)
719+
sentry_init(integrations=[CeleryIntegration()], traces_sample_rate=1.0)
720720
celery = Celery(__name__, broker=f"{system}://example.com") # noqa: E231
721721
events = capture_events()
722722

@@ -754,7 +754,7 @@ def task(): ...
754754

755755

756756
def tests_span_origin_consumer(init_celery, capture_events):
757-
celery = init_celery(enable_tracing=True)
757+
celery = init_celery(traces_sample_rate=1.0)
758758
celery.conf.broker_url = "redis://example.com" # noqa: E231
759759

760760
events = capture_events()
@@ -778,7 +778,7 @@ def publish(*args, **kwargs):
778778

779779
monkeypatch.setattr(kombu.messaging.Producer, "_publish", publish)
780780

781-
sentry_init(integrations=[CeleryIntegration()], enable_tracing=True)
781+
sentry_init(integrations=[CeleryIntegration()], traces_sample_rate=1.0)
782782
celery = Celery(__name__, broker="redis://example.com") # noqa: E231
783783

784784
events = capture_events()
@@ -807,7 +807,7 @@ def test_send_task_wrapped(
807807
capture_events,
808808
reset_integrations,
809809
):
810-
sentry_init(integrations=[CeleryIntegration()], enable_tracing=True)
810+
sentry_init(integrations=[CeleryIntegration()], traces_sample_rate=1.0)
811811
celery = Celery(__name__, broker="redis://example.com") # noqa: E231
812812

813813
events = capture_events()

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
@@ -303,7 +303,7 @@ def test_engine_name_not_string(sentry_init):
303303
def test_query_source_disabled(sentry_init, capture_events):
304304
sentry_options = {
305305
"integrations": [SqlalchemyIntegration()],
306-
"enable_tracing": True,
306+
"traces_sample_rate": 1.0,
307307
"enable_db_query_source": False,
308308
"db_query_source_threshold_ms": 0,
309309
}
@@ -354,7 +354,7 @@ class Person(Base):
354354
def test_query_source_enabled(sentry_init, capture_events, enable_db_query_source):
355355
sentry_options = {
356356
"integrations": [SqlalchemyIntegration()],
357-
"enable_tracing": True,
357+
"traces_sample_rate": 1.0,
358358
"db_query_source_threshold_ms": 0,
359359
}
360360
if enable_db_query_source is not None:
@@ -405,7 +405,7 @@ class Person(Base):
405405
def test_query_source(sentry_init, capture_events):
406406
sentry_init(
407407
integrations=[SqlalchemyIntegration()],
408-
enable_tracing=True,
408+
traces_sample_rate=1.0,
409409
enable_db_query_source=True,
410410
db_query_source_threshold_ms=0,
411411
)
@@ -470,7 +470,7 @@ def test_query_source_with_module_in_search_path(sentry_init, capture_events):
470470
"""
471471
sentry_init(
472472
integrations=[SqlalchemyIntegration()],
473-
enable_tracing=True,
473+
traces_sample_rate=1.0,
474474
enable_db_query_source=True,
475475
db_query_source_threshold_ms=0,
476476
)
@@ -533,7 +533,7 @@ class Person(Base):
533533
def test_no_query_source_if_duration_too_short(sentry_init, capture_events):
534534
sentry_init(
535535
integrations=[SqlalchemyIntegration()],
536-
enable_tracing=True,
536+
traces_sample_rate=1.0,
537537
enable_db_query_source=True,
538538
db_query_source_threshold_ms=100,
539539
)
@@ -599,7 +599,7 @@ def __exit__(self, type, value, traceback):
599599
def test_query_source_if_duration_over_threshold(sentry_init, capture_events):
600600
sentry_init(
601601
integrations=[SqlalchemyIntegration()],
602-
enable_tracing=True,
602+
traces_sample_rate=1.0,
603603
enable_db_query_source=True,
604604
db_query_source_threshold_ms=100,
605605
)

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"))

tests/tracing/test_misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def test_start_transaction_updates_scope_name_source(sentry_init):
478478

479479
@pytest.mark.parametrize("sampled", (True, None))
480480
def test_transaction_dropped_debug_not_started(sentry_init, sampled):
481-
sentry_init(enable_tracing=True)
481+
sentry_init(traces_sample_rate=1.0)
482482

483483
tx = Transaction(sampled=sampled)
484484

@@ -498,7 +498,7 @@ def test_transaction_dropped_debug_not_started(sentry_init, sampled):
498498

499499

500500
def test_transaction_dropeed_sampled_false(sentry_init):
501-
sentry_init(enable_tracing=True)
501+
sentry_init(traces_sample_rate=1.0)
502502

503503
tx = Transaction(sampled=False)
504504

@@ -516,7 +516,7 @@ def test_transaction_dropeed_sampled_false(sentry_init):
516516

517517

518518
def test_transaction_not_started_warning(sentry_init):
519-
sentry_init(enable_tracing=True)
519+
sentry_init(traces_sample_rate=1.0)
520520

521521
tx = Transaction()
522522

0 commit comments

Comments
 (0)