Skip to content

Commit 5758fd7

Browse files
committed
fix last test
1 parent e1cf67c commit 5758fd7

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def add_query_source(span):
216216
if not should_add_query_source:
217217
return
218218

219-
# We assume here that the span is just ending now. We can't use
220-
# the actual end timestamp of the span because the span can't be
221-
# finished in order to set any attributes on it.
219+
# We assume here that the query is just ending now. We can't use
220+
# the actual end timestamp of the span because in OTel the span
221+
# can't be finished in order to set any attributes on it.
222222
duration = datetime.now(tz=timezone.utc) - span.start_timestamp
223223
threshold = client.options.get("db_query_source_threshold_ms", 0)
224224
slow_query = duration / timedelta(milliseconds=1) > threshold

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -679,24 +679,21 @@ async def test_no_query_source_if_duration_too_short(sentry_init, capture_events
679679

680680
@contextmanager
681681
def fake_record_sql_queries(*args, **kwargs):
682-
with freeze_time(datetime.datetime(2024, 1, 1, microsecond=0)):
682+
with freeze_time(datetime.datetime(2024, 1, 1, microsecond=99999)):
683683
with record_sql_queries(*args, **kwargs) as span:
684-
freezer = freeze_time(
685-
datetime.datetime(2024, 1, 1, microsecond=99999)
686-
)
687-
freezer.start()
688-
689-
freezer.stop()
690-
691-
yield span
684+
yield span
692685

693686
with mock.patch(
694-
"sentry_sdk.integrations.asyncpg.record_sql_queries",
695-
fake_record_sql_queries,
687+
"sentry_sdk.tracing.POTelSpan.start_timestamp",
688+
datetime.datetime(2024, 1, 1, microsecond=0, tzinfo=datetime.timezone.utc),
696689
):
697-
await conn.execute(
698-
"INSERT INTO users(name, password, dob) VALUES ('Alice', 'secret', '1990-12-25')",
699-
)
690+
with mock.patch(
691+
"sentry_sdk.integrations.asyncpg.record_sql_queries",
692+
fake_record_sql_queries,
693+
):
694+
await conn.execute(
695+
"INSERT INTO users(name, password, dob) VALUES ('Alice', 'secret', '1990-12-25')",
696+
)
700697

701698
await conn.close()
702699

@@ -729,24 +726,21 @@ async def test_query_source_if_duration_over_threshold(sentry_init, capture_even
729726

730727
@contextmanager
731728
def fake_record_sql_queries(*args, **kwargs):
732-
with freeze_time(datetime.datetime(2024, 1, 1, microsecond=0)):
729+
with freeze_time(datetime.datetime(2024, 1, 1, microsecond=100001)):
733730
with record_sql_queries(*args, **kwargs) as span:
734-
freezer = freeze_time(
735-
datetime.datetime(2024, 1, 1, microsecond=100001)
736-
)
737-
freezer.start()
738-
739-
freezer.stop()
740-
741-
yield span
731+
yield span
742732

743733
with mock.patch(
744-
"sentry_sdk.integrations.asyncpg.record_sql_queries",
745-
fake_record_sql_queries,
734+
"sentry_sdk.tracing.POTelSpan.start_timestamp",
735+
datetime.datetime(2024, 1, 1, microsecond=0, tzinfo=datetime.timezone.utc),
746736
):
747-
await conn.execute(
748-
"INSERT INTO users(name, password, dob) VALUES ('Alice', 'secret', '1990-12-25')",
749-
)
737+
with mock.patch(
738+
"sentry_sdk.integrations.asyncpg.record_sql_queries",
739+
fake_record_sql_queries,
740+
):
741+
await conn.execute(
742+
"INSERT INTO users(name, password, dob) VALUES ('Alice', 'secret', '1990-12-25')",
743+
)
750744

751745
await conn.close()
752746

0 commit comments

Comments
 (0)