Skip to content

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

Open
jbdelhommeau wants to merge 10 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 10 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 10 commits April 16, 2026 16:13
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>
@bwoebi bwoebi force-pushed the feat/3753-redis-lifecycle-commands-enabled branch from 6855610 to 1c7c52e Compare April 16, 2026 14:18
@datadog-prod-us1-6
Copy link
Copy Markdown

datadog-prod-us1-6 bot commented Apr 16, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Other Violations

🧪 24 Tests failed

testHashFunctions with data set #13 from tests/Integrations/PHPRedis/V3.DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest.DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest::testHashFunctions   View in Datadog   (Fix with Cursor)
DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest::testHashFunctions with data set #13 ('hScan', array('h1', null), array('v1', 'v2', '3'), array('v1', 'v2', '3'), 'hScan h1 0')
RedisCluster.hScan: Expected tag format for 'redis.raw_command' does not match actual value
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-hScan h1 0
+hScan h1 null

Received Spans graph:
...
testMethodsSpansOnly with data set #7 from tests/Integrations/PHPRedis/V3.DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest.DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest::testMethodsSpansOnly   View in Datadog   (Fix with Cursor)
DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest::testMethodsSpansOnly with data set #7 ('scan', array(null, 'CONNECTION_1'), '0 CONNECTION_1_AS_ARG')
RedisCluster.scan: Expected tag format for 'redis.raw_command' does not match actual value
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-scan 0 127.0.0.1 7001
+scan null 127.0.0.1 7001

Received Spans graph:
...
testSetFunctions with data set #14 from tests/Integrations/PHPRedis/V3.DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest.DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest::testSetFunctions   View in Datadog   (Fix with Cursor)
DDTrace\Tests\Integrations\PHPRedis\V3\PHPRedisClusterTest::testSetFunctions with data set #14 ('sScan', array('s1{hash}', null), 'ARRAY_COUNT_3', array(3, 3), 'sScan s1{hash} 0')
RedisCluster.sScan: Expected tag format for 'redis.raw_command' does not match actual value
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-sScan s1{hash} 0
+sScan s1{hash} null

Received Spans graph:
...
View all

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 60.65% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1c7c52e | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

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

2 participants