lambda_otel_lite

Trait SpanAttributesExtractor

Source
pub trait SpanAttributesExtractor {
    // Required method
    fn extract_span_attributes(&self) -> SpanAttributes;
}
Expand description

Trait for types that can provide span attributes.

Implement this trait for your event types to enable automatic attribute extraction. The layer will automatically detect and use this implementation when processing events.

§Implementation Guidelines

When implementing this trait:

  1. Extract relevant attributes that describe the event
  2. Set appropriate span kind if different from SERVER
  3. Include any headers needed for context propagation
  4. Add span links if the event is related to other traces

§Example

use lambda_otel_lite::{SpanAttributes, SpanAttributesExtractor};
use std::collections::HashMap;

struct CustomEvent {
    operation: String,
    trace_parent: Option<String>,
}

impl SpanAttributesExtractor for CustomEvent {
    fn extract_span_attributes(&self) -> SpanAttributes {
        let mut attributes = HashMap::new();
        attributes.insert("operation".to_string(), self.operation.clone());

        // Add trace context if available
        let carrier = self.trace_parent.as_ref().map(|header| {
            let mut headers = HashMap::new();
            headers.insert("traceparent".to_string(), header.clone());
            headers
        });

        SpanAttributes {
            attributes,
            carrier,
            ..SpanAttributes::default()
        }
    }
}

Required Methods§

Source

fn extract_span_attributes(&self) -> SpanAttributes

Extract span attributes from this type.

This method should extract any relevant information from the implementing type that should be included in the OpenTelemetry span. This includes:

  • Custom attributes describing the event
  • Span kind if different from SERVER
  • Headers for context propagation
  • Links to related traces

Implementations on Foreign Types§

Source§

impl SpanAttributesExtractor for AlbTargetGroupRequest

Source§

impl SpanAttributesExtractor for ApiGatewayProxyRequest

Source§

impl SpanAttributesExtractor for ApiGatewayV2httpRequest

Implementors§