From e0d6678183e7748600c0fd3c829675f00f03e9e3 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 22 Jul 2024 13:42:32 +0200 Subject: [PATCH] Make Django db spans have origin auto.db.django (#3319) --- sentry_sdk/integrations/django/__init__.py | 7 ++++--- tests/integrations/django/test_db_query_data.py | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index 4f18d93a8a..253fce1745 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -116,6 +116,7 @@ class DjangoIntegration(Integration): identifier = "django" origin = f"auto.http.{identifier}" + origin_db = f"auto.db.{identifier}" transaction_style = "" middleware_spans = None @@ -630,7 +631,7 @@ def execute(self, sql, params=None): params_list=params, paramstyle="format", executemany=False, - span_origin=DjangoIntegration.origin, + span_origin=DjangoIntegration.origin_db, ) as span: _set_db_data(span, self) options = ( @@ -663,7 +664,7 @@ def executemany(self, sql, param_list): params_list=param_list, paramstyle="format", executemany=True, - span_origin=DjangoIntegration.origin, + span_origin=DjangoIntegration.origin_db, ) as span: _set_db_data(span, self) @@ -683,7 +684,7 @@ def connect(self): with sentry_sdk.start_span( op=OP.DB, description="connect", - origin=DjangoIntegration.origin, + origin=DjangoIntegration.origin_db, ) as span: _set_db_data(span, self) return real_connect(self) diff --git a/tests/integrations/django/test_db_query_data.py b/tests/integrations/django/test_db_query_data.py index 087fc5ad49..41ad9d5e1c 100644 --- a/tests/integrations/django/test_db_query_data.py +++ b/tests/integrations/django/test_db_query_data.py @@ -481,7 +481,10 @@ def test_db_span_origin_execute(sentry_init, client, capture_events): assert event["contexts"]["trace"]["origin"] == "auto.http.django" for span in event["spans"]: - assert span["origin"] == "auto.http.django" + if span["op"] == "db": + assert span["origin"] == "auto.db.django" + else: + assert span["origin"] == "auto.http.django" @pytest.mark.forked @@ -520,4 +523,4 @@ def test_db_span_origin_executemany(sentry_init, client, capture_events): (event,) = events assert event["contexts"]["trace"]["origin"] == "manual" - assert event["spans"][0]["origin"] == "auto.http.django" + assert event["spans"][0]["origin"] == "auto.db.django"