Java Code Examples for brave.propagation.Propagation.Setter

The following examples show how to use brave.propagation.Propagation.Setter. 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
Source Project: brave   Source File: InjectorFactory.java    License: 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 2
Source Project: brave   Source File: StringPropagationAdapterTest.java    License: 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 3
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 Project: cxf   Source File: AbstractBraveClientProvider.java    License: 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 Project: brave   Source File: InjectorFactoryTest.java    License: 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
private Setter<Invocation, String> injector() {
  return (invocation, key, value) -> invocation.getContext().put(key, value);
}
 
Example 7
Source Project: zipkin-aws   Source File: AWSInjector.java    License: Apache License 2.0 4 votes vote down vote up
AWSInjector(AWSPropagation propagation, Setter<R, String> setter) {
  this.propagation = propagation;
  this.setter = setter;
}
 
Example 8
Source Project: brave-opentracing   Source File: TextMapSetterTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override protected Setter<TextMap, String> setter() {
  return TextMap::put;
}
 
Example 9
Source Project: brave   Source File: URLConnectionSetterTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override protected Setter<URLConnection, String> setter() {
  return URLConnection::setRequestProperty;
}
 
Example 10
Source Project: brave   Source File: InjectorFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override public <R> void inject(Setter<R, String> setter, TraceContext context, R request) {
}
 
Example 11
Source Project: brave   Source File: InjectorFactory.java    License: 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 12
Source Project: brave   Source File: InjectorFactory.java    License: 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 Project: brave   Source File: InjectorFactory.java    License: Apache License 2.0 4 votes vote down vote up
RemoteInjector(Setter<R, String> setter, InjectorFunction injectorFunction) {
  this.injectorFunction = injectorFunction;
  this.setter = setter;
}
 
Example 14
Source Project: brave   Source File: InjectorFactory.java    License: 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 15
Source Project: brave   Source File: StringPropagationAdapterTest.java    License: 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 16
Source Project: brave   Source File: RpcClientRequestSetterTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override protected Setter<RpcClientRequest, String> setter() {
  return SETTER;
}
 
Example 17
Source Project: brave   Source File: HttpClientRequestSetterTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override protected Setter<HttpClientRequest, String> setter() {
  return SETTER;
}