func TestThriftTracingPropagation(t *testing.T) { suite := &PropagationTestSuite{ Encoding: EncodingInfo{Format: tchannel.Thrift, HeadersSupported: true}, Register: func(t *testing.T, ch *tchannel.Channel) TracingCall { opts := &thrift.ClientOptions{HostPort: ch.PeerInfo().HostPort} thriftClient := thrift.NewClient(ch, ch.PeerInfo().ServiceName, opts) handler := &ThriftHandler{ TraceHandler: TraceHandler{Ch: ch}, t: t, thriftClient: gen.NewTChanSimpleServiceClient(thriftClient), } // Register Thrift handler server := thrift.NewServer(ch) server.Register(gen.NewTChanSimpleServiceServer(handler)) return handler.firstCall }, TestCases: map[TracerType][]PropagationTestCase{ Noop: { {ForwardCount: 2, TracingDisabled: true, ExpectedBaggage: "", ExpectedSpanCount: 0}, {ForwardCount: 2, TracingDisabled: false, ExpectedBaggage: "", ExpectedSpanCount: 0}, }, Mock: { {ForwardCount: 2, TracingDisabled: true, ExpectedBaggage: BaggageValue, ExpectedSpanCount: 0}, {ForwardCount: 2, TracingDisabled: false, ExpectedBaggage: BaggageValue, ExpectedSpanCount: 6}, }, Jaeger: { {ForwardCount: 2, TracingDisabled: true, ExpectedBaggage: BaggageValue, ExpectedSpanCount: 0}, {ForwardCount: 2, TracingDisabled: false, ExpectedBaggage: BaggageValue, ExpectedSpanCount: 6}, }, }, } suite.Run(t) }
func getClients(t *testing.T, serverCh *tchannel.Channel) (gen.TChanSimpleService, gen.TChanSecondService) { serverInfo := serverCh.PeerInfo() ch := testutils.NewClient(t, nil) ch.Peers().Add(serverInfo.HostPort) client := NewClient(ch, serverInfo.ServiceName, nil) simpleClient := gen.NewTChanSimpleServiceClient(client) secondClient := gen.NewTChanSecondServiceClient(client) return simpleClient, secondClient }
func getClients(serverCh *tchannel.Channel) (gen.TChanSimpleService, gen.TChanSecondService, error) { serverInfo := serverCh.PeerInfo() ch, err := testutils.NewClientChannel(nil) if err != nil { return nil, nil, err } ch.Peers().Add(serverInfo.HostPort) client := NewClient(ch, serverInfo.ServiceName, nil) simpleClient := gen.NewTChanSimpleServiceClient(client) secondClient := gen.NewTChanSecondServiceClient(client) return simpleClient, secondClient, nil }
func (h *thriftHandler) callDownstream(ctx context.Context, target *Downstream) (*Response, error) { req := &Request{ ServerRole: target.ServerRole, Downstream: target.Downstream, } opts := &thrift.ClientOptions{HostPort: target.HostPort} thriftClient := thrift.NewClient(h.ch, target.ServiceName, opts) serviceClient := gen.NewTChanSimpleServiceClient(thriftClient) tReq, err := requestToThrift(req) if err != nil { return nil, err } log.Printf("Calling Thrift service %s (%s)", target.ServiceName, target.HostPort) tctx := thrift.Wrap(ctx) res, err := serviceClient.Call(tctx, tReq) if err != nil { return nil, err } return responseFromThrift(res) }