use of com.uber.jaeger.Span in project jaeger-client-java by jaegertracing.
the class TraceBehaviorResourceTest method testStartTraceHttp.
@Test
public void testStartTraceHttp() throws Exception {
Span span = (Span) server.getTracer().buildSpan("root").start();
TracingUtils.getTraceContext().push(span);
String expectedTraceId = String.format("%x", span.context().getTraceId());
String expectedBaggage = "baggage-example";
Downstream downstream = new Downstream(SERVICE_NAME, "127.0.0.1", 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);
}
use of com.uber.jaeger.Span in project jaeger-client-java by jaegertracing.
the class JerseyServerFilterTest method testOperationNameSuccess.
@Test
public void testOperationNameSuccess() throws Exception {
Response response = target("hello/world/middle-earth").request().get();
assertEquals(200, response.getStatus());
Span span = reporter.getSpans().get(0);
assertEquals("GET:/hello/world/{worldId}", span.getOperationName());
assertCache("getHello");
}
use of com.uber.jaeger.Span in project jaeger-client-java by jaegertracing.
the class ServerFilterTest method filter.
@Test
public void filter() throws Exception {
String method = "GET";
URI uri = new URI("http://localhost/path");
when(containerRequestContext.getMethod()).thenReturn(method);
UriInfo uriInfo = mock(UriInfo.class);
when(uriInfo.getAbsolutePath()).thenReturn(uri);
when(uriInfo.getBaseUri()).thenReturn(uri);
when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>();
headers.add(Constants.X_UBER_SOURCE, "source");
when(containerRequestContext.getHeaders()).thenReturn(headers);
when(containerResponseContext.getStatus()).thenReturn(200);
undertest.filter(containerRequestContext);
undertest.filter(containerRequestContext, containerResponseContext);
List<Span> spans = reporter.getSpans();
assertEquals(1, spans.size());
Span span = spans.get(0);
Map<String, Object> tags = span.getTags();
assertEquals(method, span.getOperationName());
assertEquals(Tags.SPAN_KIND_SERVER, tags.get(Tags.SPAN_KIND.getKey()));
assertEquals(uri.toString(), tags.get(Tags.HTTP_URL.getKey()));
assertEquals("localhost", tags.get(Tags.PEER_HOSTNAME.getKey()));
// Exercise catch blocks on filter methods for code coverage
undertest.filter(null);
// For filter(requestContext, responseContext) we first need to make sure there's something in the traceContext
undertest.filter(containerRequestContext);
undertest.filter(containerRequestContext, null);
}
use of com.uber.jaeger.Span in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testSpanLogsCreateAnnotations.
@Test
public void testSpanLogsCreateAnnotations() {
Span span = (com.uber.jaeger.Span) tracer.buildSpan("span-with-logs").startManual();
span.log("event");
// use sorted map for consistent ordering in test
Map<String, Object> fields = new TreeMap<String, Object>();
fields.put("event", "structured data");
fields.put("string", "something");
fields.put("number", 42);
fields.put("boolean", true);
span.log(fields);
com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
List<String> annotationValues = new ArrayList<String>();
for (Annotation annotation : zipkinSpan.getAnnotations()) {
annotationValues.add(annotation.getValue());
}
List<String> expectedValues = new ArrayList<String>();
expectedValues.add("event");
expectedValues.add("{\"boolean\":true,\"event\":\"structured data\",\"number\":42,\"string\":\"something\"}");
assertEquals("zipkin span should contain matching annotations for span logs", expectedValues, annotationValues);
}
use of com.uber.jaeger.Span in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.
@Test
public void testRpcChildSpanHasTheSameId() {
String expectedOperation = "parent";
Span client = (Span) tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).startManual();
Map<String, String> map = new HashMap<>();
TextMap carrier = new TextMapInjectAdapter(map);
tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
carrier = new TextMapExtractAdapter(map);
SpanContext ctx = (SpanContext) tracer.extract(Format.Builtin.TEXT_MAP, carrier);
assertEquals(client.context().getSpanId(), ctx.getSpanId());
Span server = (Span) tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).startManual();
assertEquals("client and server must have the same span ID", client.context().getSpanId(), server.context().getSpanId());
}
Aggregations