Skip to content

Bug: Metric.add_dimension doesn't aggregate #1579

Closed

Description

@cfchou

Expected Behaviour

https://awslabs.github.io/aws-lambda-powertools-python/latest/core/metrics/#getting-started

Tip
You can initialize Metrics in any other module too. It'll keep track of your aggregate metrics in memory to optimize costs (one blob instead of multiples).

I may be wrong but I think this behavior should also apply to add_dimension. I expect to be able to add_dimension or add_metrics to any Metrics instance. When serializing any one of the instances, an EMF blob is created and it has all metrics and dimensions.

Current Behaviour

When serializing a Metrics instance, dimensions added to other instances do not appear.

Code snippet

def test_metrics_reuse_dimension_set(metric, dimension, namespace):
    # GIVEN Metrics is initialized
    my_metrics = Metrics(namespace=namespace)
    my_metrics.add_dimension(**dimension)
    my_metrics.add_metric(**metric)

    # WHEN Metrics is initialized one more time
    my_metrics_2 = Metrics(namespace=namespace)

    # THEN Both class instances should have the same dimension set
    assert my_metrics_2.dimension_set == my_metrics.dimension_set


### Possible Solution

_No response_

### Steps to Reproduce

1. Create two `Metrics` instances
2. Pick one to add_metric and add_dimension
3. Serialize another one

### AWS Lambda Powertools for Python version

latest

### AWS Lambda function runtime

3.8

### Packaging format used

PyPi

### Debugging logs

_No response_

Activity

  1. added
    bug
    triage
    on Oct 10, 2022
  2. boring-cyborg commented on Oct 10, 2022

    @boring-cyborg

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out the #python channel on our AWS Lambda Powertools Discord: Invite link

  3. heitorlessa commented on Oct 10, 2022

    @heitorlessa
    Contributor

    Thank you @cfchou for raising this - this is a bug. Investigating and once we have a fix we'll make a patch release ASAP

  4. removed
    triage
    on Oct 10, 2022
  5. self-assigned this
    on Oct 10, 2022
  6. heitorlessa commented on Oct 10, 2022

    @heitorlessa
    Contributor

    Got a fix (thanks to your quick tests too!). Triple checking if I haven't missed anything else before we make a release

  7. github-actions commented on Oct 10, 2022

    @github-actions
    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.

  8. added
    pending-release
    on Oct 10, 2022
  9. heitorlessa commented on Oct 10, 2022

    @heitorlessa
    Contributor

    Making a patch release and will share more info soon.

  10. github-actions commented on Oct 10, 2022

    @github-actions
    Contributor

    This is now released under 1.31.0 version!

  11. removed
    pending-release
    on Oct 10, 2022
  12. heitorlessa commented on Oct 10, 2022

    @heitorlessa
    Contributor

    Publishing Lambda Layer across 22 AWS regions, should be live in ~10m. Will post here when done.

  13. heitorlessa commented on Oct 10, 2022

    @heitorlessa
    Contributor

    Lambda Layer deployment complete - new version is 38 across all regions.

    e.g., arn:aws:lambda:eu-west-1:017000801446:layer:AWSLambdaPowertoolsPython:38.

    Please let us know if this somehow doesn't solve your end @cfchou. Thank you one more time for this great bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions