Skip to content

flush() doesn't clear properties #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

Open
benkehoe opened this issue May 30, 2020 · 2 comments
Open

flush() doesn't clear properties #35

benkehoe opened this issue May 30, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@benkehoe
Copy link
Contributor

According the README, flush() "[f]lushes 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."

However, in MetricContext.create_copy_with_context(), which is used by MetricsLogger.flush() to reset the context, copies the old properties. This means in my Lambda function, if I have conditional properties in my logging object, once I've set one in one invocation, it remains present in the context in future invocations.

@benkehoe
Copy link
Contributor Author

I'm currently working around this by called metrics.context.properties.clear() at the beginning of my handler. I'd be up for contributing a fix. My preference would be to change the signature to MetricContext.create_copy_with_context(copy_properties=True) to preserve its default behavior, and change MetricsLogger.flush() to set this to false to make its behavior match the spec. Let me know if this would be acceptable.

@jaredcnance jaredcnance added enhancement New feature or request documentation Improvements or additions to documentation labels Jun 1, 2020
@rstevens011
Copy link

rstevens011 commented May 2, 2024

I had a case where in the lambda handler with a property set inside a for loop, only a single EMF string would be printed to the log group with only the last iteration printed to the log stream. A simple example:

@metric_scope
def lambda_handler(event, context, metrics):
    foo = [ "bar", "bars"]
    for idx, x in enumerate(foo):
        metrics.set_property("property_name", x)
        metrics.put_metric("metric_name", float(idx))

This would result in a log stream entry with property_name being set to bars. I feel like this is a similar problem to the OP's and could be the same root cause. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants