fix(span-stats): only report hostname in client stats when DD_TRACE_REPORT_HOSTNAME is set #10972
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10972"
general
weight: 0.35
rochdev
What does this PR do?
With client-side stats enabled (
DD_TRACE_STATS_COMPUTATION_ENABLED=true), the v0.6 stats payload now setsHostnametoos.hostname()only whenDD_TRACE_REPORT_HOSTNAME(reportHostname) is enabled. Otherwise the field is an empty string, so the agent's own hostname is used.Motivation
SpanStatsProcessoralways setHostnametoos.hostname(). The agent passes the clientHostnamethrough unchanged and adds its ownAgentHostnamebeside it (client_stats_aggregator.go). A non-empty client hostname takes precedence for the resultingtrace.*metrics.In containerized environments such as Kubernetes,
os.hostname()is the pod name. That host has no infrastructure tags, so host-level tags (for examplekube_cluster_name) are missing from the service's trace metrics. The same service traced by a tracer that leavesHostnameempty resolves to the tagged node instead.Every other place dd-trace-js reports a hostname is already gated on
reportHostname:opentracing/tracer.js)host.name(opentelemetry/resource-attributes.js,opentelemetry/metrics/index.js)profiling/config.js,profiling/exporters/event_serializer.js)Client stats were the exception.
Tracked in APMS-20685.
Additional Notes
Behavior change: with
DD_TRACE_REPORT_HOSTNAMEunset (the default), stats payloads no longer include the process hostname. To keep the previous behavior, setDD_TRACE_REPORT_HOSTNAME=true(orreportHostname: true).Empty value:
''is the protobuf default forClientStatsPayload.hostname, and it is what Java sends when hostname reporting is off. The msgpack encoder already defaults the field to''.Cross-tracer comparison (client stats
Hostnamefield):| Tracer | Value sent | Gated on report-hostname? |
|---|---|---|
| Java |
reportHostName ? getHostName() : ""(Config.java), used by ClientStatsAggregator.java and written by SerializingMetricWriter.java | Yes || Go | hostname set only with
DD_TRACE_REPORT_HOSTNAME,DD_TRACE_SOURCE_HOSTNAME, orWithHostname()(config.go), used in stats.go | Yes || Python |
set_hostname()only whenDD_TRACE_REPORT_HOSTNAMEis enabled (writer.py) | Yes || libdatadog trace exporter | empty unless the caller sets it (builder.rs, stats_exporter.rs) | Up to the caller |
| .NET | machine name (StatsAggregator.cs, HostMetadata.cs) | No |
| PHP (sidecar) |
DD_HOSTNAME(sidecar.c), falling back to the machine hostname (connection_session.rs) | No || Ruby (native transport) |
Socket.hostname(native.rb) | No || Node.js before this PR |
os.hostname()| No || Node.js with this PR |
reportHostname ? os.hostname() : ''| Yes |Backport:
v5.xandv6.xhave the same unconditionalos.hostname()inspan_stats.js, so this fix applies to both release lines.Tests:
Hostname: ''.- default config (
reportHostnameisfalse) exports''.-
reportHostname: trueexportsos.hostname().🤖 Generated with Claude Code