@coozzy/prometheus
Advanced tools
Comparing version 3.2.3 to 3.2.4
@@ -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": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9536
224
4
+ Added@grpc/grpc-js@1.10.6
+ Added@grpc/grpc-js@1.10.6(transitive)
+ Added@grpc/proto-loader@0.7.13(transitive)
+ Added@js-sdsl/ordered-map@4.4.2(transitive)
+ Added@protobufjs/aspromise@1.1.2(transitive)
+ Added@protobufjs/base64@1.1.2(transitive)
+ Added@protobufjs/codegen@2.0.4(transitive)
+ Added@protobufjs/eventemitter@1.1.0(transitive)
+ Added@protobufjs/fetch@1.1.0(transitive)
+ Added@protobufjs/float@1.0.2(transitive)
+ Added@protobufjs/inquire@1.1.0(transitive)
+ Added@protobufjs/path@1.1.2(transitive)
+ Added@protobufjs/pool@1.1.0(transitive)
+ Added@protobufjs/utf8@1.1.0(transitive)
+ Added@types/node@22.10.1(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlodash.camelcase@4.3.0(transitive)
+ Addedlong@5.2.3(transitive)
+ Addedprotobufjs@7.4.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)