use of io.jaegertracing.internal.JaegerSpanContext 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);
}
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method support128BitTraceIdExtraction.
@Test
public void support128BitTraceIdExtraction() {
String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
String parentSpan = "d1595c6ec91668af";
String tracecontext = String.format("00-%s-%s-01", hex128Bits, parentSpan);
TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
textMap.put(TRACE_PARENT, tracecontext);
JaegerSpanContext context = traceContextCodec.extract(textMap);
assertNotNull(HexCodec.lowerHexToUnsignedLong(parentSpan));
assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow());
assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh());
assertEquals(HexCodec.lowerHexToUnsignedLong(parentSpan).longValue(), context.getSpanId());
assertTrue(context.isSampled());
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testTraceStatePropagation.
@Test
public void testTraceStatePropagation() {
Map<String, String> extractCarrier = new HashMap<>();
TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
textMap.put(TRACE_PARENT, EXAMPLE_TRACE_PARENT);
textMap.put(TRACE_STATE, "whatever");
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
Map<String, String> injectCarrier = new HashMap<>();
traceContextCodec.inject(spanContext, new TextMapAdapter(injectCarrier));
assertEquals(extractCarrier, injectCarrier);
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class B3TextMapCodecTest method support128BitTraceIdExtraction.
@Test
public void support128BitTraceIdExtraction() {
String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
String lower64Bits = "48485a3953bb6124";
DelegatingTextMap textMap = new DelegatingTextMap();
textMap.put(B3TextMapCodec.TRACE_ID_NAME, hex128Bits);
textMap.put(B3TextMapCodec.SPAN_ID_NAME, lower64Bits);
textMap.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, "0");
textMap.put(B3TextMapCodec.SAMPLED_NAME, "1");
textMap.put(B3TextMapCodec.FLAGS_NAME, "1");
textMap.put(B3TextMapCodec.BAGGAGE_PREFIX + "foo", "bar");
textMap.put("random-foo", "bar");
JaegerSpanContext context = b3Codec.extract(textMap);
assertNotNull(HexCodec.lowerHexToUnsignedLong(lower64Bits));
assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow());
assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh());
assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits).longValue(), context.getSpanId());
assertEquals(0, context.getParentId());
assertEquals(B3TextMapCodec.SAMPLED_FLAG | B3TextMapCodec.DEBUG_FLAG, context.getFlags());
assertEquals(1, ((Set<Entry<String, String>>) context.baggageItems()).size());
assertEquals("bar", context.getBaggageItem("foo"));
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class B3TextMapCodecTest method testDefault.
@Test
public void testDefault() {
B3TextMapCodec b3Codec = new B3TextMapCodec.Builder().build();
DelegatingTextMap entries = new DelegatingTextMap();
long traceIdLow = 1;
long spanId = 2;
long parentId = 3;
JaegerSpanContext spanContext = new JaegerSpanContext(0L, traceIdLow, spanId, parentId, (byte) 0).withBaggageItem("foo", "bar");
b3Codec.inject(spanContext, entries);
assertEquals(5, entries.delegate.size());
assertNotNull(entries.delegate.get(B3TextMapCodec.TRACE_ID_NAME));
assertNotNull(entries.delegate.get(B3TextMapCodec.SPAN_ID_NAME));
assertNotNull(entries.delegate.get(B3TextMapCodec.PARENT_SPAN_ID_NAME));
assertNotNull(entries.delegate.get(B3TextMapCodec.SAMPLED_NAME));
assertEquals("bar", entries.delegate.get("baggage-foo"));
}
Aggregations