Skip to content

Make Django db spans have origin auto.db.django #3319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions tests/integrations/django/test_db_query_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Loading