Skip to content

Conversation

@leghadjeu-christian
Copy link
Contributor

@leghadjeu-christian leghadjeu-christian commented Dec 5, 2025

Fixes #3221
Design discussion issue (if applicable) #

Changes

Add experimental experimental_span_attributes feature to enrich log records with attributes from active tracing spans.
When enabled, span attributes are automatically included in log records. Event attributes take precedence on conflicts.

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)

@leghadjeu-christian leghadjeu-christian requested a review from a team as a code owner December 5, 2025 21:24
@leghadjeu-christian leghadjeu-christian marked this pull request as draft December 5, 2025 21:26
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 86.28571% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.5%. Comparing base (07bb613) to head (6b1042a).

Files with missing lines Patch % Lines
opentelemetry-appender-tracing/src/layer.rs 86.2% 24 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #3282    +/-   ##
======================================
  Coverage   80.5%   80.5%            
======================================
  Files        129     129            
  Lines      23286   23456   +170     
======================================
+ Hits       18748   18894   +146     
- Misses      4538    4562    +24     

☔ 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.

@leghadjeu-christian leghadjeu-christian marked this pull request as ready for review December 10, 2025 01:11
@leghadjeu-christian leghadjeu-christian changed the title [WIP]: feat(appender-tracing): add experimental span attributes enrichment feat(appender-tracing): add experimental span attributes enrichment Dec 10, 2025
self.logger.emit(log_record);
}
#[cfg(feature = "experimental_span_attributes")]
fn on_new_span(
Copy link
Member

Choose a reason for hiding this comment

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

do we need to do anything to remove this from the span extensions, when span is being exited? Or its auto removed by tracing itself?

id: &tracing::span::Id,
ctx: tracing_subscriber::layer::Context<'_, S>,
) {
let span = ctx.span(id).expect("Span not found; this is a bug");
Copy link
Member

Choose a reason for hiding this comment

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

is it a bug in OTel side? or tracing ?


#[test]
#[cfg(feature = "experimental_span_attributes")]
fn test_span_context_enrichment_enabled() {
Copy link
Member

Choose a reason for hiding this comment

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

can you add a test for nested spans? I am curious on how that works as well...

if let Some(span) = ctx.event_span(event) {
let extensions = span.extensions();
if let Some(stored) = extensions.get::<StoredSpanAttributes>() {
// Add span attributes first (event attributes will overwrite on conflict). TODO: Consider conflict resolution strategies.
Copy link
Member

Choose a reason for hiding this comment

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

Can you point me to where is the overwrite logic? OTel SDK itself does not do any overwrite...

);
}

fn record_i64(&mut self, field: &tracing::field::Field, value: i64) {
Copy link
Member

Choose a reason for hiding this comment

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

are the field names &'static str ? Can we leverage that and avoid String which forces a heap allocation for each attribute?

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/src/common.rs#L16-L49
We'd avoid allocation if &'static str is used. Let's do it. Its already done in the event visitor.

/// Visitor to extract fields from a tracing span
#[cfg(feature = "experimental_span_attributes")]
struct SpanFieldVisitor {
fields: HashMap<String, AnyValue>,
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using String as the key, you should use OTel's Key.. that should avoid the heap allocations.

Copy link
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.

Thanks for working on this. I left comments. We need to do this with high performance, avoiding allocations wherever feasible.
Also, we need to have tests for nested spans.
please check comments.

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.

Add tracing span support to tracing events in opentelemetry-appender-tracing

2 participants