Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coozzy/prometheus

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coozzy/prometheus - npm Package Compare versions

Comparing version 3.2.3 to 3.2.4

5

index.d.ts

@@ -6,2 +6,5 @@ /*~ If this module is a UMD module that exposes a global variable 'myLib' when

import {Request, Response, NextFunction} from "express";
import {ServerInterceptingCall} from "@grpc/grpc-js";
import {ServerInterceptingCallInterface} from "@grpc/grpc-js/src/server-interceptors";
import {ServerMethodDefinition} from "@grpc/grpc-js/build/src/make-client";

@@ -21,3 +24,3 @@ export as namespace metrics;

function grpcMiddleware(ctx: object, next: () => void): void;
function grpcMiddleware(methodDescriptor: ServerMethodDefinition<any, any>, call: ServerInterceptingCallInterface): ServerInterceptingCall;

@@ -24,0 +27,0 @@ function incGrpcError(clientName: string, methodName: string, errorCode: number): void;

41

index.js
const Prometheus = require('prom-client');
const http = require('http');
const grpc = require('@grpc/grpc-js');

@@ -84,19 +85,31 @@ const logger = require('@coozzy/logger');

module.exports.grpcMiddleware = async function (ctx, next) {
const startTime = Date.now();
module.exports.grpcMiddleware = function (methodDescriptor, call) {
let startTime;
await next();
const listener = new grpc.ServerListenerBuilder()
.withOnReceiveMessage((message, next) => {
startTime = Date.now();
next(message);
})
.build();
const responseTime = Date.now() - startTime;
const responder = new grpc.ResponderBuilder()
.withStart(next => next(listener))
.withSendStatus((status, next) => {
const responseTime = Date.now() - startTime;
if (grpcRequestDurationMilliseconds) {
grpcRequestDurationMilliseconds
.observe(
{
method: ctx.call.metadata.get('method'),
status_code: ctx.status.details && ctx.status.details.code ? ctx.status.details.code : ctx.status.code
},
responseTime
);
}
if (grpcRequestDurationMilliseconds) {
grpcRequestDurationMilliseconds
.observe(
{
method: methodDescriptor.path ? methodDescriptor.path.substring(methodDescriptor.path.lastIndexOf('/') + 1): 'unknown-path',
status_code: status.code
},
responseTime
);
}
next(status);
})
.build()
return new grpc.ServerInterceptingCall(call, responder);
};

@@ -103,0 +116,0 @@

{
"name": "@coozzy/prometheus",
"version": "3.2.3",
"version": "3.2.4",
"description": "Helps collecting and exporting prometheus metrics",

@@ -18,3 +18,4 @@ "main": "index.js",

"@coozzy/logger": "1.3.2",
"prom-client": "15.1.2"
"prom-client": "15.1.2",
"@grpc/grpc-js": "1.10.6"
},

@@ -21,0 +22,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc