-
Notifications
You must be signed in to change notification settings - Fork 421
Feature request: Remove 'service' dimension from single_metric() #3917
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
Comments
Hello @nikevp! Thanks for opening this issue! I'd like to hear from other maintainers what they think about this, as disabling For now, if this is a mandatory requirement and is harming your production environment I might suggest you set the public Something like this: import os
from aws_lambda_powertools import single_metric
from aws_lambda_powertools.metrics import MetricUnit
from aws_lambda_powertools.utilities.typing import LambdaContext
STAGE = os.getenv("STAGE", "dev")
def lambda_handler(event: dict, context: LambdaContext):
with single_metric(name="MySingleMetric", unit=MetricUnit.Count, value=1, namespace="TEST") as metric:
metric.add_dimension(name="environment", value=STAGE)
metric.add_dimension(name="xyz", value="123")
metric.service = None Thanks |
Agree with @leandrodamascena comments. At most, we could add a service kwarg to the |
I agree with @rubenfonseca – I think using @leandrodamascena's code snippet, you could wrap it in a function to ensure that you get what you want without having context managers everywhere in your code |
Thanks for the quick reply @leandrodamascena. Your example works perfectly for my use case and I'm already using a singleton function for the logic. I was running into issues Friday trying to pass
Since you can easily remove the dimension before emitting, I no longer see any need for a code change. However, it might be worth noting in the logger documentation that adding $POWERTOOLS_SERVICE_NAME will automatically add a dimension to all metrics. This might be a rare edge case, but could negatively impact existing alarm coverage. |
Hi @nikevp! Thank you for the feedback! I'm pleased to hear that you were able to resolve the issue. https://docs.powertools.aws.dev/lambda/python/latest/core/metrics/#getting-started Thank you. |
Hey @leandrodamascena, I agree the metric ENV documentation is clear. On my side, I overlooked the implications of adding POWERTOOLS_SERVICE_NAME to the logger without considering the impact on metrics. Here it does not indicate adding POWERTOOLS_SERVICE_NAME will impact metrics: https://docs.powertools.aws.dev/lambda/python/latest/core/logger/#getting-started It's easy to catch in development by reviewing the logs, but only if you are setting up Metrics after Logger. If you setup the Metrics feature and later on add the Logger, a user might add POWERTOOLS_SERVICE_NAME without knowing it changes dimensions. This might not be a common migration pattern so I'm okay with the current documentation. If you think it's worth revising to clarify the dependency, you might do something like: There are some other environment variables which can be set to modify Logger's settings at a global scope. The POWERTOOLS_SERVICE_NAME environment variable is shared with other features and adds a default service dimension to Metrics. |
|
Use case
My team has a specific metric format used across lambda runtimes with the following dimensions: [Operation, Function]. I would like to use
single_metric
without 'service' added as a third dimension.I would remove POWERTOOLS_SERVICE_NAME, but we also leverage the powertools Logger.
Solution/User Experience
The ability to exclude 'service' as a dimension from
single_metric
calls.Alternative solutions
Acknowledgment
The text was updated successfully, but these errors were encountered: