You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importsoftware.amazon.lambda.powertools.metrics.Metrics;
// We expose the MetricsLogger interface from the EMF libraryimportsoftware.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
publicclassMetricsEnabledHandlerimplementsRequestHandler<Object, Object> {
MetricsLoggermetricsLogger = MetricsUtils.metricsLogger();
@Override@Metrics(namespace = "ExampleApplication", service = "booking")
publicObjecthandleRequest(Objectinput, Contextcontext) {
// User calls methods on software.amazon.cloudwatchlogs.emf.logger.MetricsLogger transitive dependencymetricsLogger.putDimensions(DimensionSet.of("environment", "prod"));
metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT);
}
}
This design is not optimal because it exposes the Metrics utility directly to breaking changes in this transitive dependency. This impacts the extensibility and interface design flexibility of the Metrics utility negatively:
Breaking changes in the EMF dependency will directly impact customers and require major version bumps of the Metrics utility in Powertools
Direct coupling with the EMF dependency only allows exposing metrics in EMF and hinders adoption of new Metrics backends
Such an interface will abstract away the direct dependency on the EMF library and will allow us to add new backends or to replace the EMF backend with our own implementation in the future.
Example interface in Java:
packagecom.amazonaws.lambda.powertools.metrics;
importjava.util.Map;
importcom.amazonaws.services.lambda.runtime.Context;
publicinterfaceMetrics {
// MetricUnit, MetricResolution and other data classes need to be implement manuallyvoidaddMetric(Stringkey, doublevalue, MetricUnitunit, MetricResolutionresolution);
defaultvoidaddMetric(Stringkey, doublevalue, MetricUnitunit) {
addMetric(key, value, unit, MetricResolution.DEFAULT);
}
defaultvoidaddMetric(Stringkey, doublevalue) {
addMetric(key, value, MetricUnit.NONE, MetricResolution.DEFAULT);
}
voidaddDimension(Stringkey, Stringvalue);
voidaddMetadata(Stringkey, Objectvalue);
voidsetDefaultDimensions(Map<String, String> defaultDimensions);
voidsetNamespace(Stringnamespace);
voidsetService(Stringservice);
voidsetRaiseOnEmptyMetrics(booleanraiseOnEmptyMetrics);
voidsetCaptureColdStart(booleancaptureColdStart);
voidsetFunctionName(StringfunctionName);
voidclearDefaultDimensions();
voidflush();
voidcaptureColdStartMetric(Contextcontext);
}
Why is this needed?
Today, we are exposing the whole interface of the https://github.com/awslabs/aws-embedded-metrics-java library that we use in the Metrics utility for logging CloudWatch EMF metrics. Example:
This design is not optimal because it exposes the Metrics utility directly to breaking changes in this transitive dependency. This impacts the extensibility and interface design flexibility of the Metrics utility negatively:
Which area does this relate to?
Metrics Utility tech debt
Suggestion
This issue suggests to add a Metrics interface similar to the other Powertools for AWS runtimes. For example, the same as .NET is doing: https://github.com/aws-powertools/powertools-lambda-dotnet/blob/develop/libraries/src/AWS.Lambda.Powertools.Metrics/IMetrics.cs.
Such an interface will abstract away the direct dependency on the EMF library and will allow us to add new backends or to replace the EMF backend with our own implementation in the future.
Example interface in Java:
Acknowledgment
The text was updated successfully, but these errors were encountered: