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
§Returns
Returns a Resource containing all detected and configured attributes.
§Examples
Basic usage with automatic detection:
use lambda_otel_lite::get_lambda_resource;
let resource = get_lambda_resource();Using with custom attributes:
use lambda_otel_lite::get_lambda_resource;
use std::env;
// Set custom attributes
env::set_var("OTEL_RESOURCE_ATTRIBUTES", "deployment.stage=prod,team=backend");
env::set_var("OTEL_SERVICE_NAME", "payment-processor");
let resource = get_lambda_resource();Merging with additional resource attributes:
use lambda_otel_lite::get_lambda_resource;
use opentelemetry::KeyValue;
use opentelemetry_sdk::Resource;
// Get base Lambda resource
let lambda_resource = get_lambda_resource();
// Create additional resource
let extra_resource = Resource::new(vec![
KeyValue::new("service.version", "1.0.0"),
KeyValue::new("deployment.environment", "staging"),
]);
// Merge resources (Lambda attributes take precedence)
let final_resource = extra_resource.merge(&lambda_resource);§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?;