@fonoster/grpc-interceptors
TypeScript icon, indicating that this package has built-in type declarations

0.2.5 • Public • Published

Credit and source

https://github.com/echo-health/node-grpc-interceptors

grpc-interceptors

This library provides a way to instrument Node.js gRPC clients and servers with interceptors/middleware e.g. for Prometheus metrics, Zipkin tracing etc.

Usage

const interceptors = require('grpc-interceptors');
const grpc = require('grpc');

const server = interceptors.serverProxy(new grpc.Server());
server.addService(proto.MyPackage.MyService.service, { Method1, Method2 });

const myMiddlewareFunc = async function (ctx, next, errorCb) {

    try {
    // do stuff before call
    console.log('Making gRPC call...');
    await next()
    // do stuff after call
    console.log(ctx.status.code);
    } catch(e) {
        errorCb({
            code: grpc.status.INTERNAL,
            message: 'Some error occurred!'
        });
    }
}

server.use(myMiddlewareFunc);

Available Interceptors

Dependents (0)

Package Sidebar

Install

npm i @fonoster/grpc-interceptors

Weekly Downloads

15

Version

0.2.5

License

ISC

Unpacked Size

24.4 kB

Total Files

21

Last publish

Collaborators

  • fonoster-oss