feat(pdo): add DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED and DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED#3752
Open
jbdelhommeau wants to merge 11 commits intoDataDog:masterfrom
Open
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>
Collaborator
|
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.) |
Author
|
cc @bwoebi ! Like the dd-trace-go I backported this feature. |
6 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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