Skip to content

feat(redis): add DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED to suppress lifecycle spans#3757

Open
jbdelhommeau wants to merge 9 commits intoDataDog:masterfrom
jbdelhommeau:feat/3753-redis-lifecycle-commands-enabled
Open

feat(redis): add DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED to suppress lifecycle spans#3757
jbdelhommeau wants to merge 9 commits intoDataDog:masterfrom
jbdelhommeau:feat/3753-redis-lifecycle-commands-enabled

Conversation

@jbdelhommeau
Copy link
Copy Markdown

Summary

Adds DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED (boolean, default true) to suppress "noise" spans from Redis lifecycle operations, keeping only the valuable data command spans.

This is a PHP backport of a pattern already established in dd-trace-go via WithIgnoreQueryTypes(QueryTypeConnect, ...), and follows the same approach as PHP PR #3752 which introduced DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED.

Closes #3753

Motivation

In high-throughput applications, lifecycle operations (connect, close, auth, ping, introspection) generate spans with little diagnostic value while consuming quota. This flag lets users opt out of those spans without losing visibility into actual Redis data operations.

What changes

When DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED=false:

Integration Suppressed Always kept
PHPRedis connect, pconnect, open, popen, close, auth, select, ping, echo, bgRewriteAOF, bgSave, flushAll, flushDb, save, restore, swapdb, getLastError, clearLastError, _serialize, _unserialize, isConnected, getHost, getPort, getDbNum, getTimeout, getReadTimeout, RedisCluster.__construct All data commands (GET, SET, HGET, ZADD…), multi/exec, rawCommand, eval/evalSha/script, geo, streams
Predis Client.__construct, Client.connect, Pipeline.executePipeline executeCommand, executeRaw

Connection metadata is preserved: even when lifecycle spans are suppressed, ObjectKVStore still stores host/port metadata from connection hooks so that data command spans continue to have out.host tags.

Implementation notes

  • Hooks for lifecycle methods use \DDTrace\install_hook() instead of \DDTrace\trace_method(), with per-call dd_trace_env_config() checks. This is necessary because hooks are registered at init() time but the config can change per-request (important for test isolation with putEnvAndReloadConfig).
  • PHPRedis RedisCluster::__construct metadata storage extracted into storeClusterMeta() static helper to avoid duplication between the span-creating and metadata-only paths.
  • Predis Client::__construct uses a prehook+posthook pair: prehook creates the span (so it covers constructor execution time), posthook stores metadata and sets span attributes.

Prior art

Test plan

  • testLifecycleCommandsDisabledPhpRedis — verifies no connect/close spans when flag=false, only data commands
  • testLifecycleCommandsDisabledPreservesHostMetadata — verifies out.host tag still present on data command spans
  • testLifecycleCommandsDisabledPredis — same for Predis
  • testLifecycleCommandsDisabledPreservesHostMetadataPredis — same for Predis
  • All 372 existing PHPRedis V5 tests pass
  • All 28 existing Predis latest tests pass

🤖 Generated with Claude Code

jbdelhommeau and others added 9 commits March 30, 2026 16:09
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace init-time $lifecycleEnabled check with per-call dd_trace_env_config()
inside install_hook callbacks so putEnvAndReloadConfig() in tests takes effect.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

feat(redis): add DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED to disable lifecycle spans

1 participant