diff --git a/pkg/trace/api/info.go b/pkg/trace/api/info.go index 4ea4a5e5bb5093..79d1d55d7d5eea 100644 --- a/pkg/trace/api/info.go +++ b/pkg/trace/api/info.go @@ -10,8 +10,10 @@ import ( "encoding/json" "fmt" "net/http" + "slices" "github.com/DataDog/datadog-agent/pkg/obfuscate" + "github.com/DataDog/datadog-agent/pkg/trace/stats" ) // makeInfoHandler returns a new handler for handling the discovery endpoint. @@ -61,6 +63,17 @@ func (r *HTTPReceiver) makeInfoHandler() (hash string, handler http.HandlerFunc) oconf.Redis = o.Redis oconf.Memcached = o.Memcached } + + // We check that endpoints contains stats, even though we know this version of the + // agent supports it. It's conceivable that the stats endpoint could be disabled at some point + // so this is defensive against that case. + canDropP0 := !r.conf.ProbabilisticSamplerEnabled && slices.Contains(all, "/v0.6/stats") + + var spanKindsStatsComputed []string + if r.conf.ComputeStatsBySpanKind { + spanKindsStatsComputed = stats.KindsComputed + } + txt, err := json.MarshalIndent(struct { Version string `json:"version"` GitCommit string `json:"git_commit"` @@ -72,15 +85,17 @@ func (r *HTTPReceiver) makeInfoHandler() (hash string, handler http.HandlerFunc) EvpProxyAllowedHeaders []string `json:"evp_proxy_allowed_headers"` Config reducedConfig `json:"config"` PeerTags []string `json:"peer_tags"` + SpanKindsStatsComputed []string `json:"span_kinds_stats_computed"` }{ Version: r.conf.AgentVersion, GitCommit: r.conf.GitCommit, Endpoints: all, FeatureFlags: r.conf.AllFeatures(), - ClientDropP0s: true, + ClientDropP0s: canDropP0, SpanMetaStructs: true, LongRunningSpans: true, EvpProxyAllowedHeaders: EvpProxyAllowedHeaders, + SpanKindsStatsComputed: spanKindsStatsComputed, Config: reducedConfig{ DefaultEnv: r.conf.DefaultEnv, TargetTPS: r.conf.TargetTPS, diff --git a/pkg/trace/api/info_test.go b/pkg/trace/api/info_test.go index 0d82e3fd41b2c2..d8fc856b6a6bed 100644 --- a/pkg/trace/api/info_test.go +++ b/pkg/trace/api/info_test.go @@ -302,6 +302,7 @@ func TestInfoHandler(t *testing.T) { "long_running_spans": nil, "evp_proxy_allowed_headers": nil, "peer_tags": nil, + "span_kinds_stats_computed": nil, "config": map[string]interface{}{ "default_env": nil, "target_tps": nil, diff --git a/pkg/trace/stats/span_concentrator.go b/pkg/trace/stats/span_concentrator.go index d886b9e7495f7c..e48f937f267a5a 100644 --- a/pkg/trace/stats/span_concentrator.go +++ b/pkg/trace/stats/span_concentrator.go @@ -6,6 +6,7 @@ package stats import ( + "slices" "strings" "sync" "time" @@ -159,12 +160,16 @@ func (sc *SpanConcentrator) NewStatSpan( // computeStatsForSpanKind returns true if the span.kind value makes the span eligible for stats computation. func computeStatsForSpanKind(kind string) bool { k := strings.ToLower(kind) - switch k { - case "server", "consumer", "client", "producer": - return true - default: - return false - } + return slices.Contains(KindsComputed, k) +} + +// KindsComputed is the list of span kinds that will have stats computed on them +// when computeStatsByKind is enabled in the concentrator. +var KindsComputed = []string{ + "server", + "consumer", + "client", + "producer", } func (sc *SpanConcentrator) addSpan(s *StatSpan, aggKey PayloadAggregationKey, containerID string, containerTags []string, origin string, weight float64) {