Java Code Examples for io.opentracing.Span#finish()

The following examples show how to use io.opentracing.Span#finish() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 6 votes vote down vote up
@Override
@Deprecated
public List<V> zrangebylex(K key, String min, String max, long offset, long count) {
  Span span = helper.buildSpan("zrangebylex", key);
  span.setTag("min", min);
  span.setTag("max", max);
  span.setTag("offset", offset);
  span.setTag("count", count);
  try {
    return commands.zrangebylex(key, min, max, offset, count);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 2
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public KeyValue<K, V> blpop(long timeout, K... keys) {
  Span span = helper.buildSpan("blpop", keys);
  span.setTag("timeout", timeout);
  try {
    return commands.blpop(timeout, keys);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 3
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void psubscribe(JedisPubSub jedisPubSub, String... patterns) {
  Span span = helper.buildSpan("psubscribe");
  span.setTag("patterns", Arrays.toString(patterns));
  try {
    super.psubscribe(jedisPubSub, patterns);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 4
Source File: TracingRedisAsyncCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isOpen() {
  Span span = helper.buildSpan("isOpen");
  try {
    return commands.isOpen();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 5
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public String slaveofNoOne() {
  Span span = helper.buildSpan("slaveofNoOne");
  try {
    return commands.slaveofNoOne();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 6
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public String clusterNodes() {
  Span span = helper.buildSpan("clusterNodes");
  try {
    return commands.clusterNodes();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 7
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long zadd(K key, ScoredValue<V>... scoredValues) {
  Span span = helper.buildSpan("zadd", key);
  try {
    return commands.zadd(key, scoredValues);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 8
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<V> zrange(K key, long start, long stop) {
  Span span = helper.buildSpan("zrange", key);
  span.setTag("start", start);
  span.setTag("stop", stop);
  try {
    return commands.zrange(key, start, stop);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 9
Source File: TracingRedisAsyncCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void reset() {
  Span span = helper.buildSpan("reset");
  try {
    commands.reset();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 10
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public String set(K key, V value) {
  Span span = helper.buildSpan("set", key);
  try {
    return commands.set(key, value);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 11
Source File: TracingRedisAdvancedClusterCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public String auth(String password) {
  Span span = helper.buildSpan("auth");
  try {
    return commands.auth(password);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 12
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long zcount(byte[] key, double min, double max) {
  Span span = helper.buildSpan("zcount", key);
  span.setTag("min", min);
  span.setTag("max", max);
  try {
    return super.zcount(key, min, max);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 13
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public List<V> zrevrangebyscore(K key,
    Range<? extends Number> range) {
  Span span = helper.buildSpan("zrevrangebyscore", key);
  span.setTag("range", nullable(range));
  try {
    return commands.zrevrangebyscore(key, range);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 14
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public long pfcount(String key) {
  Span span = helper.buildSpan("pfcount", key);
  try {
    return super.pfcount(key);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 15
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public StreamScanCursor hscan(
    KeyValueStreamingChannel<K, V> channel, K key,
    ScanCursor scanCursor, ScanArgs scanArgs) {
  Span span = helper.buildSpan("hscan", key);
  try {
    return commands.hscan(channel, key, scanCursor, scanArgs);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 16
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean move(K key, int db) {
  Span span = helper.buildSpan("move", key);
  span.setTag("db", db);
  try {
    return commands.move(key, db);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 17
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public V lindex(K key, long index) {
  Span span = helper.buildSpan("lindex", key);
  span.setTag("index", index);
  try {
    return commands.lindex(key, index);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 18
Source File: TracingRedisCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long zremrangebylex(K key, Range<? extends V> range) {
  Span span = helper.buildSpan("zremrangebylex", key);
  span.setTag("range", nullable(range));
  try {
    return commands.zremrangebylex(key, range);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 19
Source File: TracingRedisAsyncCommands.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void shutdown(boolean save) {
  Span span = helper.buildSpan("shutdown");
  try {
    commands.shutdown(save);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 20
Source File: PromisePropagationTest.java    From opentelemetry-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testPromiseCallback() {
  phaser.register(); // register test thread
  final AtomicReference<String> successResult1 = new AtomicReference<>();
  final AtomicReference<String> successResult2 = new AtomicReference<>();
  final AtomicReference<Throwable> errorResult = new AtomicReference<>();

  try (PromiseContext context = new PromiseContext(phaser, 3)) {
    Span parentSpan =
        tracer.buildSpan("promises").withTag(Tags.COMPONENT.getKey(), "example-promises").start();

    try (Scope parentScope = tracer.activateSpan(parentSpan)) {
      Promise<String> successPromise = new Promise<>(context, tracer);

      successPromise.onSuccess(
          s -> {
            tracer.activeSpan().log("Promised 1 " + s);
            successResult1.set(s);
            phaser.arriveAndAwaitAdvance(); // result set
          });
      successPromise.onSuccess(
          s -> {
            tracer.activeSpan().log("Promised 2 " + s);
            successResult2.set(s);
            phaser.arriveAndAwaitAdvance(); // result set
          });

      Promise<String> errorPromise = new Promise<>(context, tracer);

      errorPromise.onError(
          t -> {
            errorResult.set(t);
            phaser.arriveAndAwaitAdvance(); // result set
          });

      assertThat(inMemoryTracing.getSpanExporter().getFinishedSpanItems().size()).isEqualTo(0);
      successPromise.success("success!");
      errorPromise.error(new Exception("some error."));
    } finally {
      parentSpan.finish();
    }

    phaser.arriveAndAwaitAdvance(); // wait for results to be set
    assertThat(successResult1.get()).isEqualTo("success!");
    assertThat(successResult2.get()).isEqualTo("success!");
    assertThat(errorResult.get()).hasMessageThat().isEqualTo("some error.");

    phaser.arriveAndAwaitAdvance(); // wait for traces to be reported

    List<SpanData> finished = inMemoryTracing.getSpanExporter().getFinishedSpanItems();
    assertThat(finished.size()).isEqualTo(4);

    String component = Tags.COMPONENT.getKey();
    List<SpanData> spanExamplePromise = getByAttr(finished, component, "example-promises");
    assertThat(spanExamplePromise).hasSize(1);
    assertThat(spanExamplePromise.get(0).getParentSpanId()).isEqualTo(SpanId.getInvalid());

    assertThat(getByAttr(finished, component, "success")).hasSize(2);

    SpanId parentId = spanExamplePromise.get(0).getSpanId();
    for (SpanData span : getByAttr(finished, component, "success")) {
      assertThat(span.getParentSpanId()).isEqualTo(parentId);
    }

    List<SpanData> spanError = getByAttr(finished, component, "error");
    assertThat(spanError).hasSize(1);
    assertThat(spanError.get(0).getParentSpanId()).isEqualTo(parentId);
  }
}