aws-otel-java-instrumentation
aws-otel-java-instrumentation copied to clipboard
Configure `EMF` and `CompactLog` Exporters for Lambda Environment
Description of changes: Java version of these PRs:
- https://github.com/aws-observability/aws-otel-python-instrumentation/pull/442
- https://github.com/aws-observability/aws-otel-python-instrumentation/pull/437
This PR introduces Console EMF exporter and Compact Console logs exporter and enabling them for Lambda environments, allowing all forms of telemetry to be emitted directly to CloudWatch for users who've installed the Application Signals lambda layer.
To enable the Compact Console logs exporter, users must set the following environment variables in their Lambda:
OTEL_LOGS_EXPORTER:consolerequired
To enable the Console EMF exporter, users must set the following environment variables in their Lambda:
OTEL_METRICS_EXPORTER:awsemfrequiredOTEL_EXPORTER_OTLP_LOGS_HEADERS:x-aws-log-group=your-log-group,x-aws-log-stream=your-log-stream,x-aws-metric-namespaceoptional
Enabling the console exporters for EMF and logs will store the user's OTel metrics and logs directly in their Lambda log group.
Note 1: if users would like to store their EMF logs to a separate log group, they MUST* set this configuration OTEL_EXPORTER_OTLP_LOGS_HEADERS: x-aws-log-group=your-log-group,x-aws-log-stream=your-log-stream
Note 2: x-aws-metric-namespace will use default if it is not set
Testing:
- Added unit tests to validate EMF and console log record exporter configuration scenarios, including parameterized tests for both valid configurations and invalid configurations. The tests ensure the EMF and console log exporters are correctly enabled only when all required environment variables are properly configured.
Manual end to end testing with a custom built Lambda layer using the sample app configured with the following environment variables in Lambda environment:
EMF translated OTel metrics and OTel logs:
OTel log:
EMF log
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.