aws-otel-java-instrumentation icon indicating copy to clipboard operation
aws-otel-java-instrumentation copied to clipboard

Configure `EMF` and `CompactLog` Exporters for Lambda Environment

Open liustve opened this issue 1 month ago • 0 comments
trafficstars

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: console required

To enable the Console EMF exporter, users must set the following environment variables in their Lambda:

  • OTEL_METRICS_EXPORTER: awsemf required
  • OTEL_EXPORTER_OTLP_LOGS_HEADERS: x-aws-log-group=your-log-group,x-aws-log-stream=your-log-stream,x-aws-metric-namespace optional

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: image

EMF translated OTel metrics and OTel logs: OTel log: image EMF log image

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

liustve avatar Sep 26 '25 23:09 liustve