Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Talento90/c862bde98ff0f9668c25daeccb10d155 to your computer and use it in GitHub Desktop.
Save Talento90/c862bde98ff0f9668c25daeccb10d155 to your computer and use it in GitHub Desktop.
A NodeJS implementation of a gRPC client logging interceptor
'use strict';
const bunyan = require('bunyan');
const grpc = require('grpc');
const log = bunyan.createLogger({name: 'TracingClientInterceptor'});
module.exports = function(options, nextCall) {
return new grpc.InterceptingCall(nextCall(options), {
start: function(metadata, listener, next) {
log.trace('Sending metadata', metadata);
next(metadata, {
onReceiveMetadata: function(metadata, next) {
log.trace('Receiving metadata', metadata);
next(metadata);
},
onReceiveMessage: function(message, next) {
log.trace('Receiving message', message);
next(message);
},
onReceiveStatus: function(status, next) {
log.trace('Receiving status', status);
next(status);
},
});
},
sendMessage: function(message, next) {
log.trace('Sending message', message);
next(message);
},
halfClose: function(next) {
log.trace('Sending close');
next();
},
cancel: function(message, next) {
log.trace('Sending cancel', message);
next();
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment