Repository navigation
refactor(contrib): migrate database integrations to events API - #21859
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
BenchmarksBenchmark execution time: 2026-11-25 20:04:53 Comparing candidate commit f7fdaf4 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 600 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
🎉 All green!🧪 All tests passed 🔗 Commit SHA: f7fdaf4 | Docs | View more details | Give us feedback! |
Publish optional query preparation and context-associated result metadata events. Keep propagation policy in its listener and preserve legacy cursor hooks through the tracing subscriber.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
More details
Runtime validation covered the shared synchronous and asynchronous DB-API wrappers; database-backed driver behavior was assessed statically only.
🤖 Bits Code Review · Commit f5b74c4
zacharycmontoya
left a comment
There was a problem hiding this comment.
From the SDK capabilities side, LGTM
Restore legacy propagator arguments and compose metadata hooks with existing span hooks. Preserve driver exceptions and cancellation when result collection fails.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52de33a813
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
The PR moves database tracing to typed events and includes cursor compatibility and driver-error preservation fixes. One architectural concern remains: the new tracing subscriber imports contrib despite LA-1; the supplied range received static review only.
🤖 Bits Code Review · Commit 52de33a
dubloom
left a comment
There was a problem hiding this comment.
Additional comments from Claude
There was a problem hiding this comment.
Legacy cursor hooks can apply chained service mappings twice, assigning database spans to the wrong service even when the hook leaves the service unchanged.
🤖 Bits Code Review · Commit 603bc79
There was a problem hiding this comment.
More details
The PR centralizes DB-API, asyncpg, and aiomysql tracing and DBM preparation through typed database events. Removing the legacy hook bridge fixes the earlier double service-mapping defect; metadata failures now preserve driver outcomes, and no review findings remain open.
🤖 Bits Code Review · Commit 4125af8
e4e011c
into
main
## Description Follow-up to #21859. Database events carried two tag dicts, `connection_tags` and `tags`, and the database subscriber re-applied both in `on_started` and again in `on_ended`. Every DB-API query wrote its connection tags two times and its per-call tags three times. This change folds them into the single `tags` field that `TracingEvent` already applies when the span starts: - **dbapi / aiomysql**: pass the connection's tag dict directly, or `{**db_tags, **extra_tags}` when the call has extra tags, which still take precedence. - **asyncpg connect**: host, port, user and database are only known after connecting, so they are published through `DatabaseResultEvent.tags`, which `on_ended` already applies. - **Subscriber**: `on_started` is removed; `on_ended` only applies the result. - **`DatabaseOperationEvent`**: drops its redeclarations of `component`, `integration_config`, `resource` and `span_type` in favour of the `TracingEvent` fields, and sets `span_type = SpanTypes.SQL` on the class. `operation_name` stays redeclared because `TracingEvent` declares it with `init=False`. - **Port type**: `Span.set_tag` converts `network.destination.port` to `int`, but the shared lifecycle writes tags with `_set_attribute`. `_normalize_db_tags` converts the port once when the tags are captured, so the port keeps its current type. ## Customer impact DB-API `*.connection.commit` and `*.connection.rollback` spans now have span type `sql` instead of none, consistent with query spans and with dd-trace-go. Tags are unchanged. ## Testing - Updated the dbapi and dbapi_async unit tests and the mariadb and snowflake commit/rollback snapshots for the `sql` span type. - Relying on CI for the dbapi, sqlite3, asyncpg, aiomysql, pymysql, mysqlclient, psycopg and mariadb suites. ## Risks - Commit and rollback spans changing type could affect span-type-based queries. - Connection tags now skip `Span.set_tag`'s special-key handling. Only the port conversion applied to them, and it is kept by `_normalize_db_tags`. ## Additional Notes Benchmark not run yet; the change removes per-query tag writes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: louis.tricot <louis.tricot@datadoghq.com>
Description
Migrate shared sync/async DB-API wrappers, asyncpg connection/query instrumentation, and aiomysql queries to typed database events and the shared tracing lifecycle.
DatabaseOperationEventextendsTracingEvent;DatabaseTracingSubscriberextendsTracingSubscriber.Original query resources, parent relationships, measured flags, security checks, and DBM exclusions for fetches, stored procedures, and prepared statements are preserved.
Customer impact
This updates an unreleased internal refactor. Supported driver operations retain their behavior; span metadata adopts the shared tracing conventions described below.
Testing
scripts/lint checks, and dependency/import-cycle comparisons passed.Risks
A cursor metadata failure can omit row counts or query IDs. It does not change the driver's query result or replace its exception.
Additional Notes
The shared lifecycle adds standard
_dd.svc_srcservice-source attribution and uses the shared component/span-kind tagging order instead of per-driver event flags. The asyncpg snapshots reflect the intended attribution change.The internal
_set_post_execute_tags(span)hook is removed. Result metadata uses_get_post_execute_result(context).