Class EmfMetricLoggingPublisher
- All Implemented Interfaces:
AutoCloseable
,MetricPublisher
,SdkAutoCloseable
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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
void
close()
Closes this metric publisher.void
publish
(MetricCollection metricCollection) Notify the publisher of new metric data.
-
Method Details
-
builder
-
publish
Description copied from interface:MetricPublisher
Notify the publisher of new metric data. After this call returns, the caller can safely discard the givenmetricCollection
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 interfaceMetricPublisher
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceMetricPublisher
- Specified by:
close
in interfaceSdkAutoCloseable
-