opentelemetry-lambda icon indicating copy to clipboard operation
opentelemetry-lambda copied to clipboard

feat: auto-inject AWS account ID into telemetry from Lambda extension registration

Open RaphaelManke opened this issue 3 months ago • 0 comments

Summary

Automatically extract the AWS account ID from the Lambda Extensions API registration response and inject it as the cloud.account.id attribute into all telemetry (traces, logs, metrics) via a confmap converter.

This implementation uses the OpenTelemetry Collector's converter pattern to mutate the loaded configuration, ensuring the account ID is automatically available without requiring configuration or environment variables.

Changes

  • extensionapi/client.go: Added AccountId field to RegisterResponse and request the accountId feature via Lambda-Extension-Accept-Feature header
  • accountidprocessor/converter.go: New confmap converter that automatically injects a resource processor for cloud.account.id attribute into all pipelines
  • accountidprocessor/converter_test.go: Comprehensive tests for converter behavior (empty account ID, no pipelines, multiple pipelines, leading zeros)
  • extensionapi/client_test.go: Tests for JSON unmarshaling with leading zero preservation
  • lambdacomponents/default.go: Updated to accept accountID and return converter factories
  • collector.go: Updated to accept and register custom converters
  • manager.go: Updated to pass account ID through the initialization flow

Benefits

  • Account ID automatically available in all telemetry without configuration
  • No environment variables needed, uses AWS Lambda API response
  • Follows OpenTelemetry Collector patterns
  • Static injection at startup with no runtime overhead
  • Comprehensive test coverage for edge cases (leading zeros, multiple pipelines)

RaphaelManke avatar Oct 24 '25 12:10 RaphaelManke