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:
- Extract relevant attributes that describe the event
- Set appropriate span kind if different from SERVER
- Include any headers needed for context propagation
- 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§
Sourcefn extract_span_attributes(&self) -> SpanAttributes
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