Java Code Examples for brave.Span.Kind#SERVER

The following examples show how to use brave.Span.Kind#SERVER . 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: BraveSpan.java    From brave-opentracing with Apache License 2.0 6 votes vote down vote up
@Nullable static Kind trySetKind(String key, String value) {
  if (!Tags.SPAN_KIND.getKey().equals(key)) return null;

  Kind kind;
  if (Tags.SPAN_KIND_CLIENT.equals(value)) {
    kind = Kind.CLIENT;
  } else if (Tags.SPAN_KIND_SERVER.equals(value)) {
    kind = Kind.SERVER;
  } else if (Tags.SPAN_KIND_PRODUCER.equals(value)) {
    kind = Kind.PRODUCER;
  } else if (Tags.SPAN_KIND_CONSUMER.equals(value)) {
    kind = Kind.CONSUMER;
  } else {
    return null;
  }
  return kind;
}
 
Example 2
Source File: TraceFilterWebIntegrationTests.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Bean
SpanHandler uncaughtExceptionThrown(CurrentTraceContext currentTraceContext) {
	return new SpanHandler() {
		@Override
		public boolean end(TraceContext context, MutableSpan span, Cause cause) {
			if (span.kind() != Kind.SERVER || span.error() == null
					|| !log.isErrorEnabled()) {
				return true; // don't add overhead as we only log server errors
			}

			// In TracingFilter, the exception is raised in scope. This is is more
			// explicit to ensure it works in other tech such as WebFlux.
			try (Scope scope = currentTraceContext.maybeScope(context)) {
				log.error("Uncaught exception thrown", span.error());
			}
			return true;
		}

		@Override
		public String toString() {
			return "UncaughtExceptionThrown";
		}
	};
}
 
Example 3
Source File: OpenTracing0_33_BraveSpanTest.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
@DataProvider
public static Object[][] dataProviderKind() {
  return new Object[][] {
      {Tags.SPAN_KIND_CLIENT, Kind.CLIENT},
      {Tags.SPAN_KIND_SERVER, Kind.SERVER},
      {Tags.SPAN_KIND_PRODUCER, Kind.PRODUCER},
      {Tags.SPAN_KIND_CONSUMER, Kind.CONSUMER}
  };
}
 
Example 4
Source File: TracingFilter.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
  if (!isInit) return invoker.invoke(invocation);
  TraceContext invocationContext = currentTraceContext.get();

  RpcContext rpcContext = RpcContext.getContext();
  Kind kind = rpcContext.isProviderSide() ? Kind.SERVER : Kind.CLIENT;
  Span span;
  DubboRequest request;
  if (kind.equals(Kind.CLIENT)) {
    // When A service invoke B service, then B service then invoke C service, the parentId of the
    // C service span is A when read from invocation.getAttachments(). This is because
    // AbstractInvoker adds attachments via RpcContext.getContext(), not the invocation.
    // See org.apache.dubbo.rpc.protocol.AbstractInvoker(line 141) from v2.7.3
    Map<String, String> attachments = RpcContext.getContext().getAttachments();
    DubboClientRequest clientRequest = new DubboClientRequest(invoker, invocation, attachments);
    request = clientRequest;
    span = clientHandler.handleSendWithParent(clientRequest, invocationContext);
  } else {
    DubboServerRequest serverRequest = new DubboServerRequest(invoker, invocation);
    request = serverRequest;
    span = serverHandler.handleReceive(serverRequest);
  }

  boolean isSynchronous = true;
  Scope scope = currentTraceContext.newScope(span.context());
  Result result = null;
  Throwable error = null;
  try {
    result = invoker.invoke(invocation);
    error = result.getException();
    CompletableFuture<Object> future = rpcContext.getCompletableFuture();
    if (future != null) {
      isSynchronous = false;
      // NOTE: We don't currently instrument CompletableFuture, so callbacks will not see the
      // invocation context unless they use an executor instrumented by CurrentTraceContext
      // If we later instrument this, take care to use the correct context depending on RPC kind!
      future.whenComplete(FinishSpan.create(this, request, result, span));
    }
    return result;
  } catch (Throwable e) {
    propagateIfFatal(e);
    error = e;
    throw e;
  } finally {
    if (isSynchronous) FinishSpan.finish(this, request, result, error, span);
    scope.close();
  }
}