Module resource

Source
Expand description

Resource attribute management for Lambda functions.

This module provides functionality for managing OpenTelemetry resource attributes in a Lambda environment. It automatically detects and sets standard Lambda attributes and allows for custom attribute configuration through environment variables.

§Automatic FAAS Attributes

The module automatically sets relevant FAAS attributes based on the Lambda context:

§Resource Attributes

  • cloud.provider: Set to “aws”
  • cloud.region: From AWS_REGION
  • faas.name: From AWS_LAMBDA_FUNCTION_NAME
  • faas.version: From AWS_LAMBDA_FUNCTION_VERSION
  • faas.instance: From AWS_LAMBDA_LOG_STREAM_NAME
  • faas.max_memory: From AWS_LAMBDA_FUNCTION_MEMORY_SIZE
  • service.name: From OTEL_SERVICE_NAME or function name

§Configuration

§Custom Attributes

Additional attributes can be set via the OTEL_RESOURCE_ATTRIBUTES environment variable in the format: key=value,key2=value2. Values can be URL-encoded if they contain special characters:

# Setting custom attributes
OTEL_RESOURCE_ATTRIBUTES="deployment.stage=prod,custom.tag=value%20with%20spaces"

§Service Name

The service name can be configured in two ways:

  1. Using OTEL_SERVICE_NAME environment variable:
OTEL_SERVICE_NAME="my-custom-service"
  1. Through the TelemetryConfig builder:
use lambda_otel_lite::{TelemetryConfig, init_telemetry};
use opentelemetry::KeyValue;
use opentelemetry_sdk::Resource;

let resource = Resource::builder()
    .with_attributes(vec![
        KeyValue::new("service.name", "my-service"),
        KeyValue::new("service.version", "1.0.0"),
    ])
    .build();

let config = TelemetryConfig::builder()
    .resource(resource)
    .build();

let _completion_handler = init_telemetry(config).await?;

§Integration

This module is primarily used by the init_telemetry function to configure the OpenTelemetry tracer provider. The detected resource attributes are automatically attached to all spans created by the tracer.

See the telemetry module for more details on initialization and configuration options.

Functions§

get_lambda_resource
Get default Lambda resource attributes.