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

@egebilgi/log-metric-service-library

v2.3.3

Published

A lightweight log/metric emitter library for Node.js projects, designed to be used with the Egebilgi Log Metric Service. It provides a simple interface for logging and metric collection, making it easy to integrate into our applications.

Readme

Log Metric Service Middleware

Overview

This package provides an Express middleware and service for logging HTTP request metrics. It allows logging of request duration, status, and other key metrics that can be sent to a metric service Prometheus. It also includes a method for sending these metrics to a service via HTTP.

Features

  • Request Metrics: Logs HTTP request duration, status code, and other labels (e.g., service, customer ID).
  • Metric Service: Sends metrics to a specified service via HTTP.
  • Prometheus-Compatible: Compatible with Prometheus for monitoring and alerting.
  • Error Handling: Gracefully handles errors while logging metrics.

Installation

To install the package, run the following:

npm install @egebilgi/log-metric-service-library


# Usage

## Adding Middleware to Express

You can use the provided middleware to log request metrics such as response time and status code. It works seamlessly with Prometheus metrics.

```typescript
const app = express();

app.use(middlewares.logRequestMetricsMiddleware("myService", "12345"));

Method to Send Metrics

The LogMetricService class has a method sendMetric that logs a metric to a service. Below is an example of how this is used:

class LogMetricService {
  public async sendMetric(
    name: string,
    type: string,
    description: string,
    labels: {},
    value: number
  ): Promise<void> {
    try {
      const payload = { name, type, description, labels, value };
      await this.req.post("/add-metric", payload); // Sends the metric to a service endpoint
      this.emit("metricLogged", payload); // Emits a 'metricLogged' event after successful logging
    } catch (err: any) {
      this.emit("error", err); // Emits an error event if something goes wrong
    }
  }
}

Full Example

Here is a full example integrating the middleware and service into an Express application.

import express from "express";
import LogMetricService from "@/log-metric-service";
import Middlewares from "@egebilgi/log-metric-service-library";

const app = express();
const logMetricService = new LogMetricService();
const middlewares = new Middlewares(logMetricService);

// Use the logRequestMetricsMiddleware with optional service and customer_id
app.use(middlewares.logRequestMetricsMiddleware("myService", "12345"));

// Sample route to test metrics logging
app.get("/test", (req, res) => {
  res.status(200).send("Metrics logging is working!");
});

// Start the server
app.listen(3000, () => {
  console.log("Server running on http://localhost:3000");
});

Error Handling

If metric logging fails, the middleware and service will log an error message to the console and continue processing the request. You can modify the error handling logic to fit your needs.

Events

  • metricLogged: Fired when a metric is successfully logged.
  • error: Fired when there is an error in logging the metric.

Configuration Options

  • service: The name of the service being monitored (e.g., "myService").
  • customer_id: Optional identifier for the customer.

Both service and customer_id are optional parameters in the middleware.

License

This project is licensed under the MIT License - see the LICENSE file for details.