• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ServerSpan类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.github.kristofa.brave.ServerSpan的典型用法代码示例。如果您正苦于以下问题:Java ServerSpan类的具体用法?Java ServerSpan怎么用?Java ServerSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ServerSpan类属于com.github.kristofa.brave包,在下文中一共展示了ServerSpan类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getNextService

点赞 3

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
/**
 * This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a REST endpoint with
 * Hystrix fallback support.
 *
 * @return The feign pointing to the service URL and with Hystrix fallback.
 */
private NamasteService getNextService() {
    final String serviceName = "namaste";
    // This stores the Original/Parent ServerSpan from ZiPkin.
    final ServerSpan serverSpan = brave.serverSpanThreadBinder().getCurrentServerSpan();
    final CloseableHttpClient httpclient =
        HttpClients.custom()
            .addInterceptorFirst(new BraveHttpRequestInterceptor(brave.clientRequestInterceptor(), new DefaultSpanNameProvider()))
            .addInterceptorFirst(new BraveHttpResponseInterceptor(brave.clientResponseInterceptor()))
            .build();
    String url = String.format("http://%s:8080/", serviceName);
    return HystrixFeign.builder()
        // Use apache HttpClient which contains the ZipKin Interceptors
        .client(new ApacheHttpClient(httpclient))
        // Bind Zipkin Server Span to Feign Thread
        .requestInterceptor((t) -> brave.serverSpanThreadBinder().setCurrentSpan(serverSpan))
        .logger(new Logger.ErrorLogger()).logLevel(Level.BASIC)
        .decoder(new JacksonDecoder())
        .target(NamasteService.class, url,
            () -> Collections.singletonList("Namaste response (fallback)"));
}
 

开发者ID:redhat-helloworld-msa,
项目名称:hello,
代码行数:27,
代码来源:HelloResource.java

示例2: apply

点赞 3

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
@Override
public Runnable apply(Context context, Runnable runnable) {
  final ServerSpan serverSpan = serverSpanThreadBinder.getCurrentServerSpan();
  final Span clientSpan = clientSpanThreadBinder.getCurrentClientSpan();
  final Map<String, String> dc = LoggingDC.getCopyOfContextMap();

  if (logger.isDebugEnabled() && (serverSpan.getSpan() != null || clientSpan != null)) {
    logger.debug("scheduled: client={}, server={}, context={}", clientSpan, serverSpan, context);
  }
  return () -> {
    LoggingDC.setContextMap(dc);
    if (logger.isDebugEnabled() && (serverSpan.getSpan() != null || clientSpan != null)) {
      logger.debug("executing: client={}, server={}, context={}", clientSpan, serverSpan, context);
    }
    serverSpanThreadBinder.setCurrentSpan(serverSpan);
    clientSpanThreadBinder.setCurrentSpan(clientSpan);
    try {
      runnable.run();
    } finally {
      serverSpanThreadBinder.setCurrentSpan(null);
      clientSpanThreadBinder.setCurrentSpan(null);
      LoggingDC.removeAll();
    }
  };
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:26,
代码来源:ZipkinSchedulerInterceptor.java

示例3: handle

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
@Override
public void handle(RoutingContext context) {
  final HttpServerRequest req = context.request();

  requestInterceptor.handle(new ZipkinWebServerRequestAdapter(new ZipkinHttpServerRequest(req), spanNameProvider));
  final ServerSpan span = spanThreadBinder.getCurrentServerSpan();

  LoggingDC.put(span);

  if (logger.isDebugEnabled()) {
    logger.debug("Request.Started ({}): {} {} [{}]", span, req.method(), req.absoluteURI());
  }
  context.addHeadersEndHandler(v -> {
    if (span.getSample()) {
      context.response().putHeader(HTTP_HEADER_TRACE_ID, LoggingDC.toHexString(span.getSpan().getTrace_id()));
    }
  });

  context.addBodyEndHandler(v -> {
    if (logger.isDebugEnabled()) {
      logger.debug("Request.Completed ({}): {} {}", span, req.method(), req.absoluteURI());
    }
    spanThreadBinder.setCurrentSpan(span);
    responseInterceptor.handle(new ZipkinWebServerResponseAdapter(context));
    LoggingDC.removeAll();
  });
  context.next();
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:29,
代码来源:ZipkinWebHandler.java

示例4: put

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
public static void put(final ServerSpan serverSpan) {
  if (serverSpan.getSpan() != null) {
    put(serverSpan.getSpan());
  } else {
    removeAll();
  }
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:8,
代码来源:LoggingDC.java

示例5: clientSend

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
/**
 * Start a Client Send span
 *
 * Note: we save both the current client and overarching server spans in order to re-apply on the
 * response.
 */
private void clientSend(final Message msg) {
  requestInterceptor.handle(new ZipkinEventBusClientRequestAdapter(msg));
  final ServerSpan serverSpan = serverSpanThreadBinder.getCurrentServerSpan();
  final Span span = spanThreadBinder.getCurrentClientSpan();

  if (logger.isDebugEnabled()) {
    logger.debug("Client.Send ({}): address={}, reply={}, headers={}", span, msg.address(), msg.replyAddress(), msg.headers());
  }

  // We're exploiting the eventbus impl which generates reply addresses into the local jvm.
  // This would be a problem if clients were able to dictate specific reply addresses. :(
  pendingRequests.put(msg.replyAddress(), new SpanContext(serverSpan, span));
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:20,
代码来源:ZipkinEventBusClientInterceptor.java

示例6: clientReceive

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
private void clientReceive(final ServerSpan serverSpan, final Span span, final Message msg) {
  serverSpanThreadBinder.setCurrentSpan(serverSpan);
  spanThreadBinder.setCurrentSpan(span);
  responseInterceptor.handle(new ZipkinEventBusClientResponseAdapter(msg));

  // Re-establish the logging context once we continue with processing the response.
  LoggingDC.put(span);

  if (logger.isDebugEnabled()) {
    logger.debug("Client.Receive ({}): address={}, reply={}, headers={}", span, msg.address(), msg.replyAddress(), msg.headers());
  }
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:13,
代码来源:ZipkinEventBusClientInterceptor.java

示例7: handle

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
@Override
public void handle(SendContext context) {
  final Message msg = context.message();

  // We see all send()'s so ignore those we know are not server responses
  if (context.send() && msg.replyAddress() == null) {
    // If we have a span for the expected address (formerly, the replyAddress) then we can close out the span.
    final ServerSpan span = pendingResponses.remove(msg.address());
    if (span != null) {
      serverRespond(span, msg);
    }
  }
  context.next();
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:15,
代码来源:ZipkinEventBusServerInterceptor.java

示例8: serverReceive

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
private void serverReceive(final Message msg) {
  requestInterceptor.handle(new ZipkinEventBusServerRequestAdapter(msg));
  final ServerSpan span = spanThreadBinder.getCurrentServerSpan();

  LoggingDC.put(span);

  if (logger.isDebugEnabled()) {
    logger.debug("Server.Receive ({}): address={}, reply={}, headers={}", span, msg.address(), msg.replyAddress(), msg.headers());
  }

  pendingResponses.put(msg.replyAddress(), span);
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:13,
代码来源:ZipkinEventBusServerInterceptor.java

示例9: serverRespond

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
private void serverRespond(final ServerSpan span, final Message msg) {
  if (logger.isDebugEnabled()) {
    logger.debug("Server.Respond ({}): address={}, reply={}, headers={}", span, msg.address(), msg.replyAddress(), msg.headers());
  }

  spanThreadBinder.setCurrentSpan(span);
  responseInterceptor.handle(new ZipkinEventBusServerResponseAdapter(msg));

  LoggingDC.removeAll();
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:11,
代码来源:ZipkinEventBusServerInterceptor.java

示例10: clientRequest

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
private void clientRequest(Brave brave, String serviceName, ExchangeSendingEvent event) {
    ClientSpanThreadBinder clientBinder = brave.clientSpanThreadBinder();
    ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();

    // reuse existing span if we do multiple requests from the same
    ZipkinState state = event.getExchange().getProperty(ZipkinState.KEY, ZipkinState.class);
    if (state == null) {
        state = new ZipkinState();
        event.getExchange().setProperty(ZipkinState.KEY, state);
    }
    // if we started from a server span then lets reuse that when we call a downstream service
    ServerSpan last = state.peekServerSpan();
    if (last != null) {
        serverBinder.setCurrentSpan(last);
    }

    brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(this, serviceName, event.getExchange(), event.getEndpoint()));

    // store span after request
    Span span = clientBinder.getCurrentClientSpan();
    state.pushClientSpan(span);
    // and reset binder
    clientBinder.setCurrentSpan(null);
    serverBinder.setCurrentSpan(null);

    if (span != null && LOG.isDebugEnabled()) {
        String traceId = "" + span.getTrace_id();
        String spanId = "" + span.getId();
        String parentId = span.getParent_id() != null ? "" + span.getParent_id() : null;
        if (LOG.isDebugEnabled()) {
            if (parentId != null) {
                LOG.debug(String.format("clientRequest [service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
            } else {
                LOG.debug(String.format("clientRequest [service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
            }
        }
    }
}
 

开发者ID:HydAu,
项目名称:Camel,
代码行数:39,
代码来源:ZipkinTracer.java

示例11: serverRequest

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
private ServerSpan serverRequest(Brave brave, String serviceName, Exchange exchange) {
    ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();

    // reuse existing span if we do multiple requests from the same
    ZipkinState state = exchange.getProperty(ZipkinState.KEY, ZipkinState.class);
    if (state == null) {
        state = new ZipkinState();
        exchange.setProperty(ZipkinState.KEY, state);
    }
    // if we started from a another server span then lets reuse that
    ServerSpan last = state.peekServerSpan();
    if (last != null) {
        serverBinder.setCurrentSpan(last);
    }

    brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(this, exchange));

    // store span after request
    ServerSpan span = serverBinder.getCurrentServerSpan();
    state.pushServerSpan(span);
    // and reset binder
    serverBinder.setCurrentSpan(null);

    if (span != null && span.getSpan() != null && LOG.isDebugEnabled()) {
        String traceId = "" + span.getSpan().getTrace_id();
        String spanId = "" + span.getSpan().getId();
        String parentId = span.getSpan().getParent_id() != null ? "" + span.getSpan().getParent_id() : null;
        if (LOG.isDebugEnabled()) {
            if (parentId != null) {
                LOG.debug(String.format("serverRequest [service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
            } else {
                LOG.debug(String.format("serverRequest [service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
            }
        }
    }

    return span;
}
 

开发者ID:HydAu,
项目名称:Camel,
代码行数:39,
代码来源:ZipkinTracer.java

示例12: serverResponse

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
private void serverResponse(Brave brave, String serviceName, Exchange exchange) {
    ServerSpan span = null;
    ZipkinState state = exchange.getProperty(ZipkinState.KEY, ZipkinState.class);
    if (state != null) {
        // only process if it was a zipkin server event
        span = state.popServerSpan();
    }

    if (span != null) {
        ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();
        serverBinder.setCurrentSpan(span);
        brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(this, exchange));
        // and reset binder
        serverBinder.setCurrentSpan(null);

        if (span.getSpan() != null && LOG.isDebugEnabled()) {
            String traceId = "" + span.getSpan().getTrace_id();
            String spanId = "" + span.getSpan().getId();
            String parentId = span.getSpan().getParent_id() != null ? "" + span.getSpan().getParent_id() : null;
            if (LOG.isDebugEnabled()) {
                if (parentId != null) {
                    LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
                } else {
                    LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
                }
            }
        }
    }
}
 

开发者ID:HydAu,
项目名称:Camel,
代码行数:30,
代码来源:ZipkinTracer.java

示例13: popServerSpan

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
public ServerSpan popServerSpan() {
    if (!serverSpans.empty()) {
        return serverSpans.pop();
    } else {
        return null;
    }
}
 

开发者ID:HydAu,
项目名称:Camel,
代码行数:8,
代码来源:ZipkinState.java

示例14: peekServerSpan

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
public ServerSpan peekServerSpan() {
    if (!serverSpans.empty()) {
        return serverSpans.peek();
    } else {
        return null;
    }
}
 

开发者ID:HydAu,
项目名称:Camel,
代码行数:8,
代码来源:ZipkinState.java

示例15: SpanContext

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
SpanContext(final ServerSpan serverSpan, final Span clientSpan) {
  this.serverSpan = serverSpan;
  this.clientSpan = clientSpan;
}
 

开发者ID:emmanuelidi,
项目名称:vertx-zipkin,
代码行数:5,
代码来源:ZipkinEventBusClientInterceptor.java

示例16: pushServerSpan

点赞 2

import com.github.kristofa.brave.ServerSpan; //导入依赖的package包/类
public void pushServerSpan(ServerSpan span) {
    serverSpans.push(span);
}
 

开发者ID:HydAu,
项目名称:Camel,
代码行数:4,
代码来源:ZipkinState.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)