feat(redis): add DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED to suppress lifecycle spans#3757
Open
jbdelhommeau wants to merge 9 commits intoDataDog:masterfrom
Open
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ANDS_ENABLED=false
…NDS_ENABLED=false
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>
5 tasks
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
Adds
DD_TRACE_REDIS_LIFECYCLE_COMMANDS_ENABLED(boolean, defaulttrue) 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 introducedDD_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: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.__constructmulti/exec,rawCommand,eval/evalSha/script, geo, streamsClient.__construct,Client.connect,Pipeline.executePipelineexecuteCommand,executeRawConnection metadata is preserved: even when lifecycle spans are suppressed,
ObjectKVStorestill stores host/port metadata from connection hooks so that data command spans continue to haveout.hosttags.Implementation notes
\DDTrace\install_hook()instead of\DDTrace\trace_method(), with per-calldd_trace_env_config()checks. This is necessary because hooks are registered atinit()time but the config can change per-request (important for test isolation withputEnvAndReloadConfig).RedisCluster::__constructmetadata storage extracted intostoreClusterMeta()static helper to avoid duplication between the span-creating and metadata-only paths.Client::__constructuses a prehook+posthook pair: prehook creates the span (so it covers constructor execution time), posthook stores metadata and sets span attributes.Prior art
WithIgnoreQueryTypes(QueryTypeConnect, ...)—contrib/database/sql/option.goDD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED— PR feat(pdo): add DD_TRACE_PDO_PREPARED_STATEMENTS_ENABLED and DD_TRACE_PDO_LIFECYCLE_COMMANDS_ENABLED #3752Test plan
testLifecycleCommandsDisabledPhpRedis— verifies no connect/close spans when flag=false, only data commandstestLifecycleCommandsDisabledPreservesHostMetadata— verifiesout.hosttag still present on data command spanstestLifecycleCommandsDisabledPredis— same for PredistestLifecycleCommandsDisabledPreservesHostMetadataPredis— same for Predis🤖 Generated with Claude Code