pub struct SpanAttributes {
pub kind: Option<String>,
pub span_name: Option<String>,
pub attributes: HashMap<String, Value>,
pub links: Vec<Link>,
pub carrier: Option<HashMap<String, String>>,
pub trigger: String,
}Expand description
Data extracted from a Lambda event for span creation.
This struct contains all the information needed to create and configure an OpenTelemetry span, including custom attributes, span kind, links, and context propagation headers.
§Span Kind
The kind field accepts standard OpenTelemetry span kinds:
- “SERVER” (default): Inbound request handling
- “CLIENT”: Outbound calls
- “PRODUCER”: Message/event production
- “CONSUMER”: Message/event consumption
- “INTERNAL”: Internal operations
§Span Name
For HTTP spans, the span_name is automatically generated from the HTTP method and route:
- API Gateway V2: “GET /users/{id}” (with $default mapped to “/”)
- API Gateway V1: “POST /orders”
- ALB: “PUT /items/123”
§Attributes
Standard HTTP attributes following OpenTelemetry semantic conventions:
http.request.method: The HTTP methodurl.path: The request pathurl.query: The query string (if present)url.scheme: The protocol schemenetwork.protocol.version: The HTTP protocol versionhttp.route: The route pattern or resource pathclient.address: The client’s IP addressuser_agent.original: The user agent stringserver.address: The server’s domain name or host
§Context Propagation
The carrier field supports both W3C Trace Context and AWS X-Ray headers:
traceparent: W3C format containing trace ID, span ID, and trace flagstracestate: W3C vendor-specific trace informationx-amzn-trace-id: AWS X-Ray trace header format
§Examples
Basic usage with custom attributes:
use lambda_otel_lite::SpanAttributes;
use std::collections::HashMap;
use opentelemetry::Value;
let mut attributes = HashMap::new();
attributes.insert("custom.field".to_string(), Value::String("value".into()));
let span_attrs = SpanAttributes::builder()
.attributes(attributes)
.build();Fields§
§kind: Option<String>Optional span kind (defaults to SERVER if not provided) Valid values: “SERVER”, “CLIENT”, “PRODUCER”, “CONSUMER”, “INTERNAL”
span_name: Option<String>Optional span name. For HTTP spans, this should be “{http.method} {http.route}” Example: “GET /users/:id”
attributes: HashMap<String, Value>Custom attributes to add to the span. Follow OpenTelemetry semantic conventions for naming: https://opentelemetry.io/docs/specs/semconv/
links: Vec<Link>Optional span links for connecting related traces. Useful for batch processing or joining multiple workflows.
carrier: Option<HashMap<String, String>>Optional carrier headers for context propagation. Supports both W3C Trace Context and AWS X-Ray formats:
traceparent: W3C format containing trace ID, span ID, and trace flagstracestate: W3C vendor-specific trace informationx-amzn-trace-id: AWS X-Ray trace header format
trigger: StringThe type of trigger for this Lambda invocation. Common values: “datasource”, “http”, “pubsub”, “timer”, “other” Custom values can be used for more specific triggers.
Implementations§
Source§impl SpanAttributes
impl SpanAttributes
Sourcepub fn builder() -> SpanAttributesBuilder
pub fn builder() -> SpanAttributesBuilder
Create an instance of SpanAttributes using the builder syntax
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SpanAttributes
impl RefUnwindSafe for SpanAttributes
impl Send for SpanAttributes
impl Sync for SpanAttributes
impl Unpin for SpanAttributes
impl UnwindSafe for SpanAttributes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request