{"id":24472914,"url":"https://github.com/shutterstock/aws-embedded-metrics-flatten","last_synced_at":"2025-03-14T14:41:49.692Z","repository":{"id":177394352,"uuid":"660331788","full_name":"shutterstock/aws-embedded-metrics-flatten","owner":"shutterstock","description":"Helper for aws-embedded-metrics npm module - Optionally disable emitting metrics and consolidate / flatten thousands of increments on Count metrics into a single line per run.","archived":false,"fork":false,"pushed_at":"2024-06-11T20:15:39.000Z","size":141,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-02-21T11:16:29.024Z","etag":null,"topics":["aws-cloudwatch-metrics","embedded-metrics","flatten","optional"],"latest_commit_sha":null,"homepage":"https://tech.shutterstock.com/aws-embedded-metrics-flatten/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shutterstock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-29T19:11:48.000Z","updated_at":"2024-06-11T20:15:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"81c75d07-94bb-48f4-bc3d-c2ca674dcf17","html_url":"https://github.com/shutterstock/aws-embedded-metrics-flatten","commit_stats":null,"previous_names":["shutterstock/aws-embedded-metrics-flatten"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shutterstock%2Faws-embedded-metrics-flatten","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shutterstock%2Faws-embedded-metrics-flatten/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shutterstock%2Faws-embedded-metrics-flatten/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shutterstock%2Faws-embedded-metrics-flatten/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shutterstock","download_url":"https://codeload.github.com/shutterstock/aws-embedded-metrics-flatten/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243597774,"owners_count":20316842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-cloudwatch-metrics","embedded-metrics","flatten","optional"],"created_at":"2025-01-21T08:14:07.957Z","updated_at":"2025-03-14T14:41:49.671Z","avatar_url":"https://github.com/shutterstock.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm (scoped)](https://img.shields.io/npm/v/%40shutterstock/aws-embedded-metrics-flatten)](https://www.npmjs.com/package/@shutterstock/aws-embedded-metrics-flatten) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) [![API Docs](https://img.shields.io/badge/API%20Docs-View%20Here-blue)](https://tech.shutterstock.com/aws-embedded-metrics-flatten/) [![Build - CI](https://github.com/shutterstock/aws-embedded-metrics-flatten/actions/workflows/ci.yml/badge.svg)](https://github.com/shutterstock/aws-embedded-metrics-flatten/actions/workflows/ci.yml) [![Package and Publish](https://github.com/shutterstock/aws-embedded-metrics-flatten/actions/workflows/publish.yml/badge.svg)](https://github.com/shutterstock/aws-embedded-metrics-flatten/actions/workflows/publish.yml) [![Publish Docs](https://github.com/shutterstock/aws-embedded-metrics-flatten/actions/workflows/docs.yml/badge.svg)](https://github.com/shutterstock/aws-embedded-metrics-flatten/actions/workflows/docs.yml)\n\n# Overview\n\nExtensions for the [aws-embedded-metrics](https://www.npmjs.com/package/aws-embedded-metrics) npm module, adding flatcount metrics that emit a total count instead of an array of each individual count, and the ability to disable metrics without removing metrics method calls.\n\n## Installation\n\nThe package is available on npm as [@shutterstock/aws-embedded-metrics-flatten](https://www.npmjs.com/package/@shutterstock/aws-embedded-metrics-flatten)\n\n`npm i @shutterstock/aws-embedded-metrics-flatten`\n\n## Importing\n\n```typescript\nimport { FlatCountMetrics, metricScopeDummy } from '@shutterstock/aws-embedded-metrics-flatten';\n```\n\n# Features\n\n- Flattens count metrics into a single emitted line\n  - This works around the max length limitation of CloudWatch Embedded Metrics log messages\n  - Rather than emitting an array, such as `[1, 1, 1, 1, 1]`, it emits a single count of `[5]`, dramatically reducing the size of the log message when counting thousands of iterations in a Lambda function\n- Gives the ability to disable the metrics without having to protect each metric emit with a conditional\n\n# Flattening Count Metrics\n\nCloudWatch embedded metrics (parsed from CloudWatch logs) have a limit of something like 1,000 items in a metrics log statement. Metrics beyond that point will be ignored.\n\n`aws-embedded-metrics` will emit metrics with `10,000` calls to `.putMetric('MyMetric', 1, metricUnit.Count);` as an array with 10,000 elements all with the value of `1`... and about `9,000` of those will get ignored as a result.\n\n# Optional Metrics\n\n`metricScopeDummy` is a replacement for `metricScope` that will pass an `MetricsLoggerDummy` instance instead of a `MetricsLogger` instance to the callback function. `MetricsLoggerDummy` implements the same interface as `MetricsLogger` but it does not accumulate data and does not emit any logs.\n\nCoupled with a configuration setting / env var it is possible to emit metrics or not emit metrics by changing which function is used to create the `metrics` object.\n\n# Contributing\n\n## Setting up Build Environment\n\n- `nvm use`\n- `npm i`\n- `npm run build`\n- `npm run lint`\n- `npm run test`\n\n## Running Examples\n\n### metrics-flatten\n\n1. `npm run example:metrics-flatten`\n   1. Will print 2 lines of metrics\n   2. `MyFlatMetric` will have a single value of `10000`\n2. `FLATTEN_METRICS=false npm run example:metrics-flatten`\n   1. Will print many lines of metrics\n   2. `MyFlatMetric` will have 10,000 values of `1` across many different lines\n\n### metrics-optional\n\n1. `npm run example:metrics-optional`\n   1. Metrics will print\n2. `EMIT_METRICS=false npm run example:metrics-optional`\n   1. Metrics will not print\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshutterstock%2Faws-embedded-metrics-flatten","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshutterstock%2Faws-embedded-metrics-flatten","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshutterstock%2Faws-embedded-metrics-flatten/lists"}