Search in sources :

Example 1 with TraceResponse

use of io.jaegertracing.crossdock.api.TraceResponse in project jaeger-client-java by jaegertracing.

the class TraceBehavior method callDownstreamHttp.

private TraceResponse callDownstreamHttp(Downstream downstream) throws IOException {
    String downstreamUrl = String.format("http://%s:%s/join_trace", downstream.getHost(), downstream.getPort());
    log.info("Calling downstream http {} at {}", downstream.getServiceName(), downstreamUrl);
    Response resp = JerseyServer.client.target(downstreamUrl).request(MediaType.APPLICATION_JSON).post(Entity.json(new JoinTraceRequest(downstream.getServerRole(), downstream.getDownstream())));
    String respStr = resp.readEntity(String.class);
    TraceResponse response = mapper.readValue(respStr, TraceResponse.class);
    log.info("Received response {}", response);
    return response;
}
Also used : TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Response(javax.ws.rs.core.Response) JoinTraceRequest(io.jaegertracing.crossdock.api.JoinTraceRequest) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse)

Example 2 with TraceResponse

use of io.jaegertracing.crossdock.api.TraceResponse in project jaeger-client-java by jaegertracing.

the class TraceBehaviorResource method startTrace.

@POST
@Path("start_trace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TraceResponse startTrace(StartTraceRequest startRequest) throws Exception {
    log.info("http:start_trace request: {}", mapper.writeValueAsString(startRequest));
    // TODO should be starting new root span
    String baggage = startRequest.getBaggage();
    Span span = tracer.activeSpan();
    span.setBaggageItem(Constants.BAGGAGE_KEY, baggage);
    if (startRequest.isSampled()) {
        Tags.SAMPLING_PRIORITY.set(span, 1);
    }
    TraceResponse response = behavior.prepareResponse(startRequest.getDownstream());
    log.info("http:start_trace response: {}", mapper.writeValueAsString(response));
    return response;
}
Also used : Span(io.opentracing.Span) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with TraceResponse

use of io.jaegertracing.crossdock.api.TraceResponse in project jaeger-client-java by jaegertracing.

the class TraceBehaviorResourceTest method validateTraceResponse.

private void validateTraceResponse(TraceResponse response, String expectedTraceId, String expectedBaggage, int expectedDownstream) {
    ObservedSpan span = response.getSpan();
    assertEquals(expectedTraceId, span.getTraceId());
    assertEquals(expectedBaggage, span.getBaggage());
    assertEquals(expectedSampled, span.isSampled());
    TraceResponse downstream = response.getDownstream();
    if (expectedDownstream > 0) {
        assertNotNull(downstream);
        validateTraceResponse(downstream, expectedTraceId, expectedBaggage, expectedDownstream - 1);
    } else {
        assertNull(downstream);
    }
}
Also used : ObservedSpan(io.jaegertracing.crossdock.api.ObservedSpan) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse)

Example 4 with TraceResponse

use of io.jaegertracing.crossdock.api.TraceResponse in project jaeger-client-java by jaegertracing.

the class TraceBehaviorResource method joinTrace.

@POST
@Path("join_trace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TraceResponse joinTrace(JoinTraceRequest joinRequest) throws Exception {
    log.info("http:join_trace request: {}", mapper.writeValueAsString(joinRequest));
    TraceResponse response = behavior.prepareResponse(joinRequest.getDownstream());
    log.info("http:join_trace response: {}", mapper.writeValueAsString(response));
    return response;
}
Also used : TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with TraceResponse

use of io.jaegertracing.crossdock.api.TraceResponse in project jaeger-client-java by jaegertracing.

the class TraceBehaviorResourceTest method testStartTraceHttp.

@Test
public void testStartTraceHttp() throws Exception {
    Span root = server.getTracer().buildSpan("root").start();
    String expectedTraceId = ((JaegerSpanContext) root.context()).getTraceId();
    String expectedBaggage = "baggage-example";
    try (Scope scope = server.getTracer().activateSpan(root)) {
        Downstream downstream = new Downstream(SERVICE_NAME, "127.0.0.1", String.valueOf(port), Constants.TRANSPORT_HTTP, "server", null);
        StartTraceRequest startTraceRequest = new StartTraceRequest("server-role", expectedSampled, expectedBaggage, downstream);
        Response resp = JerseyServer.client.target(String.format("http://%s/start_trace", hostPort)).request(MediaType.APPLICATION_JSON).post(Entity.json(startTraceRequest));
        TraceResponse traceResponse = resp.readEntity(TraceResponse.class);
        assertNotNull(traceResponse.getDownstream());
        validateTraceResponse(traceResponse, expectedTraceId, expectedBaggage, 1);
    }
}
Also used : StartTraceRequest(io.jaegertracing.crossdock.api.StartTraceRequest) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Response(javax.ws.rs.core.Response) Scope(io.opentracing.Scope) ObservedSpan(io.jaegertracing.crossdock.api.ObservedSpan) Span(io.opentracing.Span) Downstream(io.jaegertracing.crossdock.api.Downstream) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) TraceResponse(io.jaegertracing.crossdock.api.TraceResponse) Test(org.junit.Test)

Aggregations

TraceResponse (io.jaegertracing.crossdock.api.TraceResponse)7 ObservedSpan (io.jaegertracing.crossdock.api.ObservedSpan)3 Span (io.opentracing.Span)3 Response (javax.ws.rs.core.Response)3 Downstream (io.jaegertracing.crossdock.api.Downstream)2 JoinTraceRequest (io.jaegertracing.crossdock.api.JoinTraceRequest)2 Scope (io.opentracing.Scope)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2 StartTraceRequest (io.jaegertracing.crossdock.api.StartTraceRequest)1 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)1