npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mihilmy/cw-logger

v1.0.6

Published

Aggregated cloudwatch logs publisher

Downloads

2

Readme

Library allows users to aggregate metrics and raw logs using the Embedded Metric Format, saving costs and providing raw data for analysis. Designed to be used on your frontend applications where each session is tracked with its own log stream, allowing high throughput and high cardinality metrics per user session.

📖 Concepts

  1. Reporter: Responsible for reporting logs to CloudWatch every X seconds, partitioning into multiple requests if necessary and handling a retry strategy for throttles.
  2. Aggregator: Collects metrics/logs throughout the session by acting as an in-memory storage layer, these are later sent to cloudwatch via a Reporter.

🔌 Extend It

Library was designed carefully to allow users to extend the basic usage by adding a more complex aggregation logic to optimize for costs, you can implement the Aggregator interface, and the library should continue to work as expected. You have the ability to create custom metric classes and factories.

🔐 Authorization

Request and response authorization is beyond the basic reporter capability. It's recommended having an endpoint in your backend that can proxy these requests to the cloudwatch endpoint. The most ideal design is when using it with a CloudFront distribution, and you can hookup a request signer that passes the requests to the cloudwatch origin.

🌏 Web Applications

// Step 1: Initializer a reporter instance
const reporter = new WebSessionMetricsReporter<SpotifyPlayerMetrics>({
  namespace: "WebsiteMetrics",  
  aggregator: new BasicAggregator(),
  logsEndpoint,
  logGroupName,
  flushFrequency
});
reporter.startReporting("@mihilmy");

// Step 2: Initialize handler for recording the user action
document.getElementById("save").onclick = () => reporter.addCount("SaveButtonClicks", 1);
<!-- Sample markup for a simple page  -->
<body>
<div id="app">
  <input type="text" id="Address" placeholder="Add Address" />
  <button id="save">Save</button>
</div>

<script src="src/index.ts"></script>
</body>

ƛ AWS Lambda

AWS Lambda makes it too easy to include custom metrics in your application, simply log the embedded metric format to your cloud watch logs and this will generate a metric in cloudwatch backend.

// Add this to a shared script that multiple consumers can use
const reporter = new LambdaMetricsReporter<BackendAPIMetrics>({  namespace: "BackendMetrics" });

reporter.addCount("XApiInvocations", 1); // One liner!!

CloudWatch Hard Limits

Adding these here as a reminder for how much we can optimize

  1. The embedded metric format is subject to a maximum size of 256 KB.
  2. The batch log events are limited to 1MB and 10,000 events.
  3. Can not be more than 2 hours in the future.
  4. Can not be older than 14 days.
  5. Can not span more than 24 hours.
  6. The log events in the batch must be in chronological order by their timestamp
  7. 5 TPS hard limit on sending logs to a log group.