Class EmfMetricLoggingPublisher

java.lang.Object
software.amazon.awssdk.metrics.publishers.emf.EmfMetricLoggingPublisher
All Implemented Interfaces:
AutoCloseable, MetricPublisher, SdkAutoCloseable

@ThreadSafe @Immutable public final class EmfMetricLoggingPublisher extends Object implements MetricPublisher
A metric publisher implementation that converts metrics into CloudWatch Embedded Metric Format (EMF). EMF allows metrics to be published through CloudWatch Logs using a structured JSON format, which CloudWatch automatically extracts and processes into metrics.

This publisher is particularly well-suited for serverless environments like AWS Lambda and container environments like Amazon ECS that have built-in integration with CloudWatch Logs. Using EMF eliminates the need for separate metric publishing infrastructure as metrics are automatically extracted from log entries.

The EMF publisher converts metric collections into JSON-formatted log entries that conform to the CloudWatch EMF specification. The logGroupName field is required for EMF to work. CloudWatch automatically processes these logs to generate corresponding metrics that can be used for monitoring and alerting.

  • Method Details

    • builder

      public static EmfMetricLoggingPublisher.Builder builder()
    • publish

      public void publish(MetricCollection metricCollection)
      Description copied from interface: MetricPublisher
      Notify the publisher of new metric data. After this call returns, the caller can safely discard the given metricCollection instance if it no longer needs it. Implementations are strongly encouraged to complete any further aggregation and publishing of metrics in an asynchronous manner to avoid blocking the calling thread.

      With the exception of a null metricCollection, all invocations of this method must return normally. This is to ensure that callers of the publisher can safely assume that even in situations where an error happens during publishing that it will not interrupt the calling thread.

      Specified by:
      publish in interface MetricPublisher
      Parameters:
      metricCollection - The collection of metrics.
    • close

      public void close()
      Closes this metric publisher. This implementation is empty as the EMF metric logging publisher does not maintain any resources that require explicit cleanup.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface MetricPublisher
      Specified by:
      close in interface SdkAutoCloseable