Skip to content

fix(PDO): strip libpq-style paired quotes from dbname DSN value#3885

Merged
Leiyks merged 3 commits into
masterfrom
leiyks/fix-apms-19464
May 18, 2026
Merged

fix(PDO): strip libpq-style paired quotes from dbname DSN value#3885
Leiyks merged 3 commits into
masterfrom
leiyks/fix-apms-19464

Conversation

@Leiyks
Copy link
Copy Markdown
Contributor

@Leiyks Leiyks commented May 18, 2026

Summary

Match libpq behavior in PDOIntegration::parseDsn by stripping paired wrapping single quotes from the captured dbname value. Without this, a Laravel-built DSN like pgsql:host=…;dbname='milk' produced db.name='milk', which the agent's tag-value sanitizer rewrote as _milk — splitting the inferred-entity peer.* tuple from other tracers emitting plain milk and 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. The postgresql vs postgres peer.db.system mismatch reported on the same ticket is tracked separately on the dd-trace-js side.

Leiyks added 3 commits May 18, 2026 16:36
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.
@datadog-prod-us1-4
Copy link
Copy Markdown

datadog-prod-us1-4 Bot commented May 18, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 60.70% (-0.05%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 272f0f0 | Docs | Datadog PR Page | Give us feedback!

@Leiyks Leiyks marked this pull request as ready for review May 18, 2026 15:09
@Leiyks Leiyks requested review from a team as code owners May 18, 2026 15:09
@Leiyks Leiyks requested review from LobeTia and removed request for a team May 18, 2026 15:09
@Leiyks Leiyks merged commit d8164b5 into master May 18, 2026
1846 of 1936 checks passed
@Leiyks Leiyks deleted the leiyks/fix-apms-19464 branch May 18, 2026 15:13
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@github-actions github-actions Bot added this to the 1.20.0 milestone May 18, 2026
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.

2 participants