Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Provide timestamp per metric not per metrics set #166

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

Closed
Dunedan opened this issue Sep 17, 2020 · 2 comments
Closed

Provide timestamp per metric not per metrics set #166

Dunedan opened this issue Sep 17, 2020 · 2 comments
Labels
feature-request feature request

Comments

@Dunedan
Copy link
Contributor

Dunedan commented Sep 17, 2020

Currently powertools doesn't track when a metric got added and uses the time of flushing as timestamp in the EMF metadata. This causes inaccurate time information when the function annotated with log_metrics runs longer than the minimal resolution for metrics in CloudWatch Metrics.

Here is sample code to reproduce this problem:

#!/usr/bin/env python3

import json
import time

from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit

metrics = Metrics(namespace="Test", service="Test")

@metrics.log_metrics
def handler(event, context):
    metrics.add_metric(name="TestMetric1", unit=MetricUnit.Count, value=1)
    time.sleep(65)
    metrics.add_metric(name="TestMetric2", unit=MetricUnit.Count, value=1)

handler(None, None)

This code produces the following output:

{
    "_aws": {
        "Timestamp": 1600326158339,
        "CloudWatchMetrics": [
            {
                "Namespace": "Test",
                "Dimensions": [
                    [
                        "service"
                    ]
                ],
                "Metrics": [
                    {
                        "Name": "TestMetric1",
                        "Unit": "Count"
                    },
                    {
                        "Name": "TestMetric2",
                        "Unit": "Count"
                    }
                ]
            }
        ]
    },
    "service": "Test",
    "TestMetric1": 1.0,
    "TestMetric2": 1.0
}

Instead of a single log record with a single timestamp, I'd expect to get two distinct log records with timestamps 65 seconds apart.

I also already reported the same problem for aws-embedded-metrics-python: awslabs/aws-embedded-metrics-python#53

@Dunedan Dunedan added bug Something isn't working triage Pending triage from maintainers labels Sep 17, 2020
@heitorlessa
Copy link
Contributor

heitorlessa commented Sep 17, 2020 via email

@Dunedan
Copy link
Contributor Author

Dunedan commented Sep 17, 2020

The records I expected to be written were based on the current EMF specification. I wasn't aware that changes to the EMF specification are a possibility as well and I agree, extending the specification might be a better solution. 👍

@heitorlessa heitorlessa added area/metrics feature-request feature request and removed bug Something isn't working triage Pending triage from maintainers labels Sep 18, 2020
@heitorlessa heitorlessa changed the title Metric timestamps not accurate Provide timestamp per metric not per metrics set Mar 6, 2021
@aws-powertools aws-powertools locked and limited conversation to collaborators Mar 12, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
feature-request feature request
Projects
Development

No branches or pull requests

2 participants