Expand description
Attribute extraction for OpenTelemetry spans in AWS Lambda functions.
This module provides functionality for extracting OpenTelemetry span attributes from AWS Lambda events. It includes:
- Built-in support for common AWS event types (API Gateway, ALB)
- Extensible trait system for custom event types
- Automatic W3C Trace Context and AWS X-Ray propagation
- Support for span links and custom attributes
§Architecture
The module uses a trait-based approach for attribute extraction:
- Event Processing: Each supported event type implements the
SpanAttributesExtractortrait - Attribute Collection: Standard attributes are collected based on event type
- Context Propagation: W3C Trace Context and AWS X-Ray headers are automatically extracted
- Custom Attributes: Additional attributes can be added through custom implementations
§Automatic Attributes
The module automatically extracts and sets several types of attributes:
§Resource Attributes
cloud.provider: Set to “aws”cloud.region: From AWS_REGIONfaas.name: From AWS_LAMBDA_FUNCTION_NAMEfaas.version: From AWS_LAMBDA_FUNCTION_VERSIONfaas.instance: From AWS_LAMBDA_LOG_STREAM_NAMEfaas.max_memory: From AWS_LAMBDA_FUNCTION_MEMORY_SIZEservice.name: From OTEL_SERVICE_NAME or function name
§Span Attributes
faas.coldstart: True only on first invocationfaas.invocation_id: From Lambda request IDcloud.account.id: From function ARNcloud.resource_id: Complete function ARNotel.kind: “SERVER” by defaultotel.status_code/message: From response processing
§HTTP Attributes (for supported event types)
faas.trigger: Set to “http” for API/ALB eventshttp.status_code: From responsehttp.route: Route key or resource pathhttp.method: HTTP methodurl.path: Request pathurl.query: Query parameters if presenturl.scheme: Protocol (https)network.protocol.version: HTTP versionclient.address: Client IP addressuser_agent.original: User agent stringserver.address: Server hostname
§Built-in Support
The following AWS event types are supported out of the box:
- API Gateway v1/v2 (HTTP API and REST API)
- Application Load Balancer
Each implementation follows OpenTelemetry semantic conventions for HTTP spans:
http.request.method: The HTTP method (e.g., “GET”, “POST”)url.path: The request pathurl.query: The query string (if present)url.scheme: The protocol scheme (“https” for API Gateway, configurable for ALB)network.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
§Performance Considerations
- Attribute extraction is done lazily when spans are created
- String allocations are minimized where possible
- Header extraction filters invalid UTF-8 values
Structs§
- Span
Attributes - Data extracted from a Lambda event for span creation.
- Span
Attributes Builder - Use builder syntax to set the inputs and finish with
build().
Enums§
- Trigger
Type - Common trigger types for Lambda functions.
Traits§
- Span
Attributes Extractor - Trait for types that can provide span attributes.
Functions§
- get_
status_ code - Extract status code from response if it’s an HTTP response.
- set_
common_ attributes - Set common attributes on the span based on the Lambda context.
- set_
response_ attributes - Set response attributes on the span based on the response value.