Module: OpenTelemetry::Resource::Detector::AWS::Lambda
- Extended by:
- Lambda
- Included in:
- Lambda
- Defined in:
- lib/opentelemetry/resource/detector/aws/lambda.rb
Overview
Lambda contains detect class method for determining Lambda resource attributes
Constant Summary collapse
- RESOURCE =
Create a constant for resource semantic conventions
OpenTelemetry::SemanticConventions::Resource
Instance Method Summary collapse
Instance Method Details
#detect ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/opentelemetry/resource/detector/aws/lambda.rb', line 20 def detect # Return empty resource if not running on Lambda return OpenTelemetry::SDK::Resources::Resource.create({}) unless lambda_environment? resource_attributes = {} begin # Set Lambda-specific attributes from environment variables resource_attributes[RESOURCE::CLOUD_PROVIDER] = 'aws' resource_attributes[RESOURCE::CLOUD_PLATFORM] = 'aws_lambda' resource_attributes[RESOURCE::CLOUD_REGION] = ENV.fetch('AWS_REGION', nil) resource_attributes[RESOURCE::FAAS_NAME] = ENV.fetch('AWS_LAMBDA_FUNCTION_NAME', nil) resource_attributes[RESOURCE::FAAS_VERSION] = ENV.fetch('AWS_LAMBDA_FUNCTION_VERSION', nil) resource_attributes[RESOURCE::FAAS_INSTANCE] = ENV.fetch('AWS_LAMBDA_LOG_STREAM_NAME', nil) # Convert memory size to integer resource_attributes[RESOURCE::FAAS_MAX_MEMORY] = ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE'].to_i if ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE'] rescue StandardError => e OpenTelemetry.handle_error(exception: e, message: 'Lambda resource detection failed') return OpenTelemetry::SDK::Resources::Resource.create({}) end # Filter out nil or empty values # Note: we need to handle integers differently since they don't respond to empty? resource_attributes.delete_if do |_key, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) end OpenTelemetry::SDK::Resources::Resource.create(resource_attributes) end |