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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pino-cloudwatch-metrics

v0.0.4

Published

Pino plugin for AWS CloudWatch metrics using Embedded Metric Format (EMF)

Downloads

115

Readme

pino-cloudwatch-metrics

A Pino plugin that enables seamless integration with AWS CloudWatch Metrics using the Embedded Metric Format (EMF). This allows you to emit CloudWatch metrics directly from your Pino logs without additional API calls.

Features

  • 🚀 Zero overhead: Metrics are embedded in your logs using EMF
  • 📊 Type-safe: Full TypeScript support with comprehensive type definitions
  • 🔧 Flexible: Support for custom namespaces, dimensions, and metric units
  • 🎯 Simple API: Chainable, intuitive method calls
  • 📦 Lightweight: Minimal dependencies, built on top of Pino

Installation

npm install pino-cloudwatch-metrics

Usage

Basic Setup

import pino from 'pino'
import { pinoCloudwatchMetrics, Unit } from 'pino-cloudwatch-metrics'

const logger = pinoCloudwatchMetrics()(pino())

Simple Metric Logging

// Log a metric to the default metric namespace
logger.metric({
  Latency: { value: 200, unit: Unit.Milliseconds },
  RequestCount: 5,
})
.info('Processed request')

Incrementing Count Metrics

For the common use case of incrementing a count metric, use the .increment() method as a shorthand:

// Instead of writing this:
logger.metric({ 
  RequestCount: { value: 1, unit: Unit.Count } 
}).info('Request processed')

// You can simply write:
logger.increment('RequestCount').info('Request processed')

The .increment() method automatically creates a metric with a value of 1 and unit of Count. It supports the same chaining as .metric():

logger
  .increment('LoginAttempts')
  .dimensions({ ServiceName: 'AuthService', Environment: 'production' })
  .namespace('MyApp/Auth')
  .info('User login attempt')

Custom Namespace

// Configure default namespace
const logger = pinoCloudwatchMetrics({ 
  defaultNamespace: 'MyApplication' 
})(pino())

logger.metric({
  Latency: { value: 200, unit: Unit.Milliseconds }
})
.info('Request processed')

// Or override namespace per metric
logger.metric({
  Latency: { value: 200, unit: Unit.Milliseconds }
})
.namespace('MyApplication/Metrics')
.info('API request processed')

Adding Dimensions

Dimensions allow you to filter and aggregate metrics in CloudWatch:

logger.metric({
  Latency: { value: 200, unit: Unit.Milliseconds },
  RequestCount: 1,
})
.dimensions({
  ServiceName: 'AuthService',
  Region: 'us-east-1',
  Environment: 'production'
})
.info({ requestId: 'abc123' }, 'User authenticated')

How It Works

This plugin uses the AWS CloudWatch Embedded Metric Format (EMF) to embed metrics directly in your log output. When these logs are sent to CloudWatch Logs (via CloudWatch Agent, Lambda, or other means), the metrics are automatically extracted and made available in CloudWatch Metrics.

Example Output

{
  "level": 30,
  "time": 1735689600000,
  "msg": "User authenticated",
  "requestId": "abc123",
  "_aws": {
    "Timestamp": 1735689600000,
    "CloudWatchMetrics": [
      {
        "Namespace": "AuthService",
        "Dimensions": [["ServiceName", "Region"]],
        "Metrics": [
          { "Name": "Latency", "Unit": "Milliseconds" },
          { "Name": "RequestCount", "Unit": "None" }
        ]
      }
    ]
  },
  "ServiceName": "AuthService",
  "Region": "us-east-1",
  "Latency": 200,
  "RequestCount": 1
}

Requirements

  • Node.js >= 20
  • Pino >= 10

Development

Integration Tests

The integration tests use snapshot testing to verify behavior. If something about the output format changes and you need to update the snapshots, run the following command:

npm run test:integration -- --update