Search in sources :

Example 6 with Tracer

use of io.opentracing.Tracer in project opentracing-java by opentracing.

the class GlobalTracerTest method testDelegation_inject.

@Test
public void testDelegation_inject() {
    Tracer mockTracer = mock(Tracer.class);
    SpanContext mockContext = mock(SpanContext.class);
    Format<Object> mockFormat = mock(Format.class);
    Object mockCarrier = mock(Object.class);
    GlobalTracer.register(mockTracer);
    GlobalTracer.get().inject(mockContext, mockFormat, mockCarrier);
    verify(mockTracer).inject(eq(mockContext), eq(mockFormat), eq(mockCarrier));
    verifyNoMoreInteractions(mockTracer, mockContext, mockFormat, mockCarrier);
}
Also used : SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) Test(org.junit.Test)

Example 7 with Tracer

use of io.opentracing.Tracer in project opentracing-java by opentracing.

the class GlobalTracerTest method testMultipleRegistrations_sameTracer.

/**
 * Check leniency for duplicate registration with the same tracer by mistake.
 */
@Test
public void testMultipleRegistrations_sameTracer() {
    Tracer mockTracer = mock(Tracer.class);
    GlobalTracer.register(mockTracer);
    GlobalTracer.register(mockTracer);
// 'test' that double registration of the same tracer does not throw exception
}
Also used : Tracer(io.opentracing.Tracer) Test(org.junit.Test)

Example 8 with Tracer

use of io.opentracing.Tracer in project opentracing-java by opentracing.

the class GlobalTracerTest method testDelegation_buildSpan.

@Test
public void testDelegation_buildSpan() {
    Tracer mockTracer = mock(Tracer.class);
    GlobalTracer.register(mockTracer);
    GlobalTracer.get().buildSpan("my-operation");
    verify(mockTracer).buildSpan(eq("my-operation"));
    verifyNoMoreInteractions(mockTracer);
}
Also used : Tracer(io.opentracing.Tracer) Test(org.junit.Test)

Example 9 with Tracer

use of io.opentracing.Tracer in project sharding-jdbc by shardingjdbc.

the class ExecuteEventListener method handle.

private void handle(final AbstractSQLExecutionEvent event, final String operation) {
    Tracer tracer = ShardingJDBCTracer.get();
    switch(event.getEventExecutionType()) {
        case BEFORE_EXECUTE:
            if (ExecutorDataMap.getDataMap().containsKey(SNAPSHOT_DATA_KEY) && !isCurrentMainThread()) {
                trunkInBranchContainer.set(((ActiveSpan.Continuation) ExecutorDataMap.getDataMap().get(SNAPSHOT_DATA_KEY)).activate());
            }
            branchContainer.set(tracer.buildSpan("/SJDBC/BRANCH/" + operation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOSTNAME.getKey(), event.getDataSource()).withTag(Tags.COMPONENT.getKey(), "ShardingJDBC").withTag(Tags.DB_INSTANCE.getKey(), event.getDataSource()).withTag(Tags.DB_TYPE.getKey(), "sql").withTag(Tags.DB_STATEMENT.getKey(), event.getSql()).startManual());
            break;
        case EXECUTE_FAILURE:
            Span span = branchContainer.get();
            span.setTag(Tags.ERROR.getKey(), true);
            if (event.getException().isPresent()) {
                span.log(System.currentTimeMillis(), log(event.getException().get()));
            }
            finish();
            break;
        case EXECUTE_SUCCESS:
            finish();
            break;
        default:
            throw new ShardingJdbcException("Unsupported event type");
    }
}
Also used : ActiveSpan(io.opentracing.ActiveSpan) Tracer(io.opentracing.Tracer) ShardingJdbcException(io.shardingjdbc.core.exception.ShardingJdbcException) ActiveSpan(io.opentracing.ActiveSpan) Span(io.opentracing.Span)

Example 10 with Tracer

use of io.opentracing.Tracer in project sharding-jdbc by shardingjdbc.

the class ExecuteEventListener method listenOverall.

/**
 * listen overall sql execution event.
 *
 * @param event Overall sql execution event.
 */
@Subscribe
@AllowConcurrentEvents
public void listenOverall(final OverallExecutionEvent event) {
    Tracer tracer = ShardingJDBCTracer.get();
    ActiveSpan activeSpan;
    switch(event.getEventExecutionType()) {
        case BEFORE_EXECUTE:
            activeSpan = tracer.buildSpan("/SJDBC/TRUNK/" + event.getSqlType().name()).withTag(Tags.COMPONENT.getKey(), "ShardingJDBC").startActive();
            trunkContainer.set(activeSpan);
            if (isParallelExecute(event)) {
                ExecutorDataMap.getDataMap().put(SNAPSHOT_DATA_KEY, activeSpan.capture());
            }
            break;
        case EXECUTE_FAILURE:
            activeSpan = trunkContainer.get();
            activeSpan.setTag(Tags.ERROR.getKey(), true);
            if (event.getException().isPresent()) {
                activeSpan.log(System.currentTimeMillis(), log(event.getException().get()));
            }
            deactivate();
            break;
        case EXECUTE_SUCCESS:
            deactivate();
            break;
        default:
            throw new ShardingJdbcException("Unsupported event type");
    }
}
Also used : ActiveSpan(io.opentracing.ActiveSpan) Tracer(io.opentracing.Tracer) ShardingJdbcException(io.shardingjdbc.core.exception.ShardingJdbcException) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Tracer (io.opentracing.Tracer)104 Span (io.opentracing.Span)49 SpanContext (io.opentracing.SpanContext)30 Map (java.util.Map)21 Vertx (io.vertx.core.Vertx)19 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 Test (org.junit.jupiter.api.Test)19 Future (io.vertx.core.Future)18 Buffer (io.vertx.core.buffer.Buffer)16 HttpURLConnection (java.net.HttpURLConnection)14 EventBus (io.vertx.core.eventbus.EventBus)13 JsonObject (io.vertx.core.json.JsonObject)12 Objects (java.util.Objects)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tags (io.opentracing.tag.Tags)9 Scope (io.opentracing.Scope)8 GlobalTracer (io.opentracing.util.GlobalTracer)8