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 exposes requestHandler 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 extends RequestHandlerWithProfiling, override handleRequest calling super.handleRequest and annotating it with the powertools annotations. Then implementing my concrete handlers as subclasses of BaseHandler
-
Metrics emitted by MetricsUtils.metricsLogger should have a property for the requestId
- The Metric EMF entity emitted does not contain a property for the
requestId. It has other useful things like traceId
- I think the LambdaMetricsAspect can be updated to add a
requestId property by default
-
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 and Service; that's unnecessary, I believe one to be coming from the EMF Library and the other from Powertools
- 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 Powertools MetricsUtils.metricsLogger() as it fails validation if dimensions count is equal to 0
-
MetricsUtils.withSingleMetric should have improved properties and namespace configs
withSingleMetric 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 for MetricsUtils.metricsLogger
withSingleMetric should also add the requestId 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 the MetricsUtils.metricsLogger, but gets applied to the equivalent of withSingleMetrics 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.
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
handlerRequesthandleRequestand instead exposesrequestHandlermethod that users should override to add their logicBaseHandlerthat extendsRequestHandlerWithProfiling, overridehandleRequestcallingsuper.handleRequestand annotating it with the powertools annotations. Then implementing my concrete handlers as subclasses ofBaseHandlerMetrics emitted by
MetricsUtils.metricsLoggershould have a property for therequestIdrequestId. It has other useful things liketraceIdrequestIdproperty by defaultMetrics emitted by
MetricsUtils.metricsLoggershould allow dimensions to be overriden or unset"Dimensions":[["LogGroup","ServiceName","ServiceType","Service"]].ServiceNameandService; that's unnecessary, I believe one to be coming from the EMF Library and the other from PowertoolssetDimensions()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 0MetricsUtils.withSingleMetricshould have improved properties and namespace configswithSingleMetricrequires 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.metricsLoggerwithSingleMetricshould also add therequestIdpropertyMetricsUtils. 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.defaultPropertiesthat we can append to at any time. It adds to theMetricsUtils.metricsLogger, but gets applied to the equivalent ofwithSingleMetricswhen 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.