Java Code Examples for brave.handler.SpanHandler#NOOP

The following examples show how to use brave.handler.SpanHandler#NOOP . 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: ZipkinAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
/** Returns one handler for as many reporters as exist. */
@Bean
SpanHandler zipkinSpanHandler(@Nullable List<Reporter<Span>> spanReporters,
		@Nullable Tag<Throwable> errorTag) {
	if (spanReporters == null) {
		return SpanHandler.NOOP;
	}

	LinkedHashSet<Reporter<Span>> reporters = new LinkedHashSet<>(spanReporters);
	reporters.remove(Reporter.NOOP);
	if (spanReporters.isEmpty()) {
		return SpanHandler.NOOP;
	}

	Reporter<Span> spanReporter = reporters.size() == 1 ? reporters.iterator().next()
			: new CompositeSpanReporter(reporters.toArray(new Reporter[0]));

	ZipkinSpanHandler.Builder builder = ZipkinSpanHandler.newBuilder(spanReporter);
	if (errorTag != null) {
		builder.errorTag(errorTag);
	}
	return builder.build();
}
 
Example 2
Source File: TraceBaggageConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Bean
SpanHandler baggageTagSpanHandler(
		@Qualifier(WHITELISTED_KEYS) List<String> whiteListedKeys,
		SleuthBaggageProperties sleuthBaggageProperties) {

	Set<String> tagFields = redirectOldPropertyToNew(WHITELISTED_KEYS,
			whiteListedKeys, "spring.sleuth.baggage.tag-fields",
			sleuthBaggageProperties.getTagFields());

	if (tagFields.isEmpty()) {
		return SpanHandler.NOOP; // Brave ignores these
	}

	return new BaggageTagSpanHandler(tagFields.stream().map(BaggageField::create)
			.toArray(BaggageField[]::new));
}
 
Example 3
Source File: PendingSpansClassLoaderTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public void run() {
  PendingSpans pendingSpans = new PendingSpans(new MutableSpan(),
    Platform.get().clock(), SpanHandler.NOOP, new AtomicBoolean());

  TraceContext context = CONTEXT.toBuilder().build(); // intentionally make a copy
  pendingSpans.getOrCreate(null, context, true);
  pendingSpans.remove(context);
}
 
Example 4
Source File: Tracing.java    From brave with Apache License 2.0 5 votes vote down vote up
/**
 * Inputs receive {code (context, span)} pairs for every {@linkplain TraceContext#sampledLocal()
 * locally sampled} span. The span is mutable for customization or redaction purposes. Span
 * handlers execute in order: If any handler returns {code false}, the next will not see the
 * span.
 *
 * @param spanHandler skipped if {@link SpanHandler#NOOP} or already added
 * @since 5.12
 */
public Builder addSpanHandler(SpanHandler spanHandler) {
  if (spanHandler == null) throw new NullPointerException("spanHandler == null");

  // Some configuration can coerce to no-op, ignore in this case.
  if (spanHandler == SpanHandler.NOOP) return this;

  if (!spanHandlers.add(spanHandler)) {
    Platform.get().log("Please check configuration as %s was added twice", spanHandler, null);
  }
  return this;
}
 
Example 5
Source File: ConvertingZipkinSpanHandler.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
@Override public SpanHandler build() {
  if (spanReporter == Reporter.NOOP) return SpanHandler.NOOP;
  return new ConvertingZipkinSpanHandler(this);
}
 
Example 6
Source File: NoopAwareSpanHandler.java    From brave with Apache License 2.0 4 votes vote down vote up
public static SpanHandler create(SpanHandler[] handlers,
    AtomicBoolean noop) {
  if (handlers.length == 0) return SpanHandler.NOOP;
  if (handlers.length == 1) return new NoopAwareSpanHandler(handlers[0], noop);
  return new NoopAwareSpanHandler(new CompositeSpanHandler(handlers), noop);
}