Search in sources :

Example 1 with ScopedSpan

use of brave.ScopedSpan in project brave by openzipkin.

the class RedactingSpanHandlerTest method showRedaction.

@Test
public void showRedaction() throws Exception {
    ScopedSpan span = tracing.tracer().startScopedSpan("auditor");
    try {
        span.tag("a", "1");
        span.tag("b", "4121-2319-1483-3421");
        span.annotate("cc=4121-2319-1483-3421");
        span.tag("c", "3");
    } finally {
        span.finish();
    }
    MutableSpan reported = spans.take();
    assertThat(reported.tags()).containsExactly(entry("a", "1"), // credit card tag was nuked
    entry("c", "3"));
    assertThat(reported.annotations()).extracting(Entry::getValue).containsExactly("cc=xxxx-xxxx-xxxx-xxxx");
    // Leak some data by adding a tag using the same context after the span was .
    tracing.tracer().toSpan(span.context()).tag("d", "cc=4121-2319-1483-3421");
    // Orphans are via GC, to test this, we have to drop any reference to the context
    span = null;
    GarbageCollectors.blockOnGC();
    // GC only clears the reference to the leaked data. Normal tracer use implicitly handles orphans
    tracing.tracer().nextSpan().abandon();
    MutableSpan leaked = spans.take();
    assertThat(leaked.tags()).containsExactly(// credit card tag was nuked
    entry("d", "cc=xxxx-xxxx-xxxx-xxxx"));
}
Also used : MutableSpan(brave.handler.MutableSpan) ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Example 2 with ScopedSpan

use of brave.ScopedSpan in project brave by openzipkin.

the class BaseITTracingClientInterceptor method messageTagging_streaming.

@Test
public void messageTagging_streaming() {
    initMessageTaggingClient();
    ScopedSpan span = tracing.tracer().startScopedSpan("parent");
    try {
        Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HELLO_REQUEST);
        assertThat(replies).toIterable().hasSize(10);
    } finally {
        span.finish();
    }
    assertThat(testSpanHandler.takeRemoteSpan(CLIENT).tags()).containsKey("grpc.message_send.1");
    // Response processing happens on the invocation (parent) trace context
    // Intentionally verbose here to show 10 replies
    assertThat(testSpanHandler.takeLocalSpan().tags()).containsKeys("grpc.message_recv.1", "grpc.message_recv.2", "grpc.message_recv.3", "grpc.message_recv.4", "grpc.message_recv.5", "grpc.message_recv.6", "grpc.message_recv.7", "grpc.message_recv.8", "grpc.message_recv.9", "grpc.message_recv.10");
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Example 3 with ScopedSpan

use of brave.ScopedSpan in project brave by openzipkin.

the class TracingTest method basicUsage.

@Test
public void basicUsage() {
    try (Tracing tracing = Tracing.newBuilder().addSpanHandler(new SpanHandler() {
    }).build()) {
        ScopedSpan parent = tracing.tracer().startScopedSpan("parent");
        tracing.tracer().newChild(parent.context()).finish();
        parent.finish();
    }
}
Also used : SpanHandler(brave.handler.SpanHandler) Tracing(brave.Tracing) ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Example 4 with ScopedSpan

use of brave.ScopedSpan in project brave by openzipkin.

the class ITTracingStatementInterceptor method makesChildOfCurrentSpan.

@Test
public void makesChildOfCurrentSpan() throws Exception {
    ScopedSpan parent = tracing.tracer().startScopedSpan("test");
    try {
        prepareExecuteSelect(QUERY);
    } finally {
        parent.finish();
    }
    assertThat(spans).hasSize(2);
}
Also used : ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Example 5 with ScopedSpan

use of brave.ScopedSpan in project brave by openzipkin.

the class ITTracingP6Factory method makesChildOfCurrentSpan.

@Test
public void makesChildOfCurrentSpan() throws Exception {
    ScopedSpan parent = tracing.tracer().startScopedSpan("test");
    try {
        prepareExecuteSelect(QUERY);
    } finally {
        parent.finish();
    }
    assertThat(spans).hasSize(2);
}
Also used : ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Aggregations

ScopedSpan (brave.ScopedSpan)16 Test (org.junit.Test)14 MutableSpan (brave.handler.MutableSpan)3 Tracing (brave.Tracing)2 TraceContext (brave.propagation.TraceContext)2 BookRestClient (org.apache.cxf.systest.microprofile.rest.client.tracing.BookRestClient)2 CurrentSpanCustomizer (brave.CurrentSpanCustomizer)1 Span (brave.Span)1 CLIENT (brave.Span.Kind.CLIENT)1 SpanCustomizer (brave.SpanCustomizer)1 SpanHandler (brave.handler.SpanHandler)1 FromRequestAdapter (brave.http.HttpClientAdapters.FromRequestAdapter)1 IntegrationTestSpanHandler (brave.test.IntegrationTestSpanHandler)1 HelloReply (io.grpc.examples.helloworld.HelloReply)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 After (org.junit.After)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 RunWith (org.junit.runner.RunWith)1