Search in sources :

Example 81 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class ITJms_1_1_TracingMessageProducer method should_prefer_current_to_stale_b3_header.

@Test
public void should_prefer_current_to_stale_b3_header() throws JMSException {
    jms.setReadOnlyProperties(message, false);
    setStringProperty(message, "b3", writeB3SingleFormat(newTraceContext(SamplingFlags.NOT_SAMPLED)));
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        messageProducer.send(jms.destination, message);
    }
    Message received = messageConsumer.receive();
    MutableSpan producerSpan = testSpanHandler.takeRemoteSpan(PRODUCER);
    assertChildOf(producerSpan, parent);
    assertThat(propertiesToMap(received)).containsAllEntriesOf(existingProperties).containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 82 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class ITTracingJMSProducer method should_not_serialize_parent_span_id.

@Test
public void should_not_serialize_parent_span_id() {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        producer.send(jms.queue, "foo");
    }
    Message received = consumer.receive();
    MutableSpan producerSpan = testSpanHandler.takeRemoteSpan(PRODUCER);
    assertChildOf(producerSpan, parent);
    assertThat(propertiesToMap(received)).containsAllEntriesOf(existingProperties).containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) Message(javax.jms.Message) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 83 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class JmsTracingTest method nextSpan_prefers_b3_header.

@Test
public void nextSpan_prefers_b3_header() {
    TraceContext incoming = newTraceContext(SamplingFlags.NOT_SAMPLED);
    setStringProperty(message, "b3", B3SingleFormat.writeB3SingleFormat(incoming));
    Span child;
    try (Scope ws = tracing.currentTraceContext().newScope(parent)) {
        child = jmsTracing.nextSpan(message);
    }
    assertChildOf(child.context(), incoming);
    assertThat(child.isNoop()).isTrue();
}
Also used : Scope(brave.propagation.CurrentTraceContext.Scope) TraceContext(brave.propagation.TraceContext) Span(brave.Span) Test(org.junit.Test)

Example 84 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class ITJms_1_1_TracingMessageConsumer method resetB3PropertyWithNewSampledContext.

TraceContext resetB3PropertyWithNewSampledContext(JmsTestRule jms) throws JMSException {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    message = jms.newMessage("foo");
    bytesMessage = jms.newBytesMessage("foo");
    String b3 = B3SingleFormat.writeB3SingleFormatWithoutParentId(parent);
    setStringProperty(message, "b3", b3);
    setStringProperty(bytesMessage, "b3", b3);
    lockMessages();
    return parent;
}
Also used : TraceContext(brave.propagation.TraceContext) MessageProperties.getPropertyIfString(brave.jms.MessageProperties.getPropertyIfString)

Example 85 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class ITJms_1_1_TracingMessageConsumer method receive_resumesTrace.

void receive_resumesTrace(JMSRunnable send, MessageConsumer messageConsumer) throws JMSException {
    TraceContext parent = resetB3PropertyWithNewSampledContext(jms);
    send.run();
    Message received = messageConsumer.receive();
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertChildOf(consumerSpan, parent);
    assertThat(received.getStringProperty("b3")).isEqualTo(parent.traceIdString() + "-" + consumerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) TraceContext(brave.propagation.TraceContext)

Aggregations

TraceContext (brave.propagation.TraceContext)200 Test (org.junit.Test)163 CurrentTraceContext (brave.propagation.CurrentTraceContext)77 Scope (brave.propagation.CurrentTraceContext.Scope)52 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)52 MutableSpan (brave.handler.MutableSpan)38 Span (brave.Span)17 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 MockResponse (okhttp3.mockwebserver.MockResponse)12 SpanHandler (brave.handler.SpanHandler)9 Clock (brave.Clock)7 SamplingFlags (brave.propagation.SamplingFlags)7 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 TestSpanHandler (brave.test.TestSpanHandler)6 AssertableCallback (brave.test.util.AssertableCallback)6 Message (javax.jms.Message)6 After (org.junit.After)6