Skip to content

feat(metrics): allow change ColdStart function_name dimension #6315

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

Merged
merged 3 commits into from
Mar 20, 2025

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #6309

Summary

This PR adds the ability to configure a custom function name for metrics, which is especially useful when capturing cold start metrics. It provides more control over metrics naming, solving the issue where CDK deployments can result in random characters added to function names.

Changes

We adding in this PR:

  1. A new function_name parameter to the Metrics constructor
  2. Support for the POWERTOOLS_METRICS_FUNCTION_NAME environment variable
  3. A prioritized resolution mechanism for determining the function name:
    • Explicitly provided constructor parameter (highest priority)
    • Environment variable value (second priority)
    • Lambda context function name (lowest priority/fallback)

User experience

from aws_lambda_powertools import Metrics
from aws_lambda_powertools.utilities.typing import LambdaContext

metrics = Metrics(function_name="my-function-name")


@metrics.log_metrics(capture_cold_start_metric=True)
def lambda_handler(event: dict, context: LambdaContext): ...
   pass

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 March 20, 2025 16:08
@boring-cyborg boring-cyborg bot added commons documentation Improvements or additions to documentation metrics tests labels Mar 20, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 20, 2025
@leandrodamascena leandrodamascena self-assigned this Mar 20, 2025
@leandrodamascena leandrodamascena changed the title feat(metrics): allow change ColdStart function name metric feat(metrics): allow change ColdStart function name dimension Mar 20, 2025
@leandrodamascena leandrodamascena changed the title feat(metrics): allow change ColdStart function name dimension feat(metrics): allow change ColdStart function_name dimension Mar 20, 2025
@github-actions github-actions bot added feature New feature or functionality and removed documentation Improvements or additions to documentation labels Mar 20, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Mar 20, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Mar 20, 2025
Copy link

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.32%. Comparing base (6424f69) to head (1d92c81).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6315   +/-   ##
========================================
  Coverage    96.32%   96.32%           
========================================
  Files          242      242           
  Lines        11676    11689   +13     
  Branches       865      867    +2     
========================================
+ Hits         11247    11260   +13     
  Misses         336      336           
  Partials        93       93           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
Copy link
Contributor Author

@leandrodamascena leandrodamascena requested review from dreamorosi and removed request for anafalcao March 20, 2025 16:59
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice

@leandrodamascena leandrodamascena merged commit dee0fdc into develop Mar 20, 2025
19 checks passed
@leandrodamascena leandrodamascena deleted the feat/coldstart-function-name branch March 20, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commons feature New feature or functionality metrics size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: allow setting functionName via constructor parameter and environment variable
2 participants