Skip to content

feat(otel): support DD_HOSTNAME as host.name OTel resource attribute#5705

Merged
mabdinur merged 11 commits into
masterfrom
munir/otel-dd-hostname
May 12, 2026
Merged

feat(otel): support DD_HOSTNAME as host.name OTel resource attribute#5705
mabdinur merged 11 commits into
masterfrom
munir/otel-dd-hostname

Conversation

@mabdinur
Copy link
Copy Markdown
Contributor

@mabdinur mabdinur commented May 7, 2026

What does this PR do?

Adds a top-level hostname configuration option backed by the DD_HOSTNAME environment variable. When DD_TRACE_REPORT_HOSTNAME is enabled:

  • DD_HOSTNAME is used as the host.name OpenTelemetry resource attribute (OTel metrics and logs), falling back to Socket.hostname if unset.
  • DD_HOSTNAME is used as the trace-level hostname tag, matching the behavior of other Datadog SDKs.

Motivation:

The DD_HOSTNAME env var is supported by other Datadog SDKs (Python, Java, etc.) and allows overriding the host name reported by the process. This brings Ruby parity and allows the Test_FR07_Host_Name::test_hostname_from_dd_hostname parametric test to pass.

Alignment with dd-trace-py:

Reviewed the dd-trace-py implementation. Python uses a single get_hostname() helper that returns DD_HOSTNAME if set, else falls back to socket.gethostname(). This value is applied to:

  • Traces: set on each span when report_hostname is true (_trace/tracer.py:564)
  • OTel metrics resource: host.name attribute when report_hostname is true
  • OTel logs resource: host.name attribute when report_hostname is true

This PR aligns Ruby with that pattern:

  • Datadog.configuration.hostname (reads DD_HOSTNAME) takes precedence over the system hostname in traces and OTel resource attributes
  • Missing RBS type declarations added: ENV_HOSTNAME constant and hostname method on Settings

Precedence (OTel resource host.name):

  1. DD_HOSTNAME (explicit override)
  2. host.name from DD_TAGS / c.tags
  3. Socket.hostname (system fallback)

Change log entry

Yes. Added DD_HOSTNAME environment variable support. When DD_TRACE_REPORT_HOSTNAME is enabled, the value of DD_HOSTNAME is used as the trace hostname and host.name OpenTelemetry resource attribute.

Additional Notes:

  • The same @settings.hostname fallback is applied in both the metrics (metrics.rb) and logs (lib/datadog/opentelemetry/logs.rb, in the companion PR feat(otel): add otel logs support #5446) resource builders.
  • RBS types updated: ENV_HOSTNAME: String in sig/datadog/core/environment/ext.rbs and def hostname: -> String? in sig/datadog/core/configuration/settings.rbs.

Add a top-level `hostname` option backed by the `DD_HOSTNAME` env var.
When `DD_TRACE_REPORT_HOSTNAME` is enabled, prefer the configured hostname
over Socket.hostname for the `host.name` OTel resource attribute.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mabdinur mabdinur added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label May 7, 2026
@mabdinur mabdinur requested review from a team as code owners May 7, 2026 21:37
@mabdinur mabdinur added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label May 7, 2026
@mabdinur mabdinur requested a review from vpellan May 7, 2026 21:37
@dd-octo-sts dd-octo-sts Bot added core Involves Datadog core libraries otel OpenTelemetry-related changes labels May 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e099643c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/datadog/opentelemetry/metrics.rb Outdated
@mabdinur mabdinur marked this pull request as draft May 7, 2026 21:44
mabdinur and others added 2 commits May 7, 2026 17:45
Move the host.name assignment to after the tag loop so DD_HOSTNAME
overrides any host.name set via DD_TAGS/OTEL_RESOURCE_ATTRIBUTES,
consistent with how service/env/version first-class settings take
precedence over their tag equivalents.

When DD_HOSTNAME is not set, Socket.hostname is used only as a fallback
when no host.name tag is present, preserving the existing tag behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…is enabled

Aligned with dd-trace-py: DD_HOSTNAME now takes precedence over the
system hostname for the trace-level hostname tag. Also adds missing
RBS type declarations for the hostname setting and ENV_HOSTNAME constant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dd-octo-sts dd-octo-sts Bot added the tracing label May 7, 2026
StandardRB requires parentheses around complex ternary conditions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented May 7, 2026

Tests

Fix all issues with BitsAI or with Cursor

⚠️ Warnings

❄️ 2 New flaky tests detected

Datadog::Core::Environment::Socket::resolved_hostname when DD_HOSTNAME is empty falls back to the system hostname from rspec   View in Datadog   (Fix with Cursor)
expected: ""
     got: nil

(compared using ==)

Failure/Error: expect(resolved).to eq(described_class.hostname)

  expected: ""
       got: nil

...
Datadog::Core::Environment::Socket::resolved_hostname when DD_HOSTNAME is not set returns the system hostname from rspec   View in Datadog   (Fix with Cursor)
expected: ""
     got: nil

(compared using ==)

Failure/Error: expect(resolved).to eq(described_class.hostname)

  expected: ""
       got: nil

...

ℹ️ Info

No other issues found (see more)

🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 97.14% (-0.00%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 99d570a | Docs | Datadog PR Page | Give us feedback!

Comment thread supported-configurations.json Outdated
Co-authored-by: Munir Abdinur <munir.abdinur@datadoghq.com>
Comment thread lib/datadog/tracing/tracer.rb Outdated
@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented May 10, 2026

Benchmarks

Benchmark execution time: 2026-05-11 15:38:55

Comparing candidate commit e8507ba in PR branch munir/otel-dd-hostname with baseline commit cbb6899 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 46 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@mabdinur mabdinur force-pushed the munir/otel-dd-hostname branch from 8b34fa6 to cd4c511 Compare May 11, 2026 03:53
@mabdinur mabdinur marked this pull request as ready for review May 11, 2026 03:54
@mabdinur mabdinur requested a review from a team as a code owner May 11, 2026 03:54
Comment thread lib/datadog/tracing/tracer.rb Outdated
@mabdinur mabdinur force-pushed the munir/otel-dd-hostname branch from cd4c511 to 8003c01 Compare May 11, 2026 14:24
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 11, 2026

Typing analysis

This PR does not change typing compared to the base branch.

@mabdinur mabdinur force-pushed the munir/otel-dd-hostname branch 4 times, most recently from 2b581cc to 142bb71 Compare May 11, 2026 15:00
@mabdinur mabdinur force-pushed the munir/otel-dd-hostname branch 2 times, most recently from 8e42dd3 to 8c3ee01 Compare May 11, 2026 15:07
…STNAME resolution

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mabdinur mabdinur force-pushed the munir/otel-dd-hostname branch from 8c3ee01 to c6deba3 Compare May 11, 2026 15:11
@mabdinur mabdinur enabled auto-merge May 11, 2026 17:53
@mabdinur
Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 Bot commented May 11, 2026

View all feedbacks in Devflow UI.

2026-05-11 17:54:08 UTC ℹ️ Start processing command /merge


2026-05-11 17:54:21 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-05-11 21:58:16 UTC ⚠️ MergeQueue: This merge request was unqueued

devflow unqueued this merge request: It did not become mergeable within the expected time

Comment thread lib/datadog/core/environment/socket.rb Outdated
Comment thread spec/datadog/core/environment/socket_spec.rb Outdated
Comment thread spec/datadog/core/environment/socket_spec.rb Outdated
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
Comment thread spec/datadog/core/environment/socket_spec.rb Outdated
Co-authored-by: Munir Abdinur <munir.abdinur@datadoghq.com>
@mabdinur mabdinur merged commit 4c7ff4f into master May 12, 2026
579 of 581 checks passed
@mabdinur mabdinur deleted the munir/otel-dd-hostname branch May 12, 2026 14:45
@dd-octo-sts dd-octo-sts Bot added this to the 2.33.0 milestone May 12, 2026
@Strech Strech mentioned this pull request May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos core Involves Datadog core libraries mergequeue-status: removed otel OpenTelemetry-related changes tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants