Skip to content

feat(pdo): add DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED and DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED #3751

@jbdelhommeau

Description

@jbdelhommeau

Summary

Add two complementary PHP PDO configuration variables that mirror the Go tracer's WithIgnoreQueryTypes() options:

  1. DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED — suppress PDO.prepare + PDOStatement.execute spans
  2. DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED — suppress connection and transaction lifecycle spans

Motivation

The Go tracer exposes fine-grained control over which DB operation types are traced via WithIgnoreQueryTypes(QueryType...). PHP had no equivalent. In high-throughput applications:

  • Prepared statement spans (PDO.prepare + execute) can generate noise when the query text is already visible on PDO.exec/PDO.query
  • Lifecycle spans (__construct, beginTransaction, commit, rollBack) have low diagnostic value in normal operation but contribute to trace volume

Both flags follow the same pattern already established for Redis (DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED).

Go tracer equivalence

PHP variable Go equivalent
DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED=false WithIgnoreQueryTypes(QueryTypePrepare)
DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED=false WithIgnoreQueryTypes(QueryTypeConnect, QueryTypeBegin, QueryTypeCommit, QueryTypeRollback)

Note: unlike Go (code-level option), PHP exposes these as environment variables — configurable without redeployment.

Behaviour

DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED

Span true (default) false
PDO.prepare
PDOStatement.execute
PDO.exec / PDO.query

DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED

Span true (default) false
PDO.__construct
PDO.connect
PDO.beginTransaction
PDO.commit
PDO.rollBack
PDO.exec / PDO.query / prepared statements

Note: connection metadata (out.host, db.system, etc.) is always preserved via ObjectKVStore so data command spans keep their tags regardless of the lifecycle flag.

Implementation scope

  • ext/configuration.h — two new CONFIG(BOOL, ...) declarations
  • src/DDTrace/Integrations/PDO/PDOIntegration.php — per-call flag checks via install_hook; beginTransaction and rollBack added as new traced methods
  • metadata/supported-configurations.json — document both variables
  • tests/Integrations/PDO/PDOTest.php — regression tests for both flags

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions