Skip to content

test(aiomysql): Add span streaming variants to aiomysql tests#6601

Merged
ericapisani merged 1 commit into
masterfrom
py-2523-add-span-streaming-tests-to-aiomysql
Jun 18, 2026
Merged

test(aiomysql): Add span streaming variants to aiomysql tests#6601
ericapisani merged 1 commit into
masterfrom
py-2523-add-span-streaming-tests-to-aiomysql

Conversation

@ericapisani

Copy link
Copy Markdown
Member

Parametrize existing aiomysql tests with span_streaming to cover both
static and stream trace lifecycle modes.

Fixes PY-2523
Fixes #6539

Parametrize existing aiomysql tests with span_streaming to cover both
static and stream trace lifecycle modes.

Fixes PY-2523
Fixes #6539
@linear-code

linear-code Bot commented Jun 17, 2026

Copy link
Copy Markdown

PY-2523

@ericapisani ericapisani marked this pull request as ready for review June 17, 2026 19:12
@ericapisani ericapisani requested a review from a team as a code owner June 17, 2026 19:12
Comment on lines 800 to +806
@contextmanager
def fake_record_sql_queries(*args, **kwargs):
def fake_record_sql_queries_streaming(*args, **kwargs):
with record_sql_queries(*args, **kwargs) as span:
pass
span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0)
span.timestamp = datetime.datetime(2024, 1, 1, microsecond=100001)
yield span

async with conn.cursor() as cur:
with mock.patch(
"sentry_sdk.integrations.aiomysql.record_sql_queries",
fake_record_sql_queries,
):
await cur.execute(
"INSERT INTO users(name, password, dob) VALUES ('Alice', 'secret', '1990-12-25')",
span._start_timestamp = datetime.datetime(
2024, 1, 1, microsecond=0, tzinfo=datetime.timezone.utc
)
yield span

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The mock in test_query_source_if_duration_over_threshold for streaming spans fails to simulate a long duration, preventing correct validation of the slow query source annotation feature.
Severity: LOW

Suggested Fix

Update the mock in the streaming test case to correctly simulate a slow query. After yield span, set span._end_timestamp to a value that ensures the duration span._end_timestamp - span._start_timestamp is greater than the 100ms threshold, similar to how the non-streaming version of the test is implemented. This will ensure the test accurately validates the intended behavior.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: tests/integrations/aiomysql/test_aiomysql.py#L800-L806

Potential issue: In the streaming version of the test
`test_query_source_if_duration_over_threshold`, the mock setup for the span only sets
`_start_timestamp`. When the span's context manager exits, `_end_timestamp` is
calculated based on the elapsed monotonic time, which is near-zero within the test's
execution. This results in a span duration that is too short to pass the `slow_query`
check in the `add_query_source` function. Consequently, the test fails to properly
simulate a slow query, meaning it cannot validate that source code information is
correctly added for slow streaming database queries as intended.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

90810 passed | ⏭️ 6129 skipped | Total: 96939 | Pass Rate: 93.68% | Execution Time: 320m 11s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -174
Passed Tests 📉 -182
Failed Tests
Skipped Tests 📈 +8

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2411 uncovered lines.
✅ Project coverage is 89.84%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.60%    89.84%    +0.24%
==========================================
  Files          192       192         —
  Lines        23732     23732         —
  Branches      8194      8194         —
==========================================
+ Hits         21265     21321       +56
- Misses        2467      2411       -56
- Partials      1357      1343       -14

Generated by Codecov Action

@alexander-alderman-webb alexander-alderman-webb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look too in-depth since it's test code

@ericapisani ericapisani merged commit 62a913b into master Jun 18, 2026
267 of 272 checks passed
@ericapisani ericapisani deleted the py-2523-add-span-streaming-tests-to-aiomysql branch June 18, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate aiomysql to span first

2 participants