Forked from drobertduke/TracingClientInterceptor.js
Created
December 6, 2018 16:24
-
-
Save Talento90/c862bde98ff0f9668c25daeccb10d155 to your computer and use it in GitHub Desktop.
A NodeJS implementation of a gRPC client logging interceptor
This file contains hidden or 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