Skip to content

feat(integrations): Add integration for aiomysql#4703

Open
tonal wants to merge 36 commits into
getsentry:masterfrom
tonal:patch-2
Open

feat(integrations): Add integration for aiomysql#4703
tonal wants to merge 36 commits into
getsentry:masterfrom
tonal:patch-2

Conversation

@tonal
Copy link
Copy Markdown

@tonal tonal commented Aug 14, 2025

Add support for aiomysql to the SDK.

@tonal tonal requested a review from a team as a code owner August 14, 2025 09:43
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@antonpirker antonpirker added the New Integration Integrating with a new framework or library label Sep 11, 2025
@antonpirker antonpirker changed the title integration for aiomysql Feat(integrations): Add integration for aiomysql Sep 11, 2025
@antonpirker
Copy link
Copy Markdown
Contributor

Hey @tonal thanks for the PR, great work! Could you address the cursor comments above?

@antonpirker antonpirker changed the title Feat(integrations): Add integration for aiomysql feat(integrations): Add integration for aiomysql Sep 11, 2025
cursor[bot]

This comment was marked as outdated.

Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment on lines +2 to +4
"""
Adapted from module sentry_sdk.integrations.asyncpg
"""
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.

Hi @tonal ,

Thanks for the contribution, much appreciated!

Can you add unit tests for the integration as well? You can probably adapt them from the asyncpg tests.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 12, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Integrations

  • Add integration for aiomysql by tonal in #4703
  • Instrument pyreqwest tracing by servusdei2018 in #5682

Other

  • (ai) Redact base64 data URLs in image_url content blocks by ericapisani in #5953
  • (ci) Cancel in-progress PR workflows on new commit push by joshuarli in #5994
  • (litellm) Add async callbacks by alexander-alderman-webb in #5969

Bug Fixes 🐛

Anthropic

  • Capture exceptions for stream() calls by alexander-alderman-webb in #5950
  • Stop setting transaction status when child span fails by alexander-alderman-webb in #5717
  • Only finish relevant spans in .create() patches by alexander-alderman-webb in #5716

Pydantic Ai

  • Adapt import for new library versions by alexander-alderman-webb in #5984
  • Use first-class hooks when available by alexander-alderman-webb in #5947

Other

  • (huggingface_hub) Stop setting transaction status when a child span fails by Zenithatic in #5952
  • (litellm) Avoid double span exits when streaming by alexander-alderman-webb in #5933
  • (wsgi) Respect HTTP_X_FORWARDED_PROTO in request.url construction by sl0thentr0py in #5963

Internal Changes 🔧

Litellm

  • Replace mocks with httpx types in rate-limit test by alexander-alderman-webb in #5975
  • Replace mocks with httpx types in embedding tests by alexander-alderman-webb in #5970
  • Replace mocks with httpx types in nonstreaming completion() tests by alexander-alderman-webb in #5937
  • Remove dead attributes by alexander-alderman-webb in #5985

Other

  • (ai) Remove gen_ai.tool.type span attribute by ericapisani in #5964
  • (anthropic) Separate sync and async .create() patches by alexander-alderman-webb in #5715
  • (openai) Split token counting by API for easier deprecation by ericapisani in #5930
  • (openai-agents) Remove error attributes by alexander-alderman-webb in #5986
  • (opentelemetry) Ignore mypy error by alexander-alderman-webb in #5927
  • 🤖 Update test matrix with new releases (04/13) by github-actions in #5983
  • Fix license metadata in setup.py by sl0thentr0py in #5934
  • Update validate-pr workflow by stephanie-anderson in #5931

Other

  • release: 2.58.0 by ericapisani in ce445d96
  • Handle None span context in the span processor and pin tokenizers version for anthropic tests on Python 3.8 by alexander-alderman-webb in #5967

🤖 This preview updates automatically when you update the PR.

Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Rewrite the aiomysql integration to fix issues raised in PR getsentry#4703:

- Patch Cursor.execute and Cursor.executemany instead of Connection.query
- Make _wrap_connect async (await inside span context)
- Handle bytes/bytearray queries from executemany's internal batching
- Normalize query text using " ".join(query.split()) for performance
- Protect _sentry_skip_next_execute flag with try/finally to prevent leakage
- Remove dead _wrap_cursor and unused _record context manager

Add 17 end-to-end tests covering connect, execute, executemany, record_params,
cursor iteration, connection pools, query source, span origin, and normalization.

Update CI configuration: tox.ini envlist, GitHub Actions workflow with MySQL
service container, and test suite config.

Co-Authored-By: Qwen Code <noreply@anthropic.com>

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Comment thread sentry_sdk/integrations/aiomysql.py
Comment thread scripts/split_tox_gh_actions/templates/test_group.jinja Outdated
Comment thread sentry_sdk/integrations/aiomysql.py
Resolve merge conflicts in auto-generated files (tox.ini,
package_dependencies.jsonl, releases.jsonl, CI workflows) by
taking upstream versions and regenerating with aiomysql config.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread sentry_sdk/integrations/aiomysql.py
tonal and others added 2 commits May 12, 2026 15:52
Include fix for compromised transitive dependency (getsentry#6257).
Regenerate tox.ini and CI workflows with aiomysql config.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace record_sql_queries with record_sql_queries_supporting_streaming
to support span streaming (addresses sentry bot review comment).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
- Use set_attribute for StreamedSpan, set_data for regular Span
- Branch _wrap_connect: traces.start_span with attributes when streaming,
  start_span with set_data otherwise (following asyncpg pattern)
- Import StreamedSpan and has_span_streaming_enabled

Addresses sentry bot and cursor bot review comments (HIGH severity).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Comment thread tests/integrations/aiomysql/test_aiomysql.py
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
…mocks

- Call add_query_source inside context for StreamedSpan, outside for
  regular Span (following asyncpg pattern)
- Fix tests to mock record_sql_queries_supporting_streaming instead of
  record_sql_queries

Addresses cursor bot review comments.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tonal
Copy link
Copy Markdown
Author

tonal commented May 12, 2026

@alexander-alderman-webb Hi! I've resolved all the bot review comments (span streaming support, StreamedSpan compatibility, test mocks) and merged the latest master. The PR is ready for review when you have a chance. Thanks!

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Looks good me! Please resolve the conflicts in tox.ini as well and then I'd approve and merge

Comment thread .github/workflows/test-integrations-web-1.yml
Comment thread sentry_sdk/integrations/__init__.py Outdated
@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

alexander-alderman-webb commented May 15, 2026

I also just ran our checks and the lint and the new tests are failing. These block merging the PR.

You can run the linter locally using the following command:

ruff format --check tests sentry_sdk

tonal and others added 3 commits May 21, 2026 15:18
MySQL 8.0 uses caching_sha2_password which requires the cryptography
package. Add it to tox config deps and regenerate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Wait until the integration is tested over a few versions before
auto-enabling. Also add cryptography dep for MySQL 8.0 auth.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Resolve conflicts in auto-generated files, add cryptography dep,
remove from auto-enabling list, fix lint.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread sentry_sdk/integrations/aiomysql.py
Comment thread requirements-dev.in Outdated
tonal and others added 4 commits May 21, 2026 15:35
Upstream renamed record_sql_queries_supporting_streaming back to
record_sql_queries since it now natively supports streaming.
Update imports and mock targets accordingly.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add import-not-found to type: ignore comments for aiomysql imports
- Explicitly type span_attributes as dict[str, Any] for mypy
- Remove accidentally committed requirements-dev.in/.txt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
import-untyped is redundant when import-not-found covers the case.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

Looks like you pulled in an incompatibility between Pydantic AI and our instrumentation by updating the test matrix.
We'll fix and reach out to you again here!

Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit db77a50. Configure here.

Comment thread scripts/populate_tox/config.py Outdated
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread sentry_sdk/integrations/aiomysql.py Outdated
Create _get_connect_data() to build breadcrumb dict directly from
connection, instead of relying on span._data which is empty for NoOpSpan.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Integration Integrating with a new framework or library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants