Skip to content

Unable to update otel.name field #240

@spencewenski

Description

@spencewenski

Bug Report

Version

tracing v0.1.41
tracing-attributes v0.1.30
tracing-core v0.1.34
tracing-opentelemetry v0.32.0
tracing-log v0.2.0
tracing-subscriber v0.3.20
tracing-serde v0.2.0

Platform

Darwin grqmuxsirm.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:29:54 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T8122 arm64

Description

I'm not able to update the special otel.name attribute after it's set on a span. For context, I'm using tower_http::trace::TraceLayer on my root axum router with a custom MakeSpan to set the otel.name to include the matched axum route. However, I also have some nested routers (added with Router::nest_service). Because the routers are nested, the matched path does not include the full path from the nested service. So, I was trying to attach an additional layer to the nested service to update the otel.name value. This seems to partially work -- traces appear to have the correct value when I view them with the log subscriber. However, the root span name is not correct in the otel collector (grafana in my case). I think it's expected that the span field is not updated if it already has a value, but I'm seeing the same behavior even if I set the value to tracing::field::Empty initially.

I tried a few different approaches to update the value:

  1. Using Span::record
let span = tracing::info_span!("A", otel.name = "otel-A", http.route = "/pathA");
span.in_scope(|| {
    Span::current().record("otel.name", "otel-A updated");
    Span::current().record("http.route", "/pathA/updated");
    tracing::info!("/pathA event");
});

which results in:

2025-11-27T20:40:40.972236Z  INFO A{otel.name="otel-A" http.route="/pathA" otel.name="otel-A updated" http.route="/pathA/updated"}: opentelemetry_otlp: /pathA event

Note the duplicate otel.name and http.route fields and the root span does not have the correct name in grafana (screenshot below).

  1. Using Span::record with tracing::field::Empty
let span = tracing::info_span!("B", otel.name = tracing::field::Empty, http.route = tracing::field::Empty);
span.in_scope(|| {
    Span::current().record("otel.name", "otel-B updated");
    Span::current().record("http.route", "/pathB/updated");
    tracing::info!("/pathB event");
});

which results in:

2025-11-27T20:40:40.972295Z  INFO B{otel.name="otel-B updated" http.route="/pathB/updated"}: opentelemetry_otlp: /pathB event

Note that the fields have the correct values, but the root span does not have the correct name in grafana (screenshot below)

  1. Using OpenTelemetrySpanExt::set_attribute:
let span = tracing::info_span!("C", otel.name = "otel-C", http.route = "/pathC");
span.in_scope(|| {
    Span::current().set_attribute("otel.name", "otel-C updated");
    Span::current().set_attribute("http.route", "/pathC/updated");
    tracing::info!("/pathC event");
});

which results in:

2025-11-27T20:40:40.972349Z  INFO C{otel.name="otel-C" http.route="/pathC"}: opentelemetry_otlp: /pathC event

Note that the fields are not updated.

  1. Using OpenTelemetrySpanExt::set_attribute with tracing::field::Empty:
let span = tracing::info_span!("D", otel.name = tracing::field::Empty, http.route = tracing::field::Empty);
span.in_scope(|| {
    Span::current().set_attribute("otel.name", "otel-D updated");
    Span::current().set_attribute("http.route", "/pathD/updated");
    tracing::info!("/pathD event");
});

which results in

2025-11-27T20:40:40.972435Z  INFO D: opentelemetry_otlp: /pathD event

Note that the fields are not present at all.

In all of the above cases, the updated otel.name value does not appear to be reported to the OTEL collector (grafana in my case) even if it appears to be correct in the log output.

Image

However, the http.route is correct when it's originally set to tracing::field::Empty, as in examples 2 and 4 (B and D) (located next to the timestamp in the below screenshots):

A

Image

B

Image

C

Image

D

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions