Skip to content

[Metrics] Improvements to Powertools Metrics #297

Closed
@humanzz

Description

@humanzz

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

  1. 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
  2. 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
  3. Metrics emitted by MetricsUtils.metricsLogger should allow dimensions to be overriden or unset

  4. 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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions