Java Code Examples for brave.propagation.TraceContext#traceIdString()

The following examples show how to use brave.propagation.TraceContext#traceIdString() . 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: JfrScopeDecorator.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override public Scope decorateScope(@Nullable TraceContext context, Scope scope) {
  if (scope == Scope.NOOP) return scope; // we only scope fields constant in the context

  ScopeEvent event = new ScopeEvent();
  if (!event.isEnabled()) return scope;

  if (context != null) {
    event.traceId = context.traceIdString();
    event.parentId = context.parentIdString();
    event.spanId = context.spanIdString();
  }

  event.begin();

  class JfrCurrentTraceContextScope implements Scope {
    @Override public void close() {
      scope.close();
      event.commit();
    }
  }
  return new JfrCurrentTraceContextScope();
}
 
Example 2
Source File: MutableSpan.java    From brave with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance from the given context, and defaults in the span.
 *
 * <p><em>Note:</em> It is unexpected to have context properties also in the span defaults. The
 * context will win in this case, as opposed to throwing an exception.
 *
 * @since 5.12
 */
public MutableSpan(TraceContext context, @Nullable MutableSpan defaults) {
  this(defaults != null ? defaults : EMPTY);
  if (context == null) throw new NullPointerException("context == null");
  // We don't call the setters as context.*IdString are well formed
  this.traceId = context.traceIdString();
  this.localRootId = context.localRootIdString();
  this.parentId = context.parentIdString();
  this.id = context.spanIdString();
  flags = 0; // don't inherit flags from the span
  if (context.debug()) setDebug();
  if (context.shared()) setShared();
}
 
Example 3
Source File: GreeterImpl.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
  TraceContext currentTraceContext = tracing != null ? tracing.currentTraceContext().get() : null;
  if (req.getName().equals("bad")) {
    responseObserver.onError(new IllegalArgumentException("bad"));
    return;
  }
  if (req.getName().equals("testerror")) {
    throw new RuntimeException("testerror");
  }
  String message = currentTraceContext != null ? currentTraceContext.traceIdString() : "";
  HelloReply reply = HelloReply.newBuilder().setMessage(message).build();
  responseObserver.onNext(reply);
  responseObserver.onCompleted();
}
 
Example 4
Source File: BraveSpanContext.java    From brave-opentracing with Apache License 2.0 4 votes vote down vote up
@Override public String toTraceId() {
  TraceContext context = extractionResult.context();
  return context != null ? context.traceIdString() : null;
}
 
Example 5
Source File: BaggageFields.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public String getValue(BaggageField field, TraceContext context) {
  return context.traceIdString();
}