Skip to content

Support publishing Metrics with no dimensions #37

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
kasikaruppiah opened this issue Sep 2, 2020 · 1 comment
Closed

Support publishing Metrics with no dimensions #37

kasikaruppiah opened this issue Sep 2, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@kasikaruppiah
Copy link

configureContextForEnvironment sets LogGroup, ServiceName and ServiceType as defaultDimension when none is set

Code to reproduce the issue

final var metricsLogger = new MetricsLogger();
metricsLogger.putMetric("ErrorMetric", 0, Unit.NONE);
metricsLogger.flush();

Generated Log

{
    "_aws": {
        "Timestamp": 1599079576076,
        "CloudWatchMetrics": [
            {
                "Namespace": "Dummy",
                "Metrics": [
                    {
                        "Name": "ErrorMetric",
                        "Unit": "None"
                    }
                ],
                "Dimensions": [
                    [
                        "LogGroup",
                        "ServiceName",
                        "ServiceType"
                    ]
                ]
            }
        ]
    },
    "traceId": "Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1",
    "functionVersion": "$LATEST",
    "LogGroup": "test",
    "ServiceName": "test",
    "ServiceType": "AWS::Lambda::Function",
    "logStreamId": "2020/09/02/[$LATEST]fe81001002b19bc93650b6779072f274",
    "ErrorMetric": 0.0,
    "executionEnvironment": "AWS_Lambda_java11"
}

Ended up using metricsLogger.setDimensions(); to remove the defaultDimensions as a workaround.

{
    "_aws": {
        "Timestamp": 1599085078153,
        "CloudWatchMetrics": [
            {
                "Namespace": "Dummy",
                "Metrics": [
                    {
                        "Name": "ErrorMetric",
                        "Unit": "None"
                    }
                ],
                "Dimensions": []
            }
        ]
    },
    "traceId": "Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1",
    "logStreamId": "2020/09/02/[$LATEST]174dbe23d48fa649561c2941f408b34e",
    "ErrorMetric": 0.0,
    "functionVersion": "$LATEST",
    "executionEnvironment": "AWS_Lambda_java11"
}

The Embedded Metric Format schema supports metrics with no dimensions. Can we update the lib to get this fixed?

@yaozhaoy
Copy link
Contributor

The current way to publish metrics with no dimensions is to call

logger.setDimensions()

There would be no dimensions carried over to subsequent flushes. You only need to call the setDimensions once for each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants