Java Code Examples for io.opentracing.mock.MockSpan#MockContext

The following examples show how to use io.opentracing.mock.MockSpan#MockContext . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TracingKafkaUtilsTest.java    From java-kafka-client with Apache License 2.0 6 votes vote down vote up
@Test
public void inject_two_contexts_and_extract() {
  MockSpan span = mockTracer.buildSpan("first").start();
  Headers headers = new RecordHeaders();
  assertEquals(0, headers.toArray().length);

  // inject first
  TracingKafkaUtils.inject(span.context(), headers, mockTracer);
  int headersLength = headers.toArray().length;
  assertTrue(headersLength > 0);

  // inject second
  MockSpan span2 = mockTracer.buildSpan("second").asChildOf(span.context()).start();
  TracingKafkaUtils.inject(span2.context(), headers, mockTracer);
  assertTrue(headers.toArray().length > headersLength);

  // check first
  MockSpan.MockContext spanContext = (MockSpan.MockContext) TracingKafkaUtils
      .extractSpanContext(headers, mockTracer);
  assertEquals(span2.context().spanId(), spanContext.spanId());
  assertEquals(span2.context().traceId(), spanContext.traceId());
}
 
Example 2
Source File: OpenTracingResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Path("/spans")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonArray getSpans() {
    JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();

    MockTracer mockTracer = (MockTracer) tracer;
    for (MockSpan span : mockTracer.finishedSpans()) {
        MockSpan.MockContext context = span.context();

        JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
        objectBuilder.add("spanId", context.spanId());
        objectBuilder.add("traceId", context.traceId());

        span.tags().forEach((k, v) -> objectBuilder.add(k, v.toString()));

        arrayBuilder.add(objectBuilder.build());
    }

    return arrayBuilder.build();
}
 
Example 3
Source File: TracingKafkaUtilsTest.java    From java-kafka-client with Apache License 2.0 5 votes vote down vote up
@Test
public void extract() {
  MockSpan span = mockTracer.buildSpan("test").start();
  Headers headers = new RecordHeaders();
  TracingKafkaUtils.inject(span.context(), headers, mockTracer);

  MockSpan.MockContext spanContext = (MockSpan.MockContext) TracingKafkaUtils
      .extractSpanContext(headers, mockTracer);

  assertEquals(span.context().spanId(), spanContext.spanId());
  assertEquals(span.context().traceId(), spanContext.traceId());
}
 
Example 4
Source File: TracingKafkaUtilsTest.java    From java-kafka-client with Apache License 2.0 5 votes vote down vote up
@Test
public void extract_no_context() {
  Headers headers = new RecordHeaders();

  MockSpan.MockContext spanContext = (MockSpan.MockContext) TracingKafkaUtils
      .extractSpanContext(headers, mockTracer);
  assertNull(spanContext);
}
 
Example 5
Source File: LoggingTracer.java    From java-jaxrs with Apache License 2.0 votes vote down vote up
@JsonProperty("context") abstract MockSpan.MockContext context();