Description
Is your feature request related to a problem? Please describe.
The following requests are based on a recent experience I had using Powerttools Metrics having used https://github.com/awslabs/aws-embedded-metrics-java in different projects before and the workarounds we had to implement and hoping they should be taken care of by Powertools so we can move our older projects to Powertools and have a consistent experience among the different projects.
As such, I'll mention a few points below
Describe the solution you'd like
-
Improve documentation/warnings about the fact that powertools annotations require the Lambda handler method to be called
handlerRequest
- I use CloudGuru Profiler with the setup described in https://docs.aws.amazon.com/codeguru/latest/profiler-ug/lambda-custom.html. This implementation overrides/hides
handleRequest
and instead exposesrequestHandler
method that users should override to add their logic - It took me a lot of time debugging/investigating this; time that could've been saved if there was better documentation or warnings about where the annotations are.
- My workaround was to create a new
BaseHandler
that extendsRequestHandlerWithProfiling
, overridehandleRequest
callingsuper.handleRequest
and annotating it with the powertools annotations. Then implementing my concrete handlers as subclasses ofBaseHandler
- I use CloudGuru Profiler with the setup described in https://docs.aws.amazon.com/codeguru/latest/profiler-ug/lambda-custom.html. This implementation overrides/hides
-
Metrics emitted by
MetricsUtils.metricsLogger
should have a property for therequestId
- The Metric EMF entity emitted does not contain a property for the
requestId
. It has other useful things liketraceId
- I think the LambdaMetricsAspect can be updated to add a
requestId
property by default
- The Metric EMF entity emitted does not contain a property for the
-
Metrics emitted by
MetricsUtils.metricsLogger
should allow dimensions to be overriden or unset- By default, they get the following dimensions
"Dimensions":[["LogGroup","ServiceName","ServiceType","Service"]]
. - For
ServiceName
andService
; that's unnecessary, I believe one to be coming from the EMF Library and the other from Powertools- https://github.com/awslabs/aws-embedded-metrics-java/blob/master/src/main/java/software/amazon/cloudwatchlogs/emf/logger/MetricsLogger.java#L174
- https://github.com/awslabs/aws-lambda-powertools-java/blob/master/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspect.java#L51
- We in our existing setups with EMF, we don't find value in any of those default dimensions. We're simply able to override them using
setDimensions()
and giving it zero arguments if we don't need any of the default dimensions. Unfortunately this cannot be done for PowertoolsMetricsUtils.metricsLogger()
as it fails validation if dimensions count is equal to 0
- By default, they get the following dimensions
-
MetricsUtils.withSingleMetric
should have improved properties and namespace configswithSingleMetric
requires the setting of a namespace. In most cases, one would want to use the default namespace which is not easily accessible (beyond grabbing it explicitly from the environment variables). I believe there should be a version of this method which simply reuses the namespace configured forMetricsUtils.metricsLogger
withSingleMetric
should also add therequestId
property- In our projects that use EMF, we have an abstraction similar to
MetricsUtils
. It provides the same general capabilities - a default metricsLogger that gets flushed at the end of a request + one off metrics. The one thing we have on top of that is that we're able to set some default properties that will be written to both types of metrics e.g.defaultProperties
that we can append to at any time. It adds to theMetricsUtils.metricsLogger
, but gets applied to the equivalent ofwithSingleMetrics
when they're instantiated. This allows us to have a consistent set of properties common across all our EMF metrics.
Additional context
It's likely that each of topics above should be addressed in a different issue and I'm happy to break it down further if you think that's useful.
I'm also happy to attempt to contribute after discussions if needed.