zipkin-js icon indicating copy to clipboard operation
zipkin-js copied to clipboard

Feature request: GRPC client/server interceptors

Open devinsba opened this issue 8 years ago • 9 comments

It would be nice to have interceptors similar to the grpc ones from openzipkin/brave

devinsba avatar Jan 31 '17 16:01 devinsba

Turns out there is a missing feature in the nodejs grpc library: https://github.com/grpc/grpc/issues/8767

devinsba avatar Jan 31 '17 20:01 devinsba

since zipkin is very much like google cloud trace, we can probably borrow approach from them https://github.com/GoogleCloudPlatform/cloud-trace-nodejs

codefromthecrypt avatar Feb 01 '17 01:02 codefromthecrypt

Their approach overall is quite nice, if I end up with time I'll take a crack at implementing it.

If someone else gets to it first: https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/blob/master/src/hooks/userspace/hook-grpc.js

devinsba avatar Feb 01 '17 15:02 devinsba

👍 Would love to see this as well!

ethanrubio avatar Mar 20 '17 21:03 ethanrubio

+1

lnshi avatar Aug 01 '17 04:08 lnshi

https://github.com/grpc/proposal/pull/14 indicates a future interceptor model (which doesn't necessarily help now)

codefromthecrypt avatar Aug 01 '17 04:08 codefromthecrypt

I am using the code that @lnshi created already. I created a wrapper function that handles getting the metadata and finishing when the function is done (for server side). It would be nice if this could be included/done automatically when using this library. But it is a bit over my head at the moment.

function trace(func) {
    return async (call, callback) => {
        global.ZIPKIN_GRPC_INTCP.uponServerRecvGrpcCall({
            serviceName: ZIPKIN_SERVICE_NAME,
            grpcMetadataFromIncomingCtx: call.metadata
        });

        try {
            await func(call, callback);
        } finally {
            global.ZIPKIN_GRPC_INTCP.uponServerFinishRespond();
        }
    }
}

Then when assigning the call to the grpc server you just use grpcMethod: trace(your_original_grpc_method)

your_original_grpc_method must be async, e.g.

async function your_original_grpc_method(call, callback) {
    try {
         // do stuff
         return callback(null, {message: 'message'});
    } catch (err) {
        return callback(err);
    }
}

wdittmer avatar Mar 17 '18 12:03 wdittmer

I think this issue is partially fixes by https://github.com/openzipkin/zipkin-js/tree/master/packages/zipkin-instrumentation-grpc-client. Ping @ghermeto

jcchavezs avatar Mar 28 '19 12:03 jcchavezs

it was... and the bad news is that gRPC in javascript doesn't have server interceptors (yet).

ghermeto avatar Mar 28 '19 14:03 ghermeto