Skip to content
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

Feature request: TypeScript: Log Metrics with JSON (not console.log) #1766

Closed
1 of 2 tasks
cortexcompiler opened this issue Oct 25, 2023 · 4 comments · Fixed by #1786
Closed
1 of 2 tasks

Feature request: TypeScript: Log Metrics with JSON (not console.log) #1766

cortexcompiler opened this issue Oct 25, 2023 · 4 comments · Fixed by #1786
Assignees
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility metrics This item relates to the Metrics Utility

Comments

@cortexcompiler
Copy link

Use case

We would like our Metrics to be logged in pure JSON to match the EMF document structure for addMetric() and the logMetrics() middleware. This will allow the logs to be machine readable and ingested by aggregators. Instead we are seeing the EMF JSON prefixed with the timestamp, request Id, and log level, because the code uses console.log()

We use the Powertools for AWS Lambda (TypeScript) Metrics and Powertools for AWS Lambda (TypeScript) Logger. The Logger works fine because it uses its own console instance.

This is an example of one of the log events from CloudWatch:

2023-10-25T17:38:05.273Z	274cced9-0439-4a76-befe-eeef0ec34460	INFO	
{
    "_aws": {
        "Timestamp": 1698255485273,
        "CloudWatchMetrics": [
            {
                "Namespace": "xxxxxx",
                "Dimensions": [
                    [
                        "service",
                        "environment",
                        "function_name"
                    ]
                ],
                "Metrics": [
                    {
                        "Name": "ColdStart",
                        "Unit": "Count"
                    }
                ]
            }
        ]
    },
    "service": "xxxxxx",
    "environment": "test",
    "function_name": "xxxxxx",
    "ColdStart": 1
}

Solution/User Experience

I would like to see the metrics logged with just JSON similar to how the logs are output from the Powertools Logger package.

  • Option 1: Stop using standard console.log() and do something similar to the Powertools Logger, or even re-use it.
    • Con: This would not technically be backwards compatible and could in theory break folks if they are parsing their logs in a specific way
    • Pro: Everyone now gets easily machine readable metrics logs
  • Option 2: Update addMetric() and logMetrics() to accept an option indicating the desire for pure JSON output.
    • Pro: Can be done in a backwards compatible manner
    • Con: requires code changes for folks that want JSON logging

Alternative solutions

An alternative would be for us to stop using PowerTools metrics and EMF and use our aggregator's metrics, or convert to OpenTelemetry to be vendor agnostic.

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

@cortexcompiler cortexcompiler added triage This item has not been triaged by a maintainer, please wait feature-request This item refers to a feature request for an existing or new utility labels Oct 25, 2023
@dreamorosi
Copy link
Contributor

Hi @cortexcompiler thank you so much for taking the time to file this feature request.

As you mentioned at the moment the Metrics utility uses console object in the Node.js Lambda runtime, which automatically appends these fields to the content. For the Logger utility we received an early feature request (#747) that asked us to remove these fields for the same exact reason.

I can see the value of adopting a similar strategy for the Metrics utility and between the two options you propose - at least for now - I'd be more inclined to go with option 1. The main reasons for this choice are keeping a relatively simple interface, and the fact that we are currently working on our next major release (#1714) so there's no better time than now to make this type of correction.

Before making a final decision I'd like to take a bit of time to: 1/ test whether or not CloudWatch is still able to parse the EMF from the logs even after removing timestamp & request id from the log, and 2/ understand whether this has any impact for an eventual integration with other 3rd party observability providers.

@dreamorosi dreamorosi added metrics This item relates to the Metrics Utility discussing The issue needs to be discussed, elaborated, or refined need-more-information Requires more information before making any calls and removed triage This item has not been triaged by a maintainer, please wait labels Oct 26, 2023
@dreamorosi dreamorosi self-assigned this Nov 8, 2023
@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation and removed discussing The issue needs to be discussed, elaborated, or refined need-more-information Requires more information before making any calls labels Nov 8, 2023
@dreamorosi
Copy link
Contributor

Hi @cortexcompiler, after looking into this I don't see any issue with supporting this.

I'm working on a PR and the change will likely be released in the next version.

@dreamorosi dreamorosi linked a pull request Nov 10, 2023 that will close this issue
9 tasks
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Nov 10, 2023
Copy link
Contributor

This is now released under v1.15.0 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility metrics This item relates to the Metrics Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants