Interface PropertiesFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface @SdkPublicApi public interface PropertiesFactory
A factory for producing custom properties to include in each EMF record.

Implementations receive the MetricCollection being published, allowing properties to be derived from the SDK metrics (e.g. service endpoint, request ID) or from ambient context (e.g. Lambda request ID, trace ID).

The returned map entries are written as top-level key-value pairs in the EMF JSON output, making them searchable in CloudWatch Logs Insights. Keys that collide with reserved EMF fields (_aws), dimension names, or metric names are silently skipped.

If the factory returns null or throws an exception, no custom properties are added and a warning is logged.

Example using ambient context:


 EmfMetricLoggingPublisher.builder()
     .propertiesFactory(metrics -> Collections.singletonMap("RequestId", requestId))
     .build();
 

Example using metric collection values:


 EmfMetricLoggingPublisher.builder()
     .propertiesFactory(metrics -> {
         Map<String, String> props = new HashMap<>();
         metrics.metricValues(CoreMetric.SERVICE_ENDPOINT)
                .stream().findFirst()
                .ifPresent(uri -> props.put("ServiceEndpoint", uri.toString()));
         return props;
     })
     .build();
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    create(MetricCollection metricCollection)
    Create a map of custom properties to include in the EMF record for the given metric collection.
  • Method Details

    • create

      Map<String,String> create(MetricCollection metricCollection)
      Create a map of custom properties to include in the EMF record for the given metric collection.
      Parameters:
      metricCollection - the SDK metric collection being published
      Returns:
      a map of property names to string values, or null for no custom properties