You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(mysqli,pdo): preserve binary SQL literals when sqlcommenter is installed
The mysqli and PDO query pre-hooks reassigned the local $query to
mb_convert_encoding($query, 'UTF-8') for the db.query.text span attribute.
When opentelemetry-sqlcommenter is also installed, that same (now
UTF-8-mangled) variable was injected and returned as the substituted
statement argument, so any non-UTF-8 byte in the executed SQL was replaced
with 0x3F ('?'). This silently corrupted BINARY/VARBINARY/BLOB writes that
embed raw bytes in a quoted literal (e.g. sha1() into a BINARY(20) column).
Convert to UTF-8 only for the span attribute (a separate $displayQuery),
and inject sqlcommenter into the raw $query so the wire statement keeps its
exact bytes. This mirrors the already-correct PDO::prepare hook. When the
sqlcommenter attribute is enabled, the attribute is set from a UTF-8-safe
copy of the injected query so span export stays valid.
Adds integration regression tests (real MySQL) proving a binary literal
round-trips unmodified through mysqli::query, PDO::exec and PDO::query with
sqlcommenter installed; both fail before this change and pass after.
Fixesopen-telemetry/opentelemetry-php#1960
- Rollback: revert commit; restores prior (corrupting) behavior.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Risk-Level: medium
AI-Agent: claude-opus-4-8
0 commit comments