Skip to content

'EphemeralMetrics' object has no attribute 'set_default_dimensions' #2676

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

Closed
tibbe opened this issue Jul 5, 2023 · 5 comments · Fixed by #2748
Closed

'EphemeralMetrics' object has no attribute 'set_default_dimensions' #2676

tibbe opened this issue Jul 5, 2023 · 5 comments · Fixed by #2748

Comments

@tibbe
Copy link
Contributor

tibbe commented Jul 5, 2023

Expected Behaviour

log_metrics() with default_dimensions should also work for EphemeralMetrics.

Current Behaviour

Since EphemeralMetrics has no set_default_dimensions method it fails with the error in the issue title.

Code snippet

@my_metrics.log_metrics(
    default_dimensions={'Stage': 'prod'}
):
def handler(event, context):
   pass:

Possible Solution

EphemeralMetrics should have most of the methods that Metrics has (in particular those related to default dimensions), as these method are orthogonal to the non-singletoness of EphemeralMetrics.

Steps to Reproduce

Run a Lambda with the code snippet above.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

PyPi

Debugging logs

No response

@tibbe tibbe added bug Something isn't working triage Pending triage from maintainers labels Jul 5, 2023
@heitorlessa
Copy link
Contributor

heitorlessa commented Jul 5, 2023

hey @tibbe great to hear from you again - we intentionally did that .

If you have an use case to persist dimensions across invocations within ephemeral metrics, happy to convert this to a feature request -- if you have the bandwidth to make a PR we can prioritize it for the next release :)

image

@heitorlessa heitorlessa added metrics and removed bug Something isn't working triage Pending triage from maintainers labels Jul 5, 2023
@heitorlessa heitorlessa moved this from Triage to Pending customer in Powertools for AWS Lambda (Python) Jul 5, 2023
@heitorlessa heitorlessa self-assigned this Jul 5, 2023
@heitorlessa
Copy link
Contributor

Asked on Discord to bring more visibility: https://discord.com/channels/1006478942305263677/1006527338621710376/1127918302686097438

In hindsight, I'm starting to think this makes sense. We'd need to signal in the docs that EphemeralMetrics instances will not share a default dimension since it's completely isolated.

I'll wait for a signal from you or another customer before proceeding.

Thanks!

@heitorlessa heitorlessa moved this from Pending customer to Working on it in Powertools for AWS Lambda (Python) Jul 10, 2023
@heitorlessa
Copy link
Contributor

Confirmed use case on Discord, will get this ready for the next release.


from OP

I have a Lambda that consumes a DynamoDB stream and receives a batch of items from DynamoDB in each invocation. I have three metrics that have a dimension that is the same across the batch (the "Stage" e.g. "prod" or "development") and a dimension that varies across the batch (the "ItemType" e.g. "user" or "chat"). The former dimension would be convenient to set as a default dimension. I could of course just set it directly after the invocation starts, which is what I did as a workaround.

The dimension that varies across the batch is a bit trickier, as I can't re-set a dimension (all metrics would simply get the value of the last call to set_dimension). I ended up using a dict of EphemeralMetrics to handle this.

At the end of the day I'm just trying to use Lambda metrics in the way that's most efficient. The ideal API is actually just to emit the dimensions with the metric (i.e. just as a SingleMetric or really just a call to a hypothetical emit_metric(*dimensions, name, unit)). What we're doing here is in my mind just a workaround for what the Lambda logging schema supports efficiently.

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jul 12, 2023
@github-actions
Copy link
Contributor

This is now released under 2.20.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jul 14, 2023
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Shipped
2 participants