Example of multiple dimension data #351
-
What were you initially searching for in the docs? Is this related to an existing part of the documentation? Please share a link Describe how we could make it clearer The visual seems to imply that I can write multiple metric values under multiple services but I don't see a clear code example of that. If you have a proposed update, please share it here |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @btorretta, thanks for raising it so we can improve our docs. Could you give me a concrete example of what you're trying to achieve? If I understood what you're after correctly, that visual can be represented in the following code. This demonstrates that every function function emit distinct metrics to the same namespace allowing them to group all metrics to a given application composed of multiple services. They use a different service name to easily filter metrics out, so you'd know metric X was emitted by service Y. shoppingcart-service Lambda functionfrom aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics(namespace="e-commerce-app", service="shoppingcart-service")
metrics.add_metric(name="CartUpdated", unit=MetricUnit.Count, value=10)
metrics.add_metric(name="CartCheckedOut", unit=MetricUnit.Count, value=1) product-service Lambda functionfrom aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics(namespace="e-commerce-app", service="product-service")
metrics.add_metric(name="ProductAdded", unit=MetricUnit.Count, value=5)
metrics.add_metric(name="ProductRemoved", unit=MetricUnit.Count, value=1) delivery-service Lambda functionfrom aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics(namespace="e-commerce-app", service="delivery-service")
metrics.add_metric(name="DeliverySuccess", unit=MetricUnit.Count, value=10)
metrics.add_metric(name="DeliveryTime", unit=MetricUnit.Seconds, value=60) In this example, we add multiple values to the metric product-service Lambda function with multiple valuesfrom aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics(namespace="e-commerce-app", service="product-service")
metrics.add_metric(name="ProductAdded", unit=MetricUnit.Count, value=5)
# Additional value to the same metric
metrics.add_metric(name="ProductAdded", unit=MetricUnit.Count, value=10)
|
Beta Was this translation helpful? Give feedback.
Hi @btorretta, thanks for raising it so we can improve our docs. Could you give me a concrete example of what you're trying to achieve?
If I understood what you're after correctly, that visual can be represented in the following code. This demonstrates that every function function emit distinct metrics to the same namespace allowing them to group all metrics to a given application composed of multiple services. They use a different service name to easily filter metrics out, so you'd know metric X was emitted by service Y.
shoppingcart-service Lambda function