← Back to Pull requests

fix(span-stats): only report hostname in client stats when DD_TRACE_REPORT_HOSTNAME is set #10972

Closed
unknown closed this pull request without merging on Oct 29, 2026 16:54 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 17:19 UTC
Author

What does this PR do?

With client-side stats enabled (DD_TRACE_STATS_COMPUTATION_ENABLED=true), the v0.6 stats payload now sets Hostname to os.hostname() only when DD_TRACE_REPORT_HOSTNAME (reportHostname) is enabled. Otherwise the field is an empty string, so the agent's own hostname is used.

Motivation

SpanStatsProcessor always set Hostname to os.hostname(). The agent passes the client Hostname through unchanged and adds its own AgentHostname beside it (client_stats_aggregator.go). A non-empty client hostname takes precedence for the resulting trace.* metrics.

In containerized environments such as Kubernetes, os.hostname() is the pod name. That host has no infrastructure tags, so host-level tags (for example kube_cluster_name) are missing from the service's trace metrics. The same service traced by a tracer that leaves Hostname empty resolves to the tagged node instead.

Every other place dd-trace-js reports a hostname is already gated on reportHostname:

  • span hostname (opentracing/tracer.js)

  • OTel host.name (opentelemetry/resource-attributes.js, opentelemetry/metrics/index.js)

  • the profiler (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_HOSTNAME unset (the default), stats payloads no longer include the process hostname. To keep the previous behavior, set DD_TRACE_REPORT_HOSTNAME=true (or reportHostname: true).

    Empty value: '' is the protobuf default for ClientStatsPayload.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 Hostname field):

    | 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, or WithHostname() (config.go), used in stats.go | Yes |
    | Python | set_hostname() only when DD_TRACE_REPORT_HOSTNAME is 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.x and v6.x have the same unconditional os.hostname() in span_stats.js, so this fix applies to both release lines.

    Tests:

  • The default-path tests now expect Hostname: ''.

  • Two new tests build the processor from the real config and assert on the payload passed to the exporter:

  • - default config (reportHostname is false) exports ''.
    - reportHostname: true exports os.hostname().
  • The disabled-path test fails without the fix.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: rochdev Review duration: 1414m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%