本文整理了Java中brave.propagation.TraceContext.findExtra()
方法的一些代码示例,展示了TraceContext.findExtra()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TraceContext.findExtra()
方法的具体详情如下:
包路径:brave.propagation.TraceContext
类名称:TraceContext
方法名:findExtra
[英]Returns an #extra() of the given type if present or null if not.
Note: it is the responsibility of Propagation.Factory#decorate(TraceContext)to consolidate extra fields. If it doesn't, there could be multiple instance of a given type and this can break logic.
[中]
代码示例来源:origin: openzipkin/brave
/** Returns the value of the field with the specified key or null if not available */
public static String get(TraceContext context, String name,
Class<? extends PropagationFields> type) {
if (context == null) throw new NullPointerException("context == null");
if (name == null) throw new NullPointerException("name == null");
PropagationFields fields = context.findExtra(type);
return fields != null ? fields.get(name) : null;
}
代码示例来源:origin: openzipkin/brave
/** Replaces the value of the field with the specified key, ignoring if not a permitted field */
public static void put(TraceContext context, String name, String value,
Class<? extends PropagationFields> type) {
if (context == null) throw new NullPointerException("context == null");
if (name == null) throw new NullPointerException("name == null");
if (value == null) throw new NullPointerException("value == null");
PropagationFields fields = context.findExtra(type);
if (fields == null) return;
fields.put(name, value);
}
}
代码示例来源:origin: openzipkin/brave
/**
* Returns an {@linkplain #extra() extra} of the given type if present or null if not.
*
* <p>Note: it is the responsibility of {@link Propagation.Factory#decorate(TraceContext)}
* to consolidate extra fields. If it doesn't, there could be multiple instance of a given type
* and this can break logic.
*/
public @Nullable <T> T findExtra(Class<T> type) {
return findExtra(type, extra);
}
代码示例来源:origin: openzipkin/brave
/** Returns a mapping of any fields in the trace context. */
public static Map<String, String> getAll(TraceContext context) {
if (context == null) throw new NullPointerException("context == null");
PropagationFields fields = context.findExtra(Extra.class);
return fields != null ? fields.toMap() : Collections.emptyMap();
}
代码示例来源:origin: openzipkin/brave
@Override public void inject(TraceContext traceContext, C carrier) {
delegate.inject(traceContext, carrier);
Extra extra = traceContext.findExtra(Extra.class);
if (extra == null) return;
inject(extra, carrier);
}
代码示例来源:origin: openzipkin/brave
/** Returns a mapping of any fields in the extraction result. */
public static Map<String, String> getAll(TraceContextOrSamplingFlags extracted) {
if (extracted == null) throw new NullPointerException("extracted == null");
TraceContext extractedContext = extracted.context();
if (extractedContext != null) return getAll(extractedContext);
PropagationFields fields = TraceContext.findExtra(Extra.class, extracted.extra());
return fields != null ? fields.toMap() : Collections.emptyMap();
}
代码示例来源:origin: openzipkin/brave
@Override public void inject(TraceContext traceContext, C carrier) {
if (carrier instanceof Metadata) {
byte[] serialized = TraceContextBinaryFormat.toBytes(traceContext);
((Metadata) carrier).put(GRPC_TRACE_BIN, serialized);
Tags tags = traceContext.findExtra(Tags.class);
if (tags != null) ((Metadata) carrier).put(GRPC_TAGS_BIN, tags.toMap());
}
delegate.inject(traceContext, carrier);
}
}
代码示例来源:origin: openzipkin/brave
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call,
final Metadata headers, final ServerCallHandler<ReqT, RespT> next) {
TraceContextOrSamplingFlags extracted = extractor.extract(headers);
Span span = extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
// If grpc propagation is enabled, make sure we refresh the server method
if (grpcPropagationFormatEnabled) {
Tags tags = span.context().findExtra(Tags.class);
if (tags != null) tags.put(RPC_METHOD, call.getMethodDescriptor().getFullMethodName());
}
span.kind(Span.Kind.SERVER);
parser.onStart(call, headers, span.customizer());
// startCall invokes user interceptors, so we place the span in scope here
ServerCall.Listener<ReqT> result;
SpanInScope scope = tracer.withSpanInScope(span);
try { // retrolambda can't resolve this try/finally
result = next.startCall(new TracingServerCall<>(span, call, parser), headers);
} catch (RuntimeException | Error e) {
span.error(e);
span.finish();
throw e;
} finally {
scope.close();
}
// This ensures the server implementation can see the span in scope
return new ScopingServerCallListener<>(tracer, span, result, parser);
}
代码示例来源:origin: io.zipkin.brave/brave
/** Replaces the value of the field with the specified key, ignoring if not a permitted field */
public static void put(TraceContext context, String name, String value,
Class<? extends PropagationFields> type) {
if (context == null) throw new NullPointerException("context == null");
if (name == null) throw new NullPointerException("name == null");
if (value == null) throw new NullPointerException("value == null");
PropagationFields fields = context.findExtra(type);
if (fields == null) return;
fields.put(name, value);
}
}
代码示例来源:origin: io.zipkin.brave/brave
/** Returns the value of the field with the specified key or null if not available */
public static String get(TraceContext context, String name,
Class<? extends PropagationFields> type) {
if (context == null) throw new NullPointerException("context == null");
if (name == null) throw new NullPointerException("name == null");
PropagationFields fields = context.findExtra(type);
return fields != null ? fields.get(name) : null;
}
代码示例来源:origin: io.zipkin.brave/brave
/** Returns a mapping of any fields in the trace context. */
public static Map<String, String> getAll(TraceContext context) {
if (context == null) throw new NullPointerException("context == null");
PropagationFields fields = context.findExtra(Extra.class);
return fields != null ? fields.toMap() : Collections.emptyMap();
}
代码示例来源:origin: io.zipkin.brave/brave
/**
* Returns an {@linkplain #extra() extra} of the given type if present or null if not.
*
* <p>Note: it is the responsibility of {@link Propagation.Factory#decorate(TraceContext)}
* to consolidate extra fields. If it doesn't, there could be multiple instance of a given type
* and this can break logic.
*/
public @Nullable <T> T findExtra(Class<T> type) {
return findExtra(type, extra);
}
代码示例来源:origin: io.zipkin.brave/brave
@Override public void inject(TraceContext traceContext, C carrier) {
delegate.inject(traceContext, carrier);
Extra extra = traceContext.findExtra(Extra.class);
if (extra == null) return;
inject(extra, carrier);
}
代码示例来源:origin: io.zipkin.brave/brave
/** Returns a mapping of any fields in the extraction result. */
public static Map<String, String> getAll(TraceContextOrSamplingFlags extracted) {
if (extracted == null) throw new NullPointerException("extracted == null");
TraceContext extractedContext = extracted.context();
if (extractedContext != null) return getAll(extractedContext);
PropagationFields fields = TraceContext.findExtra(Extra.class, extracted.extra());
return fields != null ? fields.toMap() : Collections.emptyMap();
}
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-grpc
@Override public void inject(TraceContext traceContext, C carrier) {
if (carrier instanceof Metadata) {
byte[] serialized = TraceContextBinaryFormat.toBytes(traceContext);
((Metadata) carrier).put(GRPC_TRACE_BIN, serialized);
Tags tags = traceContext.findExtra(Tags.class);
if (tags != null) ((Metadata) carrier).put(GRPC_TAGS_BIN, tags.toMap());
}
delegate.inject(traceContext, carrier);
}
}
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-grpc
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call,
final Metadata headers, final ServerCallHandler<ReqT, RespT> next) {
TraceContextOrSamplingFlags extracted = extractor.extract(headers);
Span span = extracted.context() != null
? tracer.joinSpan(extracted.context())
: tracer.nextSpan(extracted);
// If grpc propagation is enabled, make sure we refresh the server method
if (grpcPropagationFormatEnabled) {
Tags tags = span.context().findExtra(Tags.class);
if (tags != null) tags.put(RPC_METHOD, call.getMethodDescriptor().getFullMethodName());
}
span.kind(Span.Kind.SERVER);
parser.onStart(call, headers, span.customizer());
// startCall invokes user interceptors, so we place the span in scope here
ServerCall.Listener<ReqT> result;
SpanInScope scope = tracer.withSpanInScope(span);
try { // retrolambda can't resolve this try/finally
result = next.startCall(new TracingServerCall<>(span, call, parser), headers);
} catch (RuntimeException | Error e) {
span.error(e);
span.finish();
throw e;
} finally {
scope.close();
}
// This ensures the server implementation can see the span in scope
return new ScopingServerCallListener<>(tracer, span, result, parser);
}
内容来源于网络,如有侵权,请联系作者删除!