← Back to Pull requests

refactor(contrib): migrate database integrations to events API #21859

Closed
unknown closed this pull request without merging on Dec 01, 2026 16:23 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 19:34 UTC
Author

Description

Migrate shared sync/async DB-API wrappers, asyncpg connection/query instrumentation, and aiomysql queries to typed database events and the shared tracing lifecycle.

  • DatabaseOperationEvent extends TracingEvent; DatabaseTracingSubscriber extends TracingSubscriber.

  • Carry connection tags as a dictionary and apply collected result metadata when the operation ends.

  • Keep query preparation separate: DBM owns propagation policy and argument rewriting.

  • Move Snowflake query IDs into the result-metadata hook and remove the old private span-taking hook and compatibility bridge.

  • Collect cursor metadata on a best-effort basis, preserving driver return values, original errors, and cancellation.
  • 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

  • 349 tests passed across sync/async DB-API, SQLite, DBM policy, asyncpg, aiomysql, and Snowflake; 12 Snowflake skips. Python 3.9 and 3.12 were exercised.

  • Regression coverage includes metadata collection after success, driver errors and cancellation; result tags; transactions; context isolation; and patch/unpatch behavior.

  • A real SQLite trace capture verified original SQL resources and errors, parent restoration, expected span count, and a DBM traceparent matching the actual query span.

  • Formatting, typing, 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_src service-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).

    Diff: 274 lines (+205 / -69) across 3 files Reviewer: dubloom Review duration: 19968m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.68) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.68 · 274 lines diff across 3 files
    0.68
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.336
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.068
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #21859"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 67.7% (HIGH) · Higher = larger blast radius
    67.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.7% · Safe to merge
    26.7%