Last active
February 15, 2019 23:28
-
-
Save drobertduke/239e5668a20c8114626873886c754c9e to your computer and use it in GitHub Desktop.
A NodeJS implementation of a gRPC client logging interceptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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