当前位置: 首页>>代码示例>>Java>>正文


Java SpanInScope类代码示例

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


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

示例1: runFilter

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Override
public ZuulFilterResult runFilter() {
  RequestContext ctx = RequestContext.getCurrentContext();

  Span span = clientHandler.handleSend(injector, ctx);
  saveHeadersAsInvocationContext(ctx, span);

  SpanInScope scope = tracer.withSpanInScope(span);
  log.debug("Generated tracing span {} for {}", span, ctx.getRequest().getMethod());

  ctx.getRequest().setAttribute(SpanInScope.class.getName(), scope);

  ZuulFilterResult result = super.runFilter();
  log.debug("Result of Zuul filter is [{}]", result.getStatus());

  if (ExecutionStatus.SUCCESS != result.getStatus()) {
    log.debug("The result of Zuul filter execution was not successful thus will close the current span {}", span);
    clientHandler.handleReceive(ctx.getResponse(), result.getException(), span);
    scope.close();
  }
  return result;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:TracePreZuulFilter.java

示例2: handle

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
  Span span = tracingDelegate.createSpan(invocation);
  try (SpanInScope scope = tracer.tracer().withSpanInScope(span)) {
    LOGGER.debug("{}: Generated tracing span for {}",
        tracingDelegate.name(),
        invocation.getOperationName());

    invocation.next(onResponse(invocation, asyncResp, span));
  } catch (Exception e) {
    LOGGER.debug("{}: Failed invocation on {}",
        tracingDelegate.name(),
        invocation.getOperationName(),
        e);

    tracingDelegate.onResponse(span, null, e);
    throw e;
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:ZipkinTracingHandler.java

示例3: execute

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Override
public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception {
    Span span = tracer.nextSpan();
    injector.inject(span.context(), req.headers());
    // For no-op spans, we only need to inject into headers and don't set any other attributes.
    if (span.isNoop()) {
        return delegate().execute(ctx, req);
    }

    final String method = ctx.method().name();
    span.kind(Kind.CLIENT).name(method).start();

    SpanContextUtil.setupContext(ctx, span, tracer);

    ctx.log().addListener(log -> finishSpan(span, log), RequestLogAvailability.COMPLETE);

    try (SpanInScope ignored = tracer.withSpanInScope(span)) {
        return delegate().execute(ctx, req);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:21,代码来源:HttpTracingClient.java

示例4: serve

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
    TraceContextOrSamplingFlags contextOrFlags = extractor.extract(req.headers());
    Span span = contextOrFlags.context() != null ? tracer.joinSpan(contextOrFlags.context())
                                                 : tracer.newTrace(contextOrFlags.samplingFlags());
    // For no-op spans, nothing special to do.
    if (span.isNoop()) {
        return delegate().serve(ctx, req);
    }

    final String method = ctx.method().name();
    span.kind(Kind.SERVER).name(method).start();

    SpanContextUtil.setupContext(ctx, span, tracer);

    ctx.log().addListener(log -> closeSpan(span, log), RequestLogAvailability.COMPLETE);

    try (SpanInScope ignored = tracer.withSpanInScope(span)) {
        return delegate().serve(ctx, req);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:HttpTracingService.java

示例5: subsequentChildrenNestProperly_BraveStyle

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Test public void subsequentChildrenNestProperly_BraveStyle() {
  // this test is semantically identical to subsequentChildrenNestProperly_OTStyle, but uses
  // the Brave API instead of the OpenTracing API.

  Long shouldBeIdOfSpanA;
  Long idOfSpanB;
  Long shouldBeIdOfSpanB;
  Long parentIdOfSpanB;
  Long parentIdOfSpanC;

  Span spanA = brave.tracer().newTrace().name("spanA").start();
  Long idOfSpanA = spanA.context().spanId();
  try (SpanInScope scopeA = brave.tracer().withSpanInScope(spanA)) {

    Span spanB = brave.tracer().newChild(spanA.context()).name("spanB").start();
    idOfSpanB = spanB.context().spanId();
    parentIdOfSpanB = spanB.context().parentId();
    try (SpanInScope scopeB = brave.tracer().withSpanInScope(spanB)) {
      shouldBeIdOfSpanB = brave.currentTraceContext().get().spanId();
    } finally {
      spanB.finish();
    }

    shouldBeIdOfSpanA = brave.currentTraceContext().get().spanId();

    Span spanC = brave.tracer().newChild(spanA.context()).name("spanC").start();
    parentIdOfSpanC = spanC.context().parentId();
    try (SpanInScope scopeC = brave.tracer().withSpanInScope(spanC)) {
      // nothing to do here
    } finally {
      spanC.finish();
    }
  } finally {
    spanA.finish();
  }

  assertEquals("SpanA should have been active again after closing B", idOfSpanA,
      shouldBeIdOfSpanA);
  assertEquals("SpanB should have been active prior to its closure", idOfSpanB,
      shouldBeIdOfSpanB);
  assertEquals("SpanB's parent should be SpanA", idOfSpanA, parentIdOfSpanB);
  assertEquals("SpanC's parent should be SpanA", idOfSpanA, parentIdOfSpanC);
}
 
开发者ID:openzipkin-contrib,项目名称:brave-opentracing,代码行数:44,代码来源:BraveTracerTest.java

示例6: run

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Override
public Object run() {
  RequestContext context = RequestContext.getCurrentContext();
  ((SpanInScope) context.getRequest().getAttribute(SpanInScope.class.getName())).close();

  clientHandler.handleReceive(context.getResponse(), null, tracer.currentSpan());
  log.debug("Closed span {} for {}", tracer.currentSpan(), context.getRequest().getMethod());

  return null;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:11,代码来源:TracePostZuulFilter.java

示例7: invoke

import brave.Tracer.SpanInScope; //导入依赖的package包/类
<T> T invoke(String spanName, String path, ThrowableSupplier<T> supplier) throws Throwable {
  Span span = createSpan(spanName, path);
  try (SpanInScope spanInScope = tracer.withSpanInScope(span)) {
    return supplier.get();
  } catch (Throwable throwable) {
    span.tag("error", throwable.getClass().getSimpleName() + ": " + throwable.getMessage());
    throw throwable;
  } finally {
    span.finish();
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:12,代码来源:ZipkinTracingAdviser.java

示例8: startsNewChildSpan

import brave.Tracer.SpanInScope; //导入依赖的package包/类
@Test
public void startsNewChildSpan() throws Exception {
  CyclicBarrier cyclicBarrier = new CyclicBarrier(nThreads);

  CompletableFuture<?>[] futures = new CompletableFuture[nThreads];
  for (int i = 0; i < nThreads; i++) {
    futures[i] = CompletableFuture.runAsync(() -> {
      Span currentSpan = tracing.tracer().newTrace().start();

      waitTillAllAreReady(cyclicBarrier);

      try (SpanInScope spanInScope = tracing.tracer().withSpanInScope(currentSpan)) {
        assertThat(tracingAdviser.invoke(spanName, path, supplier), is(expected));
      } catch (Throwable throwable) {
        fail(throwable.getMessage());
      } finally {
        currentSpan.finish();
      }
    }, Executors.newFixedThreadPool(nThreads));
  }

  CompletableFuture.allOf(futures).join();

  assertThat(traces.size(), is(nThreads));

  for (Queue<zipkin2.Span> queue : traces.values()) {
    zipkin2.Span child = queue.poll();
    assertThat(child.name(), is(spanName));

    zipkin2.Span parent = queue.poll();
    assertThat(child.parentId(), is(parent.id()));
    assertThat(child.traceId(), is(parent.traceId()));
    assertThat(tracedValues(child), contains(this.getClass().getCanonicalName()));
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:36,代码来源:ZipkinTracingAdviserTest.java

示例9: BraveScope

import brave.Tracer.SpanInScope; //导入依赖的package包/类
/**
 * @param source the BraveActiveSpanSource that created this BraveActiveSpan
 * @param scope a SpanInScope to be closed upon deactivation of this ActiveSpan
 * @param wrapped the wrapped BraveSpan to which we will delegate all span operations
 */
BraveScope(BraveScopeManager source, SpanInScope scope, BraveSpan wrapped,
    boolean finishSpanOnClose) {
  this.source = source;
  this.scope = scope;
  this.wrapped = wrapped;
  this.finishSpanOnClose = finishSpanOnClose;
}
 
开发者ID:openzipkin-contrib,项目名称:brave-opentracing,代码行数:13,代码来源:BraveScope.java

示例10: setupContext

import brave.Tracer.SpanInScope; //导入依赖的package包/类
/**
 * Sets up the {@link RequestContext} to push and pop the {@link Span} whenever it is entered/exited.
 */
public static void setupContext(RequestContext ctx, Span span, Tracer tracer) {
    ctx.onEnter(unused -> SPAN_IN_THREAD.set(tracer.withSpanInScope(span)));
    ctx.onExit(unused -> {
        SpanInScope spanInScope = SPAN_IN_THREAD.get();
        if (spanInScope != null) {
            spanInScope.close();
            SPAN_IN_THREAD.remove();
        }
    });
}
 
开发者ID:line,项目名称:armeria,代码行数:14,代码来源:SpanContextUtil.java


注:本文中的brave.Tracer.SpanInScope类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。