You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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?
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 byMetricsLogger.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.The text was updated successfully, but these errors were encountered: