Skip to content

Example of multiple dimension data #338

Closed

Description

@btorretta

What were you initially searching for in the docs?
I was looking for an example of writing metrics that are organized beyond name space and service.

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

Activity

  1. heitorlessa commented on Mar 15, 2021

    @heitorlessa
    Contributor

    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

    from 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 function

    from 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 function

    from 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 ProductAdded, first 5, then 10. While you can add multiple values to a given metric, you cannot have a dimension with multiple values.

    product-service Lambda function with multiple values

    from 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)
  2. locked and limited conversation to collaborators on Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationneed-more-informationPending information to continue

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions