You can extends TBinaryProtocol, create your own protocol class, then replace 
the protocol when you start your server, that’s pretty simple.

To create your own protocol:

public class TTracingBinaryProtocol extends TBinaryProtocol {

    public TTracingBinaryProtocol(TTransport trans, long stringLengthLimit, 
long containerLengthLimit,
                                  boolean strictRead, boolean strictWrite) {
        super(trans, stringLengthLimit, containerLengthLimit, strictRead, 
strictWrite);
    }

    @Override
    public TMessage readMessageBegin() throws TException {
        int size = readI32();
        // handle the header here, if it is Tracing Protocl, read the trace id 
and other info, then call the super method.
}

    public static class Factory extends TBinaryProtocol.Factory {

        public TProtocol getProtocol(TTransport trans) {
            return new TTracingBinaryProtocol(trans, stringLengthLimit_, 
containerLengthLimit_, strictRead_, strictWrite_);
        }
    }

}

To use your own protocol:

            TThreadedSelectorServer server = new TThreadedSelectorServer(
                    new 
TThreadedSelectorServer.Args(randomPort.transport).processor(processor).
                            protocolFactory(new 
TTracingBinaryProtocol.Factory()).selectorThreads(2).workerThreads(48));
            server.serve();



On 27/10/2017, 9:36 AM, "Akshya Gupta" <[email protected]> wrote:

    Thanks so much. That's what I figured. Maybe I need to put a change in
    processor also to pass on the attached context. I think with newer version
    of thrift, passing a context is anyways necessary. But we are using 0.9.3
    Let me give it a shot
    
    On Oct 26, 2017 6:34 PM, "Daniel Wu" <[email protected]> wrote:
    
    > Actually you can just add a protocol add an extra header just like
    > Finagle. You don’t change anything to thrift and you can communicate
    > between raw binary protocol and your own protocol.
    >
    > On 27/10/2017, 8:39 AM, "Akshya Gupta" <[email protected]> wrote:
    >
    >     Hello,
    >
    >     I was trying to integrate the tracing capabilities of opentracing into
    > the thrift RPC for golang.
    >
    >     But I am not sure which files I would need to modify. My thoughts were
    > to create a new TProtocol (like TCompactProtocol) which would accept the
    > tracer and the span context created by the opentracing and then whenever 
an
    > rpc message is sent or received, a span trace would be sent to the tracer.
    >
    >     I saw that there is a java-thrift implementation https://github.com/
    > opentracing-contrib/java-thrift <https://github.com/
    > opentracing-contrib/java-thrift>
    >     But the implementation for golang would be a bit different I guess,
    > hence the question
    >
    >     Thanks
    >     Aks.
    >     --
    >
    >     This message and its attachments are intended only for the addressee
    > and
    >     may contain legally privileged and/or confidential information. If you
    > are
    >     not the intended recipient, you are hereby notified that you must not
    > use,
    >     disseminate, or copy this material in any form, or take any action
    > based
    >     upon it. If you have received this message by error, please 
immediately
    >     delete it and its attachments and notify the sender at SnapRoute, Inc.
    > by
    >     electronic mail message reply. Thank you.
    >
    >
    >
    >
    >
    >
    
    -- 
    
    This message and its attachments are intended only for the addressee and 
    may contain legally privileged and/or confidential information. If you are 
    not the intended recipient, you are hereby notified that you must not use, 
    disseminate, or copy this material in any form, or take any action based 
    upon it. If you have received this message by error, please immediately 
    delete it and its attachments and notify the sender at SnapRoute, Inc. by 
    electronic mail message reply. Thank you.
    




Reply via email to