Java Code Examples for brave.propagation.TraceContext#Injector
The following examples show how to use
brave.propagation.TraceContext#Injector .
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: InjectorFactory.java From brave with Apache License 2.0 | 6 votes |
/** * 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 File: DubboClientHandler.java From brave-instrumentation-dubbo with Apache License 2.0 | 5 votes |
/** * Starts the client span after assigning it a name and tags. */ public Span handleSend(TraceContext.Extractor extractor, TraceContext.Injector injector) { Span span = nextSpan(extractor.extract(RpcContext.getContext().getAttachments())); injector.inject(span.context(), RpcContext.getContext().getAttachments()); if (span.isNoop()) return span; span.kind(Span.Kind.CLIENT); Tracer.SpanInScope ws = tracer.withSpanInScope(span); try { parser.request(adapter, RpcContext.getContext(), span); } finally { ws.close(); } return span.start(); }
Example 3
Source File: PropagationTest.java From brave with Apache License 2.0 | 5 votes |
@Override public void accept(Propagation<?> propagation) { TraceContext.Injector<Map<Object, String>> injector = propagation.injector(Map::put); TraceContext.Extractor<Map<Object, String>> extractor = propagation.extractor(Map::get); TraceContext ctx = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false).build(); Map<Object, String> map = new LinkedHashMap<>(); injector.inject(ctx, map); assertThat(extractor.extract(map).context()) .isEqualToIgnoringGivenFields(ctx, "traceIdString", "spanIdString"); }
Example 4
Source File: ITKafkaTracing.java From brave with Apache License 2.0 | 4 votes |
@Override public <R> TraceContext.Injector<R> injector(Setter<R, String> setter) { return (traceContext, request) -> setter.put(request, TRACE_ID, traceContext.traceIdString()); }