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);
}
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
}
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);
}
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");
}
}
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");
}
}
Aggregations