Socket
Book a DemoInstallSign in
Socket

@shutterstock/aws-embedded-metrics-flatten

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shutterstock/aws-embedded-metrics-flatten

Helpers for aws-embedded-metrics

1.0.6
latest
Source
npmnpm
Version published
Maintainers
4
Created
Source

npm (scoped) License: MIT API Docs Build - CI Package and Publish Publish Docs

Overview

Extensions for the 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.

Installation

The package is available on npm as @shutterstock/aws-embedded-metrics-flatten

npm i @shutterstock/aws-embedded-metrics-flatten

Importing

import { FlatCountMetrics, metricScopeDummy } from '@shutterstock/aws-embedded-metrics-flatten';

Features

  • Flattens count metrics into a single emitted line
    • This works around the max length limitation of CloudWatch Embedded Metrics log messages
    • 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
  • Gives the ability to disable the metrics without having to protect each metric emit with a conditional

Flattening Count Metrics

CloudWatch 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.

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.

Optional Metrics

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.

Coupled 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.

Contributing

Setting up Build Environment

  • nvm use
  • npm i
  • npm run build
  • npm run lint
  • npm run test

Running Examples

metrics-flatten

  • npm run example:metrics-flatten
    • Will print 2 lines of metrics
    • MyFlatMetric will have a single value of 10000
  • FLATTEN_METRICS=false npm run example:metrics-flatten
    • Will print many lines of metrics
    • MyFlatMetric will have 10,000 values of 1 across many different lines

metrics-optional

  • npm run example:metrics-optional
    • Metrics will print
  • EMIT_METRICS=false npm run example:metrics-optional
    • Metrics will not print

Keywords

aws

FAQs

Package last updated on 29 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.