Skip to content

single_metric() to inherit default dimensions #1859

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
2 tasks done
prudnikov opened this issue Jan 25, 2023 · 7 comments · Fixed by #1880
Closed
2 tasks done

single_metric() to inherit default dimensions #1859

prudnikov opened this issue Jan 25, 2023 · 7 comments · Fixed by #1880
Assignees
Labels

Comments

@prudnikov
Copy link
Contributor

Use case

At the root level I define default metric which is environment name in my case.

metrics = Metrics()
metrics.set_default_dimensions(Environment=ENVIRONMENT)

This is all fine and Environment gets propagated to all metrics. However, when single_metric() is used this default dimension is ignored. This is what I do to overcome that.

metrics = Metrics()

with single_metric(
    name="Metric1", unit=MetricUnit.Milliseconds, value=elapsed_ms
) as this_metric:
    this_metric.add_dimension(name="TableName", value=self.table_name)


    for name, value in metrics.default_dimensions.items():
        this_metric.add_dimension(name=name, value=value)

or it should be possible with this_metric.default_dimensions = metrics.default_dimensions, I did not tried this.

This way all the default dimensions are propagated with a single metric.

Solution/User Experience

When creating a SingleMetric with single_metric context manager default dimensions should be copied to a SingleMetric instance.

I can imagine the situation when you don't want to propagate default dimensions to the SingleMetric.

To keep existing usage untouched I suppose the default behavior should be to not propagate default dimensions. So the solution can be the additional keyword argument inherit_default_dimensions: bool = False

with single_metric("Name", MetricUnit.Count, 1, inherit_default_dimensions=True) as this_metric:
    this_metric.add_dimension(name="Dim1", value="Val")

Alternative solutions

No response

Acknowledgment

@prudnikov prudnikov added feature-request feature request triage Pending triage from maintainers labels Jan 25, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 25, 2023

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

@prudnikov
Copy link
Contributor Author

I'll be happy to contribute to this feature.

@rubenfonseca
Copy link
Contributor

Hi @prudnikov thank you so much for opening this issue, it's very well written and very clear! We would be happy to merge your contribution and this feature. Kudos!

@rubenfonseca rubenfonseca added metrics and removed triage Pending triage from maintainers labels Jan 25, 2023
@rubenfonseca
Copy link
Contributor

Hi @prudnikov do you have the time to submit a PR for this issue? We would love to review it and merge it :)

@prudnikov
Copy link
Contributor Author

@rubenfonseca I'll try to finish this today.
By they way, this will require extracting of SingleMetric and single_metric to a separate module. I'll create single_metric.py and move them to this module. Otherwise there is a circular import. I need to use Metrics inside the single_metric

@prudnikov
Copy link
Contributor Author

I just created a PR, I changed design a little bit, my motivation for that is described in the PR.

@rubenfonseca rubenfonseca linked a pull request Feb 1, 2023 that will close this issue
7 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2023

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants