feat(pdo): add DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED and DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED#3752
Conversation
…rted-configurations
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…EMENTS_ENABLED=false
…onfig call Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hey @jbdelhommeau, I think it's worth adding such a config given that it's been a repeated ask. However is the goal really fully eliminating all traces of queries being executed at all via prepared statement? (the tracer has facilities to extend the duration of already closed spans etc.) |
|
cc @bwoebi ! Like the dd-trace-go I backported this feature. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ENABLED=false Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ollBack spans
Add SpanAssertion::exists('PDO.beginTransaction') to the five failing tests
that call $pdo->beginTransaction() but had no corresponding span assertion
after DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED began tracing that method.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hey @jbdelhommeau, sorry for the delay, but I wasn't quite sure what to do with this: I propose:
The proper API for dropping spans like this is |
Summary
Two complementary PHP PDO configuration variables — a PHP port of the Go tracer's
WithIgnoreQueryTypes():DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED(boolean, defaulttrue) — suppressPDO.prepare+PDOStatement.executespansDD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED(boolean, defaulttrue) — suppress connection and transaction lifecycle spansCloses #3751
Rationale — Go tracer parité
In the Go tracer,
WithIgnoreQueryTypes(QueryType...)lets users opt out of specific operation types at code level. PHP exposes the same control as environment variables (no redeployment required):WithIgnoreQueryTypesequivalentDD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED=falseQueryTypePrepareDD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED=falseQueryTypeConnect + QueryTypeBegin + QueryTypeCommit + QueryTypeRollbackThis is also consistent with
DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLEDadded in PR #3757 for Redis/Predis.Behaviour
DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLEDtrue(default)falsePDO.preparePDOStatement.executePDO.exec/PDO.queryDD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLEDtrue(default)falsePDO.__constructPDO.connectPDO.beginTransactionPDO.commitPDO.rollBackPDO.exec/PDO.query/ prepared statementsChanges
ext/configuration.hCONFIG(BOOL, ...)declarationssrc/DDTrace/Integrations/PDO/PDOIntegration.phpinstall_hook;__construct+connectconverted fromtrace_method;beginTransactionandrollBackadded as new traced methodsmetadata/supported-configurations.jsontests/Integrations/PDO/PDOTest.phpbeginTransaction/rollBackspanstests/randomized/config/envs.phpImplementation notes
install_hookwith a per-calldd_trace_env_config()check — necessary because hooks are registered once atinit()time but config can change per-request (test isolation viaputEnvAndReloadConfig).PDO::__constructuses prehook+posthook pair: prehook creates the span (covers constructor duration), posthook storesObjectKVStoremetadata (requires constructor to have completed) and sets span attributes.PDOStatement::executeuses$hook->data = truesentinel to avoid a seconddd_trace_env_config()call in the posthook.Test plan
testPDOPreparedStatementsDisabled— no prepare/execute spans when flag=falsetestPDOPreparedStatementsDisabledDoesNotAffectExec— exec still tracedtestPDOLifecycleCommandsDisabled— no construct/commit spans; exec still tracedtestPDOLifecycleCommandsDisabledTransactions— no beginTransaction/commit/rollBack; exec still tracedtruepreserves existing behaviour)🤖 Generated with Claude Code