Java Code Examples for io.opentracing.Span

The following examples show how to use io.opentracing.Span. These examples are extracted from open source projects. 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
@Override
@Deprecated
public Long zrangebyscore(ValueStreamingChannel<V> channel, K key,
    String min, String max) {
  Span span = helper.buildSpan("zrangebyscore", key);
  span.setTag("min", min);
  span.setTag("max", max);
  try {
    return commands.zrangebyscore(channel, key, min, max);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 2
Source Project: opentracing-java   Source File: ErrorReportingTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCallbackError() {
    final Span span = tracer.buildSpan("one").start();
    executor.submit(new Runnable() {
        @Override
        public void run() {
            try (Scope scope = tracer.activateSpan(span)) {
                throw new RuntimeException("Invalid state");
            } catch (Exception exc) {
                Tags.ERROR.set(span, true);
            } finally {
                span.finish();
            }
        }
    });

    await().atMost(5, TimeUnit.SECONDS).until(finishedSpansSize(tracer), equalTo(1));

    List<MockSpan> spans = tracer.finishedSpans();
    assertEquals(spans.size(), 1);
    assertEquals(spans.get(0).tags().get(Tags.ERROR.getKey()), true);
}
 
Example 3
@Override
public List<ScoredValue<V>> zrangebyscoreWithScores(K key,
    Range<? extends Number> range, Limit
    limit) {
  Span span = helper.buildSpan("zrangebyscoreWithScores", key);
  span.setTag("range", range == null ? "null" : range.toString());
  span.setTag("limit", limit == null ? "null" : limit.toString());
  try {
    return commands.zrangebyscoreWithScores(key, range, limit);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 4
Source Project: thorntail   Source File: TracingContextProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public MiniConProp.ContextSnapshot capture() {
    Tracer tracer = GlobalTracer.get();
    ScopeManager scopeManager = tracer.scopeManager();
    Scope activeScope = scopeManager.active();

    if (activeScope != null) {
        Span span = activeScope.span();
        return () -> {
            Scope propagated = scopeManager.activate(span, false);
            return propagated::close;
        };
    }

    return MiniConProp.ContextSnapshot.NOOP;
}
 
Example 5
Source Project: nakadi   Source File: SubscriptionService.java    License: MIT License 6 votes vote down vote up
public ItemsWrapper<SubscriptionEventTypeStats> getSubscriptionStat(final String subscriptionId,
                                                                    final StatsMode statsMode,
                                                                    final Span span)
        throws InconsistentStateException, NoSuchEventTypeException,
        NoSuchSubscriptionException, ServiceTemporarilyUnavailableException {
    final Subscription subscription;
    try {
        subscription = subscriptionRepository.getSubscription(subscriptionId);
        authorizationValidator.authorizeSubscriptionView(subscription);
    } catch (final ServiceTemporarilyUnavailableException ex) {
        TracingService.logErrorInSpan(span, ex);
        throw new InconsistentStateException(ex.getMessage());
    }
    final List<SubscriptionEventTypeStats> subscriptionStat = createSubscriptionStat(subscription, statsMode);
    return new ItemsWrapper<>(subscriptionStat);
}
 
Example 6
@Override
public void onPreHandle(HttpServletRequest httpServletRequest, Object handler, Span span) {
  Map<String, Object> logs = new HashMap<>(3);
  logs.put("event", "preHandle");
  logs.put(HandlerUtils.HANDLER, handler);

  String metaData = HandlerUtils.className(handler);
  if (metaData != null) {
    logs.put(HandlerUtils.HANDLER_CLASS_NAME, metaData);
  }

  metaData = HandlerUtils.methodName(handler);
  if (metaData != null) {
    logs.put(HandlerUtils.HANDLER_METHOD_NAME, metaData);
  }

  span.log(logs);
}
 
Example 7
@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 8
Source Project: java-redis-client   Source File: TracingJedisCluster.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<byte[]> srandmember(byte[] key, int count) {
  Span span = helper.buildSpan("srandmember", key);
  span.setTag("count", count);
  try {
    return super.srandmember(key, count);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 9
@Override
@Deprecated
public RedisFuture<Long> zrangebyscore(
    ValueStreamingChannel<V> channel, K key, String min,
    String max, long offset, long count) {
  Span span = helper.buildSpan("zrangebyscore", key);
  span.setTag("min", min);
  span.setTag("max", max);
  span.setTag("offset", offset);
  span.setTag("count", count);
  return prepareRedisFuture(commands.zrangebyscore(channel, key, min, max, offset, count), span);
}
 
Example 10
Source Project: opentracing-toolbox   Source File: LogInterceptor.java    License: MIT License 5 votes vote down vote up
@CheckReturnValue
default Collection<Log> intercept(
        final Span span,
        final long timestamp,
        final Map<String, ?> fields) {

    return singleton(Log.of(timestamp, fields));
}
 
Example 11
Source Project: java-redis-client   Source File: TracingRScoredSortedSet.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RFuture<Integer> sortToAsync(String destName, SortOrder order) {
  Span span = tracingRedissonHelper.buildSpan("sortToAsync", set);
  span.setTag("destName", nullable(destName));
  span.setTag("order", nullable(order));
  return tracingRedissonHelper.prepareRFuture(span, () -> set.sortToAsync(destName, order));
}
 
Example 12
Source Project: hono   Source File: AbstractRegistrationService.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private Future<RegistrationResult> createSuccessfulRegistrationResult(
        final String tenantId,
        final String deviceId,
        final JsonObject deviceData,
        final Span span) {
    return getAssertionPayload(tenantId, deviceId, deviceData, span)
            .compose(payload -> Future.succeededFuture(RegistrationResult.from(
                    HttpURLConnection.HTTP_OK,
                    payload,
                    getRegistrationAssertionCacheDirective(deviceId, tenantId))))
            .recover(thr -> Future.succeededFuture(RegistrationResult.from(ServiceInvocationException.extractStatusCode(thr))));
}
 
Example 13
@Override
public RedisFuture<List<V>> zrange(K key, long start, long stop) {
  Span span = helper.buildSpan("zrange", key);
  span.setTag("start", start);
  span.setTag("stop", stop);
  return prepareRedisFuture(commands.zrange(key, start, stop), span);
}
 
Example 14
Source Project: java-redis-client   Source File: TracingRMultimap.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RFuture<Boolean> removeAsync(Object key, Object value) {
  Span span = tracingRedissonHelper.buildSpan("removeAsync", map);
  span.setTag("key", nullable(key));
  span.setTag("value", nullable(value));
  return tracingRedissonHelper.prepareRFuture(span, () -> map.removeAsync(key, value));
}
 
Example 15
Source Project: java-redis-client   Source File: TracingRedisCommands.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Boolean hsetnx(K key, K field, V value) {
  Span span = helper.buildSpan("hsetnx", key);
  try {
    return commands.hsetnx(key, field, value);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 16
@Override
public RedisFuture<String> migrate(String host, int port, int db, long timeout,
    MigrateArgs<K> migrateArgs) {
  Span span = helper.buildSpan("migrate");
  span.setTag("host", host);
  span.setTag("port", port);
  span.setTag("db", db);
  span.setTag("timeout", timeout);
  return prepareRedisFuture(commands.migrate(host, port, db, timeout, migrateArgs), span);
}
 
Example 17
Source Project: java-redis-client   Source File: TracingJedisCluster.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<String> blpop(int timeout, String... keys) {
  Span span = helper.buildSpan("blpop", keys);
  span.setTag("timeout", timeout);
  try {
    return super.blpop(timeout, keys);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 18
Source Project: java-redis-client   Source File: TracingJedisCluster.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Boolean getbit(String key, long offset) {
  Span span = helper.buildSpan("getbit", key);
  span.setTag("offset", offset);
  try {
    return super.getbit(key, offset);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 19
Source Project: java-redis-client   Source File: TracingRedisCommands.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String ltrim(K key, long start, long stop) {
  Span span = helper.buildSpan("ltrim", key);
  span.setTag("start", start);
  span.setTag("stop", stop);
  try {
    return commands.ltrim(key, start, stop);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 20
Source Project: java-redis-client   Source File: TracingRedisCommands.java    License: 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 21
Source Project: hono   Source File: DelegatedCommandSenderImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private Future<ProtonDelivery> runSendAndWaitForOutcomeOnContext(final Message rawMessage, final Span span) {
    return connection.executeOnContext(result -> {
        if (sender.sendQueueFull()) {
            final ServiceInvocationException e = new ServerErrorException(HttpURLConnection.HTTP_UNAVAILABLE, "no credit available");
            logMessageSendingError("error sending message [ID: {}, address: {}], no credit available",
                    rawMessage.getMessageId(), getMessageAddress(rawMessage));
            logError(span, e);
            span.finish();
            result.fail(e);
        } else {
            sendMessageAndWaitForOutcome(rawMessage, span).onComplete(result);
        }
    });
}
 
Example 22
@Override
public Long sunionstore(K destination, K... keys) {
  Span span = helper.buildSpan("sunionstore", keys);
  try {
    return commands.sunionstore(destination, keys);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 23
@Override
public String clusterReset(boolean hard) {
  Span span = helper.buildSpan("clusterReset");
  span.setTag("hard", hard);
  try {
    return commands.clusterReset(hard);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 24
@Override
public void debugSegfault() {
  Span span = helper.buildSpan("debugSegfault");
  try {
    commands.debugSegfault();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 25
@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 26
@Override
public void channelRead(final ChannelHandlerContext handlerContext, final Object message) {
  if (!(message instanceof HttpRequest)) {
    handlerContext.fireChannelRead(message);
    return;
  }

  final HttpRequest request = (HttpRequest)message;
  final Tracer tracer = GlobalTracer.get();

  final SpanBuilder spanBuilder = tracer.buildSpan(request.method().name())
    .withTag(Tags.COMPONENT, "netty")
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER)
    .withTag(Tags.HTTP_METHOD, request.method().name())
    .withTag(Tags.HTTP_URL, request.uri());

  final SpanContext spanContext = tracer.extract(Builtin.HTTP_HEADERS, new NettyExtractAdapter(request.headers()));
  if (spanContext != null)
    spanBuilder.asChildOf(spanContext);

  final Span span = spanBuilder.start();
  try (final Scope scope = tracer.activateSpan(span)) {
    handlerContext.channel().attr(SERVER_ATTRIBUTE_KEY).set(span);

    try {
      handlerContext.fireChannelRead(message);
    }
    catch (final Throwable t) {
      OpenTracingApiUtil.setErrorTag(span, t);
      span.finish();
      throw t;
    }
  }
}
 
Example 27
@Override
public void reset() {
  Span span = helper.buildSpan("reset");
  try {
    commands.reset();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 28
@Override
public String flushdb() {
  Span span = helper.buildSpan("flushdb");
  try {
    return commands.flushdb();
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example 29
Source Project: opentracing-toolbox   Source File: SpanDecorator.java    License: MIT License 5 votes vote down vote up
@Override
default void onRequest(
        final HttpServletRequest request,
        final Span span) {

    // nothing to do
}
 
Example 30
private <T> RedisFuture<T> continueScopeSpan(RedisFuture<T> redisFuture) {
  Tracer tracer = tracingConfiguration.getTracer();
  Span span = tracer.activeSpan();
  CompletableRedisFuture<T> customRedisFuture = new CompletableRedisFuture<>(redisFuture);
  redisFuture.whenComplete((v, throwable) -> {
    try (Scope ignored = tracer.scopeManager().activate(span)) {
      if (throwable != null) {
        customRedisFuture.completeExceptionally(throwable);
      } else {
        customRedisFuture.complete(v);
      }
    }
  });
  return customRedisFuture;
}