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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations