fix(PDO): strip libpq-style paired quotes from dbname DSN value#3885
Conversation
Laravel's Postgres connector wraps the dbname in single quotes when building the DSN (`dbname='milk'`). libpq strips those at connect time so the database name on the wire is `milk`, but the tracer's DSN regex captured the value verbatim and tagged `db.name='milk'`. The agent's tag-value sanitizer then rewrote the disallowed quote to `_`, emitting `peer.db.name=_milk` and splitting the inferred-entity peer.* tuple from other tracers that emit the unquoted name. Match libpq's behavior: peel paired wrapping single quotes from the captured dbname; leave unpaired quotes visible so real config typos still surface. Fixes APMS-19464.
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 272f0f0 | Docs | Datadog PR Page | Give us feedback! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 272f0f0737
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| // Match libpq: strip paired wrapping single quotes from dbname (APMS-19464). | ||
| if (strlen($db) >= 2 && $db[0] === "'" && substr($db, -1) === "'") { | ||
| $db = substr($db, 1, -1); |
There was a problem hiding this comment.
Unescape libpq-quoted dbnames before tagging
When a valid pgsql DSN uses libpq escaping inside the quoted dbname, this only removes the outer quotes and leaves escape characters in the tag. For example pgsql:dbname='customer\'s db' connects to database customer's db, but the span now emits db.name=customer\'s db, so peer-service/db-name identity is still split for quoted database names containing a quote or backslash. After stripping libpq-style quotes, the escaped \' and \\ sequences need to be decoded as libpq does.
Useful? React with 👍 / 👎.
Summary
Match libpq behavior in
PDOIntegration::parseDsnby stripping paired wrapping single quotes from the captureddbnamevalue. Without this, a Laravel-built DSN likepgsql:host=…;dbname='milk'produceddb.name='milk', which the agent's tag-value sanitizer rewrote as_milk— splitting the inferred-entitypeer.*tuple from other tracers emitting plainmilkand causing duplicate Service Page entries even after applying a Service Remapping rule.Context
Fixes APMS-19464. A Datadog inferred entity is keyed on the full
peer.*tag tuple, not the display name. Thepostgresqlvspostgrespeer.db.systemmismatch reported on the same ticket is tracked separately on the dd-trace-js side.