Skip to content
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

feat(metrics): support to set default dimension in EphemeralMetrics #2748

Merged

Conversation

leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented Jul 11, 2023

Issue number: #2676

Summary

Changes

This PR introduces the enhancement of the EphemeralMetrics class. You can now use the set_default_dimensions method or the default_dimensions parameter in the log_metrics decorator to persist dimensions across Lambda invocations.
If you'd like to remove them at some point, you can use clear_default_dimensions method.

User experience

Using log_metrics decorator

from aws_lambda_powertools.metrics import MetricUnit, EphemeralMetrics
from aws_lambda_powertools.utilities.typing import LambdaContext

ephemeral = EphemeralMetrics(namespace="POWERTOOLS")


@ephemeral.log_metrics(
    default_dimensions={'stage': 'prod'}
)
def lambda_handler(event: dict, context: LambdaContext):
    ephemeral.add_metric(name="OrderCount", unit=MetricUnit.Count, value=8)

Using set_default_dimensions

from aws_lambda_powertools.metrics import MetricUnit, EphemeralMetrics
from aws_lambda_powertools.utilities.typing import LambdaContext

ephemeral = EphemeralMetrics(namespace="POWERTOOLS")
ephemeral.set_default_dimensions(stage="prod")


@ephemeral.log_metrics
def lambda_handler(event: dict, context: LambdaContext):
    ephemeral.add_metric(name="OrderCount", unit=MetricUnit.Count, value=8)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team as a code owner July 11, 2023 14:49
@boring-cyborg boring-cyborg bot added commons documentation Improvements or additions to documentation metrics tests labels Jul 11, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 11, 2023
@github-actions github-actions bot added the feature New feature or functionality label Jul 11, 2023
@heitorlessa heitorlessa changed the title feat(metrics): adds default dimension support in EphemeralMetrics feat(metrics): support to set default dimension in EphemeralMetrics Jul 12, 2023
@heitorlessa heitorlessa changed the title feat(metrics): support to set default dimension in EphemeralMetrics feat(metrics): support to set default dimension in EphemeralMetrics Jul 12, 2023
@leandrodamascena leandrodamascena merged commit 62766e7 into aws-powertools:develop Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commons documentation Improvements or additions to documentation feature New feature or functionality metrics size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'EphemeralMetrics' object has no attribute 'set_default_dimensions'
2 participants