opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

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

Open cijothomas opened this issue 1 month ago • 4 comments

opentelemetry-appender-tracing crate currently converts tracing events to OpenTelemetry LogRecords but ignores span context. We should include span attributes in the LogRecord attributes when events are emitted within an active span (tracing span).

Current behavior:

let span = info_span!("request", user_id = 123, endpoint = "/api/users");
let _guard = span.enter();
info!(status = 200, "Request completed");
// LogRecord only contains: status = 200, message = "Request completed"

Desired behavior:

let span = info_span!("request", user_id = 123, endpoint = "/api/users");
let _guard = span.enter();
info!(status = 200, "Request completed");
// LogRecord should contain: status = 200, message = "Request completed", user_id = 123, endpoint = "/api/users"

This is distinct from the tracing-opentelemetry crate which converts tracing spans to OTel spans. This issue is specifically about enriching log records with span context from tracing.

cijothomas avatar Nov 03 '25 17:11 cijothomas

Design Considerations

  1. Opt-in behavior - Feature should be disabled by default to maintain backward compatibility

  2. Span name inclusion - Decide whether to include the span name as a LogRecord attribute and what attribute key to use (e.g., span.name, tracing.span_name)

  3. Span depth control - Allow users to configure how many levels of the span hierarchy to include:

    • Current span only
    • Full span stack with all ancestors
    • Configurable depth limit
  4. Attribute conflict resolution - Handle cases where span and event attributes have the same key:

    • Event attributes take precedence (overwrite span attributes)
    • Span attributes take precedence
    • Use prefixing/suffixing and/or depth_prefixing to avoid conflicts
    • User-configurable strategy
  5. Attribute filtering - Provide options to:

    • Include/exclude specific span attributes
    • Apply attribute name transformations

cijothomas avatar Nov 03 '25 17:11 cijothomas

I've been bitten by this. Currently, I get logs with all the span context emitted just fine to stderr, but OTEL doesn't pick up the span context fields. So I'm missing a whole bunch of my context.

Bluefinger avatar Dec 01 '25 07:12 Bluefinger

@cijothomas i can work on this, please can you assign me.

leghadjeu-christian avatar Dec 02 '25 06:12 leghadjeu-christian

@cijothomas i can work on this, please can you assign me.

Thanks! Please work on it incrementally - I listed several considerations, but we can start with the most basic one, and then incrementally add more advanced capabilities.

cijothomas avatar Dec 02 '25 17:12 cijothomas