-
Notifications
You must be signed in to change notification settings - Fork 37
Support Clearing Custom Dimensions on MetricsLogger #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm facing a similar issue, the dimensions are retained but the metrics are reset. |
We are facing a similar issue like this. We want to reset statically created MetricsLogger for each Lambda request. We don't want to force instantiate MetricsLogger for each request. Please provide any ETA on this. |
Hi there, We recently ran into this issue as well. We have use-case where we are setting dimensions & emitting metrics based on the contents of a message we receive, which can vary. We've worked around this by instantiating a new logger instance when we need to change the dimensions, but this isn't ideal. Is there a plan to fix this behavior? |
This looks like an easy fix assuming the README/docs are correct and this is truly a bug and not by design. If this is intentional there needs to be another way to clear dimensions as there's no possible way of doing so without having the consumer control for dimensions manually. Also the docs should get updated if this is the case. |
As per README,
MetricsLogger.flush()
shouldFlushes the current MetricsContext to the configured sink and resets all properties, dimensions and metric values. The namespace and default dimensions will be preserved across flushes.
In fact, the dimensions and properties on the metricsLogger are retained after flushing.
This unit test illustrates the behavior:
Spoke with yaozhaoy about this today, and he said this is actually the desired behavior since metrics Dimension should be preserved across calls to flush for customer convenience. He said he'll update the README accordingly.
My use case is the following: I have a single lambda fronted by several invocation paths from an API gateway. I want a dimension that indicates the invoking path, since the path changes my lambda behavior. There's currently no way to do this with a single metricsLogger since if I were to reset the dimensions, I lose the defaultDimensions (see
aws-embedded-metrics-java/src/main/java/software/amazon/cloudwatchlogs/emf/model/MetricDirective.java
Line 71 in 6c10ae0
Since I'm overwriting the dimension with the same key, my CloudWatch metrics actually do come out fine. However, CloudWatch Insights get clobbered with duplicates of each Dimension. Excerpt (ServiceType being my custom dimension):
The way I'm currently solving this is to force instantiation of a new MetricsLogger for each request to my lambda.
Feature Request: Be able to reset the MetricsLogger for each new request so that I can support different dimensions (and properties etc) from the same logger instance.
The text was updated successfully, but these errors were encountered: