Skip to content

feat: add otel resource and instrumentation scope attributes to traces#498

Merged
svencowart merged 2 commits intomainfrom
resource-scope-attributes
Mar 2, 2026
Merged

feat: add otel resource and instrumentation scope attributes to traces#498
svencowart merged 2 commits intomainfrom
resource-scope-attributes

Conversation

@svencowart
Copy link
Member

@svencowart svencowart commented Mar 2, 2026

Changes

  • introduce otlp/resource module with detect_resource() that collects host.name, host.id, host.ip, telemetry.distro.*, k8s.node.uid, k8s.node.name, k8s.cluster.uid, and k8s.namespace.name at startup
  • resolve host.name with priority: k8s internaldns > getaddrinfo ai_canonname > k8s hostname > gethostname() fallback
  • collect internalip addresses from k8s node api (all addresses of type
    "InternalIP" from node.status.addresses) with fall back to host_interface_ips() via nix getifaddrs when k8s is unavailable, filtering loopback, point-to-point, and link-local
  • cache sdktracer with instrumentation scope set to mermin version, removing per-export provider.tracer() call
  • fix metrics_exporter not delegating set_resource to inner exporter, causing resource attributes to never appear in exported spans
  • refactor metrics_exporter export to async fn, removing unsafe transmute against a 'static bound that does not exist on the trait
  • bump mermin/cargo.toml version in release ci pipeline via sed
  • update local k8s dev docs to use colima k3s with a local docker registry

Fixes #481

Type of change

  • Bug fix

Testing

Deployed on k8s and without k8s environment and verified the results.

Proof it works

Output without k8s cluster:

Spans
Resource
         ->  host.name=String(Owned("98c4a29c9d1e"))
         ->  telemetry.distro.version=String(Static("0.1.0"))
         ->  telemetry.distro.name=String(Static("mermin"))
         ->  host.id=String(Owned("355568efae014062b277813a9ccd7f54"))
         ->  host.ip=Array(String([Owned("172.17.0.3")]))

Output within k8s cluster:

mermin-c8jj7 mermin Spans
mermin-c8jj7 mermin Resource
mermin-c8jj7 mermin      ->  k8s.cluster.uid=String(Owned("f6200247-39c6-4aa7-948a-c5e56cf6f0a7"))
mermin-c8jj7 mermin      ->  host.name=String(Owned("colima-atlantis"))
mermin-c8jj7 mermin      ->  host.ip=Array(String([Owned("172.17.0.3")]))
mermin-c8jj7 mermin      ->  telemetry.distro.version=String(Static("0.1.0"))
mermin-c8jj7 mermin      ->  telemetry.distro.name=String(Static("mermin"))
mermin-c8jj7 mermin      ->  k8s.node.name=String(Owned("colima-atlantis"))
mermin-c8jj7 mermin      ->  k8s.namespace.name=String(Owned("default"))
mermin-c8jj7 mermin      ->  k8s.node.uid=String(Owned("b1496f8a-62dc-4800-b23f-65a8c89e48ae"))

- introduce otlp/resource module with detect_resource() that collects
  host.name, host.id, telemetry.distro.*, k8s.node.uid, k8s.node.name,
  k8s.cluster.uid, and k8s.namespace.name at startup
- resolve host.name with priority: k8s internaldns > getaddrinfo
  ai_canonname > k8s hostname > gethostname() fallback
- cache sdktracer with instrumentation scope set to mermin version,
  removing per-export provider.tracer() call
- fix metrics_exporter not delegating set_resource to inner exporter,
  causing resource attributes to never appear in exported spans
- refactor metrics_exporter export to async fn, removing unsafe transmute
  against a 'static bound that does not exist on the trait
- bump mermin/cargo.toml version in release ci pipeline via sed
- update local k8s dev docs to use colima k3s with a local docker registry
@svencowart svencowart force-pushed the resource-scope-attributes branch from 877c0e0 to d3b166a Compare March 2, 2026 18:26
- collect internalip addresses from k8s node api (all addresses of type
  "InternalIP" from node.status.addresses)
- fall back to host_interface_ips() via nix getifaddrs when k8s is
  unavailable, filtering loopback, point-to-point, and link-local
- emit host.ip as an otel array(string) value per semantic conventions
- extend get_k8s_node return type to (uid, host, ips) tuple
- enable nix "net" feature for ifaddrs support
@svencowart svencowart merged commit 32cf595 into main Mar 2, 2026
18 checks passed
@svencowart svencowart deleted the resource-scope-attributes branch March 2, 2026 18:53
@github-actions github-actions bot mentioned this pull request Mar 2, 2026
svencowart added a commit that referenced this pull request Mar 2, 2026
# Description
Release the v0.3.0 version

# Changelog
## [v0.3.0] - 2026-03-02

### Features

- Add otel resource and instrumentation scope attributes to traces
(#498)


[v0.2.1..v0.3.0](v0.2.1...v0.3.0)

Co-authored-by: svencowart <8366524+svencowart@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing Resource and Scope during export

1 participant