Skip to content

otel: add host.name resource attribute to logs/traces via gethostname#12352

Merged
mcgrew-oai merged 9 commits intomainfrom
mcgrew/otel-host-name
Feb 25, 2026
Merged

otel: add host.name resource attribute to logs/traces via gethostname#12352
mcgrew-oai merged 9 commits intomainfrom
mcgrew/otel-host-name

Conversation

@mcgrew-oai
Copy link
Contributor

PR Summary

This PR adds the OpenTelemetry host.name resource attribute to Codex OTEL exports so every OTEL log (and trace, via the shared resource) carries the machine hostname.

What changed

  • Added host.name to the shared OTEL Resource in /Users/michael.mcgrew/code/codex/codex-rs/otel/src/otel_provider.rs
    • This applies to both:
      • OTEL logs (SdkLoggerProvider)
      • OTEL traces (SdkTracerProvider)
  • Hostname is now resolved via gethostname::gethostname() (best-effort)
    • Value is trimmed
    • Empty values are omitted (non-fatal)
  • Added focused unit tests for:
    • including host.name when present
    • omitting host.name when missing/empty

Why

  • host.name is host/process metadata and belongs on the OTEL resource, not per-event attributes.
  • Attaching it in the shared resource is the smallest change that guarantees coverage across all exported OTEL logs/traces.

Scope / Non-goals

  • No public API changes
  • No changes to metrics behavior (this PR only updates log/trace resource metadata)

Dependency updates

  • Added gethostname as a workspace dependency and codex-otel dependency
  • Cargo.lock updated accordingly
  • MODULE.bazel.lock unchanged after refresh/check

Validation

  • just fmt
  • cargo test -p codex-otel
  • just bazel-lock-update
  • just bazel-lock-check

otel: add host.name resource attribute to logs/traces via gethostname
@mcgrew-oai mcgrew-oai added the oai PRs contributed by OpenAI employees label Feb 20, 2026
@mcgrew-oai mcgrew-oai enabled auto-merge (squash) February 24, 2026 20:07
@mcgrew-oai mcgrew-oai disabled auto-merge February 24, 2026 21:38
@mcgrew-oai mcgrew-oai merged commit bccce0d into main Feb 25, 2026
38 of 39 checks passed
@mcgrew-oai mcgrew-oai deleted the mcgrew/otel-host-name branch February 25, 2026 14:54
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

oai PRs contributed by OpenAI employees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants