Search in sources :

Example 1 with ForwardingClientStreamTracer

use of io.grpc.internal.ForwardingClientStreamTracer in project grpc-java by grpc.

the class TokenAttachingTracerFactory method newClientStreamTracer.

@Override
public ClientStreamTracer newClientStreamTracer(ClientStreamTracer.StreamInfo info, Metadata headers) {
    if (delegate == null) {
        return NOOP_TRACER;
    }
    final ClientStreamTracer clientStreamTracer = delegate.newClientStreamTracer(info, headers);
    class TokenPropagationTracer extends ForwardingClientStreamTracer {

        @Override
        protected ClientStreamTracer delegate() {
            return clientStreamTracer;
        }

        @Override
        public void streamCreated(Attributes transportAttrs, Metadata headers) {
            Attributes eagAttrs = checkNotNull(transportAttrs.get(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS), "eagAttrs");
            String token = eagAttrs.get(GrpclbConstants.TOKEN_ATTRIBUTE_KEY);
            headers.discardAll(GrpclbConstants.TOKEN_METADATA_KEY);
            if (token != null) {
                headers.put(GrpclbConstants.TOKEN_METADATA_KEY, token);
            }
            delegate().streamCreated(transportAttrs, headers);
        }
    }
    return new TokenPropagationTracer();
}
Also used : ClientStreamTracer(io.grpc.ClientStreamTracer) ForwardingClientStreamTracer(io.grpc.internal.ForwardingClientStreamTracer) ForwardingClientStreamTracer(io.grpc.internal.ForwardingClientStreamTracer) GrpcAttributes(io.grpc.internal.GrpcAttributes) Attributes(io.grpc.Attributes) Metadata(io.grpc.Metadata)

Aggregations

Attributes (io.grpc.Attributes)1 ClientStreamTracer (io.grpc.ClientStreamTracer)1 Metadata (io.grpc.Metadata)1 ForwardingClientStreamTracer (io.grpc.internal.ForwardingClientStreamTracer)1 GrpcAttributes (io.grpc.internal.GrpcAttributes)1