Skip to content

feat(appender-tracing): propagate span name to logs#3466

Open
SuperFluffy wants to merge 1 commit into
open-telemetry:mainfrom
SuperFluffy:propagate-span-name
Open

feat(appender-tracing): propagate span name to logs#3466
SuperFluffy wants to merge 1 commit into
open-telemetry:mainfrom
SuperFluffy:propagate-span-name

Conversation

@SuperFluffy

Copy link
Copy Markdown
Contributor

Changes

Propagates the tracing span name to OTEL logs.

Similar to the experimental span attributes, the span containing the event is valuable to identify where and what happened.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@SuperFluffy SuperFluffy requested a review from a team as a code owner April 21, 2026 15:06
@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.0%. Comparing base (1b3846c) to head (2073c8b).

Additional details and impacted files
@@          Coverage Diff           @@
##            main   #3466    +/-   ##
======================================
  Coverage   82.9%   83.0%            
======================================
  Files        130     130            
  Lines      27768   27923   +155     
======================================
+ Hits       23040   23195   +155     
  Misses      4728    4728            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread opentelemetry-appender-tracing/src/layer.rs Outdated
Comment thread opentelemetry-appender-tracing/src/layer.rs Outdated

@cijothomas cijothomas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agree we need to provide a way to attach span name, but need to also avoid picking an attribute name ourselves. See
#3466 (comment)

Comment thread opentelemetry-appender-tracing/src/layer.rs Outdated
@SuperFluffy

Copy link
Copy Markdown
Contributor Author

Agree we need to provide a way to attach span name, but need to also avoid picking an attribute name ourselves. See #3466 (comment)

Did the changes. I guess this leaves open the question what to do if span and attribute names clash - but I don't think this crate should handle. Last time I checked the tracing crate itself just uses the last value it finds for a given key, so this is consistent.

@SuperFluffy SuperFluffy requested a review from cijothomas May 4, 2026 16:13
@cijothomas

Copy link
Copy Markdown
Member

Agree we need to provide a way to attach span name, but need to also avoid picking an attribute name ourselves. See #3466 (comment)

Did the changes. I guess this leaves open the question what to do if span and attribute names clash - but I don't think this crate should handle. Last time I checked the tracing crate itself just uses the last value it finds for a given key, so this is consistent.

The clash is not handled by the OTel api/sdk, so it is left to users. (Something to be revisited, but definitely outside scope of this PR)

@SuperFluffy

Copy link
Copy Markdown
Contributor Author

Updated the PR and removed the feature flags since span attribute propagation was stabilized.

Comment thread opentelemetry-appender-tracing/src/layer.rs Outdated
@SuperFluffy

Copy link
Copy Markdown
Contributor Author

@cijothomas Is this a good time to revisit this? Happy to create a new patch.

@SuperFluffy SuperFluffy reopened this Jun 12, 2026
@cijothomas

Copy link
Copy Markdown
Member

I’d suggest making span-name enrichment a separate builder option from span-attribute enrichment:

let layer = OpenTelemetryTracingBridge::builder(&provider)
    .with_tracing_span_attributes(TracingSpanAttributes::all())
    .with_tracing_span_name("span.name")
    .build();

with_tracing_span_name should be independent, so users can enable span attributes only, span name only, or both. The argument should be documented as the log attribute key where the current tracing span name will be stored, not the span name itself. If users do not call this method, we should not add any span-name attribute.

@SuperFluffy SuperFluffy force-pushed the propagate-span-name branch from b125321 to 2073c8b Compare June 23, 2026 12:45
@SuperFluffy

Copy link
Copy Markdown
Contributor Author

@cijothomas Let's give this another shot. :-) The change is simple enough.

// Extract tracing-span enrichment if enabled.
#[cfg(feature = "experimental_span_attributes")]
if self.span_attributes.is_some() {
if self.span_attributes.is_some() || self.span_name.is_some() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if just span_name is required, do we need to walk entire scope? Any easier way to grab the span name from current ?

self
}

/// Store the current tracing span's name on each emitted log record using

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@SuperFluffy
Thanks for continuing to work on this. This is looking better. One thing I want to discuss more:

Pretty sure we'd need to expand the support for this to let use pick inner-most or outer-most (or all 🤣 ). Could you consider that future need in mind, and see if how could we evolve?

I haven't dug into details yet, but I think we should consider a design that can accommodate future expansion without looking awkward.

An example use-case I am aware of is: When a service receives incoming request, it starts a tracing::span with name indicating overall operation. Then there are sub spans too. For the log, it may be desired to store the outermost span name, instead of inner most. I understand we agreed to start with inner-most, but could you outline how this could be expanded without ending up with confusing API ?

@cijothomas

Copy link
Copy Markdown
Member

@SuperFluffy I will also ask in OTel semantic convention group if they have thought about blessing/reserving an attribute for stamping span-name to Logs. If such a thing lands, then we can follow that.

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.

2 participants