Skip to content

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

Open
SuperFluffy wants to merge 3 commits intoopen-telemetry:mainfrom
SuperFluffy:propagate-span-name
Open

feat(appender-tracing): propagate span name to logs#3466
SuperFluffy wants to merge 3 commits intoopen-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
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.7%. Comparing base (8e95e16) to head (85941a7).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3466     +/-   ##
=======================================
+ Coverage   83.2%   83.7%   +0.4%     
=======================================
  Files        128     126      -2     
  Lines      25086   25502    +416     
=======================================
+ Hits       20896   21370    +474     
+ Misses      4190    4132     -58     

☔ View full report in Codecov by Sentry.
📢 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.

}
}
if let Some(name) = current_span_name {
log_record.add_attribute(Key::new("span.name"), AnyValue::from(name));
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.

"span.name" - Its tricky! There is no established convention, so any name we pick can cause issues. Need to see if we can find any alternate solution.

Also, what happens when nesting of spans is there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, what happens when nesting of spans is there?

Related to your other comment for the test - this selects the inner-most span, so the span that immediately contains the event. I think that's the most natural span to select?

Alternatively we can follow tracing-subscriber's formatting subscriber which essentially contains a list of all spans.

"span.name"

I agree. None of this is great. Maybe just name?

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.

Given there is no way we can ensure conflict avoidance, could we avoid making that decision ourselves, and let user make that?
use_span_name("whatever name.user wants") ?
If user does not do the above, then we ignore the span-name. If the do it, then they gives us the attribute name.

WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, that simplifies this a lot. Added a OpenTelemetryTracingBridgeBuilder::with_span_name to toggle injecting spans into the attribute list.

assert_eq!(logs.len(), 1);
let log = &logs[0];

// The span.name should be the current (leaf/innermost) span
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.

How do we determine what innermost is what user wants?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Innermost is the most natural. Alternatively I can see collecting a list of all spans (probably not ideal).

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.

seems reasonable. Though I can see some users wanting ability to customize it. Probably we can start with this, and based on feedback, allow advanced capabilities.

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.

could you add this as a TODO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added this as an inline TODO in the loop under OpenTelemetryTracingBridge::on_event.

Copy link
Copy Markdown
Member

@cijothomas cijothomas left a comment

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)

/// (the default) disables it.
#[cfg(feature = "experimental_span_attributes")]
pub fn with_span_name(mut self, key: impl Into<Key>) -> Self {
self.span_name_key = Some(key.into());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note sure in how far this matters, but key here should be set once and be alive until the end of the program. Does it make sense to Box::leak::<'static> the key/string?

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.

given this is tracing related, and tracing only has &static` keys, lets also accept that here?

Copy link
Copy Markdown
Contributor Author

@SuperFluffy SuperFluffy May 5, 2026

Choose a reason for hiding this comment

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

given this is tracing related, and tracing only has &static keys, lets also accept that here?

Can you clarify? Do you mean we should only have

        pub fn with_span_name(mut self, key: &'static str) -> Self {

@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
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