pub fn get_lambda_resource() -> ResourceExpand description
Get default Lambda resource attributes.
This function automatically detects and sets standard Lambda attributes from environment
variables and allows for custom attribute configuration through OTEL_RESOURCE_ATTRIBUTES.
§Environment Variables
AWS_REGION: Setscloud.regionAWS_LAMBDA_FUNCTION_NAME: Setsfaas.nameand defaultservice.nameAWS_LAMBDA_FUNCTION_VERSION: Setsfaas.versionAWS_LAMBDA_FUNCTION_MEMORY_SIZE: Setsfaas.max_memoryAWS_LAMBDA_LOG_STREAM_NAME: Setsfaas.instanceOTEL_SERVICE_NAME: Overrides default service nameOTEL_RESOURCE_ATTRIBUTES: Additional attributes in key=value format
§Configuration Attributes
The following configuration attributes are set in the resource only when the corresponding environment variables are explicitly set:
LAMBDA_EXTENSION_SPAN_PROCESSOR_MODE: Setslambda_otel_lite.extension.span_processor_modeLAMBDA_SPAN_PROCESSOR_QUEUE_SIZE: Setslambda_otel_lite.lambda_span_processor.queue_sizeLAMBDA_SPAN_PROCESSOR_BATCH_SIZE: Setslambda_otel_lite.lambda_span_processor.batch_sizeOTLP_STDOUT_SPAN_EXPORTER_COMPRESSION_LEVEL: Setslambda_otel_lite.otlp_stdout_span_exporter.compression_level
§Returns
Returns a Resource containing all detected and configured attributes.
§Examples
Basic usage with environment variables:
use lambda_otel_lite::resource::get_lambda_resource;
use opentelemetry::KeyValue;
// Get resource with Lambda environment attributes
let resource = get_lambda_resource();Adding custom attributes:
use lambda_otel_lite::resource::get_lambda_resource;
use opentelemetry::KeyValue;
use opentelemetry_sdk::Resource;
// Get Lambda resource
let lambda_resource = get_lambda_resource();
// Create custom resource
let extra_resource = Resource::builder()
.with_attributes(vec![
KeyValue::new("deployment.stage", "prod"),
KeyValue::new("team", "backend"),
])
.build();
// Combine resources (custom attributes take precedence)
// Create a new resource with all attributes
let mut all_attributes = vec![
KeyValue::new("deployment.stage", "prod"),
KeyValue::new("team", "backend"),
];
// Add lambda attributes (could be done more programmatically in real code)
all_attributes.push(KeyValue::new("cloud.provider", "aws"));
all_attributes.push(KeyValue::new("faas.name", "my-function"));
let final_resource = Resource::builder()
.with_attributes(all_attributes)
.build();§Integration with Telemetry Config
This function is automatically called by init_telemetry
when no custom resource is provided. To override or extend these attributes, use
the TelemetryConfig builder:
use lambda_otel_lite::{TelemetryConfig, init_telemetry};
use opentelemetry_sdk::Resource;
// Get base Lambda resource
let base_resource = lambda_otel_lite::get_lambda_resource();
// Configure telemetry with the resource
let config = TelemetryConfig::builder()
.resource(base_resource)
.build();
let _completion_handler = init_telemetry(config).await?;