brave.propagation.Propagation.Setter Java Examples

The following examples show how to use brave.propagation.Propagation.Setter. 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: StringPropagationAdapterTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void setterAdapter() {
  Map<String, Integer> map = new LinkedHashMap<>();
  map.put("1", 1);
  map.put("2", 2);

  Setter<Map<Integer, String>, String> wrappedSetter = new SetterAdapter<>(setter, map);

  Map<Integer, String> request = new LinkedHashMap<>();

  wrappedSetter.put(request, "1", "one");
  wrappedSetter.put(request, "2", "two");
  wrappedSetter.put(request, "3", "three");

  assertThat(request)
      .hasSize(2)
      .containsEntry(1, "one")
      .containsEntry(2, "two");
}
 
Example #2
Source File: InjectorFactory.java    From brave with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a potentially composite injector if the input is an instance of {@link RemoteSetter}.
 * Otherwise, a deferred injector is return that examples the request parameter to decide if it is
 * remote or not.
 */
public <R> TraceContext.Injector<R> newInjector(Setter<R, String> setter) {
  if (setter == null) throw new NullPointerException("setter == null");
  if (setter instanceof RemoteSetter) {
    RemoteSetter<?> remoteSetter = (RemoteSetter<?>) setter;
    switch (remoteSetter.spanKind()) {
      case CLIENT:
        return new RemoteInjector<>(setter, clientInjectorFunction);
      case PRODUCER:
        return new RemoteInjector<>(setter, producerInjectorFunction);
      case CONSUMER:
        return new RemoteInjector<>(setter, consumerInjectorFunction);
      default: // SERVER is nonsense as it cannot be injected
    }
  }
  return new DeferredInjector<>(setter, this);
}
 
Example #3
Source File: TracingJobListenerTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
void addSpanToJobData(JobDataMap data) {
	brave.Span span = tracing.tracer().nextSpan().start();
	try (SpanInScope spanInScope = tracing.tracer().withSpanInScope(span)) {
		tracing.propagation()
				.injector((Setter<JobDataMap, String>) StringKeyDirtyFlagMap::put)
				.inject(tracing.currentTraceContext().get(), data);
	}
	finally {
		span.finish();
	}
}
 
Example #4
Source File: AbstractBraveClientProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
private <C> Setter<C, String> inject(final Map<String, List<String>> requestHeaders) {
    return (carrier, key, value) -> {
        if (!requestHeaders.containsKey(key)) {
            requestHeaders.put(key, Collections.singletonList(value));
        }
    };
}
 
Example #5
Source File: InjectorFactoryTest.java    From brave with Apache License 2.0 5 votes vote down vote up
static InjectorFunction newInjectorFunction(String keyName, AtomicInteger callCount) {
  return new InjectorFunction() {
    @Override public List<String> keyNames() {
      return Arrays.asList(keyName);
    }

    @Override public <R> void inject(Setter<R, String> setter, TraceContext context, R request) {
      callCount.incrementAndGet();
    }
  };
}
 
Example #6
Source File: HttpClientRequestSetterTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override protected Setter<HttpClientRequest, String> setter() {
  return SETTER;
}
 
Example #7
Source File: ZipkinConsumerDelegate.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private Setter<Invocation, String> injector() {
  return (invocation, key, value) -> invocation.getContext().put(key, value);
}
 
Example #8
Source File: RpcClientRequestSetterTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override protected Setter<RpcClientRequest, String> setter() {
  return SETTER;
}
 
Example #9
Source File: StringPropagationAdapterTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Test public void setter_equalsHashCodeString() {
  assertDelegates(
      () -> mock(Setter.class),
      g -> new SetterAdapter<>(g, Collections.emptyMap())
  );
}
 
Example #10
Source File: InjectorFactory.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public <R> void inject(Setter<R, String> setter, TraceContext context, R request) {
  for (InjectorFunction injectorFunction : injectorFunctions) {
    injectorFunction.inject(setter, context, request);
  }
}
 
Example #11
Source File: InjectorFactory.java    From brave with Apache License 2.0 4 votes vote down vote up
RemoteInjector(Setter<R, String> setter, InjectorFunction injectorFunction) {
  this.injectorFunction = injectorFunction;
  this.setter = setter;
}
 
Example #12
Source File: InjectorFactory.java    From brave with Apache License 2.0 4 votes vote down vote up
DeferredInjector(Setter<R, String> setter, InjectorFactory injectorFactory) {
  this.setter = setter;
  this.injectorFactory = injectorFactory;
}
 
Example #13
Source File: InjectorFactory.java    From brave with Apache License 2.0 4 votes vote down vote up
/** Like {@see TraceContext.Injector#inject} except the {@code setter} is explicit. */
<R> void inject(Setter<R, String> setter, TraceContext context, R request);
 
Example #14
Source File: InjectorFactory.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public <R> void inject(Setter<R, String> setter, TraceContext context, R request) {
}
 
Example #15
Source File: URLConnectionSetterTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override protected Setter<URLConnection, String> setter() {
  return URLConnection::setRequestProperty;
}
 
Example #16
Source File: TextMapSetterTest.java    From brave-opentracing with Apache License 2.0 4 votes vote down vote up
@Override protected Setter<TextMap, String> setter() {
  return TextMap::put;
}
 
Example #17
Source File: AWSInjector.java    From zipkin-aws with Apache License 2.0 4 votes vote down vote up
AWSInjector(AWSPropagation propagation, Setter<R, String> setter) {
  this.propagation = propagation;
  this.setter = setter;
}