Java Code Examples for io.opentracing.noop.NoopSpan#INSTANCE

The following examples show how to use io.opentracing.noop.NoopSpan#INSTANCE . 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: JdbcTracingUtils.java    From java-jdbc with Apache License 2.0 6 votes vote down vote up
static Span buildSpan(String operationName,
    String sql,
    ConnectionInfo connectionInfo,
    boolean withActiveSpanOnly,
    Set<String> ignoredStatements,
    Tracer tracer) {
  if (!TracingDriver.isTraceEnabled() || (withActiveSpanOnly && tracer.activeSpan() == null)) {
    return NoopSpan.INSTANCE;
  } else if (ignoredStatements != null && ignoredStatements.contains(sql)) {
    return NoopSpan.INSTANCE;
  }

  Tracer.SpanBuilder spanBuilder = tracer.buildSpan(operationName)
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);

  Span span = spanBuilder.start();
  decorate(span, sql, connectionInfo);

  return span;
}
 
Example 2
Source File: OpenCensusTracerAdapter.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public Span activeSpan() {
  io.opencensus.trace.Span inner = ocTracer.getCurrentSpan();
  if (inner == null) {
    return null;
  }

  // An open census blank span is never sampled.
  // Moreover, gRPC creates non-blank spans even though it doesn't want to sample them.
  // The default policy is to inherit the sampling policy from the parent span.
  // Therefore, gRPC spans will not be sampled when we create blank parents.
  // Further reading:
  // https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/Sampling.md
  final boolean shouldNotSample = !inner.getContext().getTraceOptions().isSampled();

  // Our traces will not sample if we use a noop.
  return shouldNotSample ? NoopSpan.INSTANCE : new OpenCensusSpanAdapter(inner);
}
 
Example 3
Source File: TracingHelper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public Span buildSpan(String operationName, byte[][] keys) {
  if (traceWithActiveSpanOnly && tracer.activeSpan() == null) {
    return NoopSpan.INSTANCE;
  } else {
    return builder(operationName)
        .withTag("keys", toString(keys))
        .start();
  }
}
 
Example 4
Source File: TracingHelper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public Span buildSpan(String operationName) {
  if (traceWithActiveSpanOnly && tracer.activeSpan() == null) {
    return NoopSpan.INSTANCE;
  } else {
    return builder(operationName).start();
  }
}
 
Example 5
Source File: TracingHelper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public Span buildSpan(String operationName, Object key) {
  if (traceWithActiveSpanOnly && tracer.activeSpan() == null) {
    return NoopSpan.INSTANCE;
  } else {
    return builder(operationName).withTag("key", nullable(key)).start();
  }
}
 
Example 6
Source File: TracingHelper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public Span buildSpan(String operationName, byte[] key) {
  if (traceWithActiveSpanOnly && tracer.activeSpan() == null) {
    return NoopSpan.INSTANCE;
  } else {
    return builder(operationName).withTag("key", Arrays.toString(key))
        .start();
  }
}
 
Example 7
Source File: TracingHelper.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
public Span buildSpan(String operationName, Object[] keys) {
  if (traceWithActiveSpanOnly && tracer.activeSpan() == null) {
    return NoopSpan.INSTANCE;
  } else {
    return builder(operationName).withTag("keys",
        Arrays.toString(limitKeys(keys))).start();
  }
}
 
Example 8
Source File: ServerTracingDynamicFeature.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void filter(ContainerRequestContext containerRequestContext) {
  // Check if there is already a Span context.
  if(TracingUtils.getResourceSpan(containerRequestContext).isPresent()) {
    return;
  }

  // Check if there is an existing span to join.
  final MultivaluedMap<String, String> headers = containerRequestContext.getHeaders();
  final SpanContext parentSpanContext = tracer.extract(Format.Builtin.HTTP_HEADERS, new RequestHeaderTextMap(headers));
  final boolean shouldTrace = Boolean.parseBoolean(headers.getFirst(TracingUtils.TRACING_HEADER));

  final Span span;
  if ((parentSpanContext == null || parentSpanContext instanceof NoopSpanContext) && !shouldTrace) {
    span = NoopSpan.INSTANCE;
  } else {
    span = tracer.buildSpan("http-request")
      .ignoreActiveSpan()
      .asChildOf(parentSpanContext)
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
      .withTag(Tags.HTTP_METHOD.getKey(), containerRequestContext.getMethod())
      .withTag(Tags.HTTP_URL.getKey(), containerRequestContext.getUriInfo().getRequestUri().toASCIIString())
      .start();
  }

  containerRequestContext.setProperty(TracingUtils.SPAN_CONTEXT_PROPERTY, new SpanHolder(span, tracer.activateSpan(span)));
}
 
Example 9
Source File: DeviceRegistryTokenAuthProvider.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private Span extractSpan(final JsonObject authInfo, final String operationName) {
    final Span span;
    final SpanContext context = TracingHelper.extractSpanContext(this.tracer, authInfo);
    if (context != null) {
        span = TracingHelper
                .buildChildSpan(this.tracer, context, operationName, getClass().getSimpleName())
                .start();
    } else {
        span = NoopSpan.INSTANCE;
    }
    return span;
}
 
Example 10
Source File: TenantTraceSamplingHandler.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
private Span getTracingHandlerServerSpan(final RoutingContext ctx) {
    final Object spanObject = ctx.get(TracingHandler.CURRENT_SPAN);
    return spanObject instanceof Span ? (Span) spanObject : NoopSpan.INSTANCE;
}
 
Example 11
Source File: TracingInterceptor.java    From java-jaxrs with Apache License 2.0 3 votes vote down vote up
/**
 * Client requests :
 * <ul>
 * <li>Serialization of request body happens between the tracing filter invocation so we can use child_of.</li>
 * <li>Deserialization happens after the request is processed by the client filter therefore we can use follows_from only.</li>
 * </ul>
 * Server requests :
 * <ul>
 * <li>Deserialization happens between the span in the server filter is started and finished so we can use child_of.</li>
 * <li>Serialization of response entity happens after the server span if finished so we can use only follows_from.</li>
 * </ul>
 * @param context Used to retrieve the current span wrapper created by the jax-rs request filter.
 * @param operationName "serialize" or "deserialize" depending on the context
 * @return a noop span is no span context is registered in the context. Otherwise a new span related to the current on retrieved from the context.
 */
private Span buildSpan(InterceptorContext context, String operationName) {
    final SpanWrapper spanWrapper = findSpan(context);
    if(spanWrapper == null) {
        return NoopSpan.INSTANCE;
    }
    final Tracer.SpanBuilder spanBuilder = tracer.buildSpan(operationName);
    if(spanWrapper.isFinished()) {
        spanBuilder.addReference(References.FOLLOWS_FROM, spanWrapper.get().context());
    } else {
        spanBuilder.asChildOf(spanWrapper.get());
    }
    return spanBuilder.start();
}