brave.Tracer.startScopedSpan()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中brave.Tracer.startScopedSpan()方法的一些代码示例,展示了Tracer.startScopedSpan()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.startScopedSpan()方法的具体详情如下:
包路径:brave.Tracer
类名称:Tracer
方法名:startScopedSpan

Tracer.startScopedSpan介绍

[英]Returns a new child span if there's a #currentSpan() or a new trace if there isn't. The result is the "current span" until ScopedSpan#finish() is called. Here's an example:

ScopedSpan span = tracer.startScopedSpan("encode");catch (RuntimeException | Error e)  
span.error(e); // Unless you handle exceptions, you might not know the operation failed! 
throw e; 
} finally  
span.finish(); 
} 
}

[中]

代码示例

代码示例来源:origin: openzipkin/brave

@Test public void makesChildOfCurrentSpan() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 RecordedRequest request = server.takeRequest();
 assertThat(request.getHeader("x-b3-traceId"))
   .isEqualTo(parent.context().traceIdString());
 assertThat(request.getHeader("x-b3-parentspanid"))
   .isEqualTo(parent.context().spanIdString());
 assertThat(Arrays.asList(takeSpan(), takeSpan()))
   .extracting(Span::kind)
   .containsOnly(null, Span.Kind.CLIENT);
}

代码示例来源:origin: openzipkin/brave

@Test public void propagatesExtra_newTrace() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 assertThat(server.takeRequest().getHeader(EXTRA_KEY))
   .isEqualTo("joey");
 // we report one in-process and one RPC client span
 assertThat(Arrays.asList(takeSpan(), takeSpan()))
   .extracting(Span::kind)
   .containsOnly(null, Span.Kind.CLIENT);
}

代码示例来源:origin: openzipkin/brave

@Test public void propagatesExtra_unsampledTrace() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE);
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 assertThat(server.takeRequest().getHeader(EXTRA_KEY))
   .isEqualTo("joey");
}

代码示例来源:origin: openzipkin/brave

@Test public void redirect() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse().setResponseCode(302)
   .addHeader("Location: " + url("/bar")));
 server.enqueue(new MockResponse().setResponseCode(404)); // hehe to a bad location!
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  get(client, "/foo");
 } catch (RuntimeException e) {
  // some think 404 is an exception
 } finally {
  parent.finish();
 }
 Span client1 = takeSpan();
 Span client2 = takeSpan();
 assertThat(Arrays.asList(client1.tags().get("http.path"), client2.tags().get("http.path")))
   .contains("/foo", "/bar");
 assertThat(takeSpan().kind()).isNull(); // local
}

代码示例来源:origin: openzipkin/brave

server.enqueue(new MockResponse());
ScopedSpan parent = tracer.startScopedSpan("test");
try {
 getAsync(client, "/items/1");
ScopedSpan otherSpan = tracer.startScopedSpan("test2");
try {
 for (int i = 0; i < 2; i++) {

代码示例来源:origin: jeqo/talk-kafka-zipkin

@GET
@Path("{lang}")
@Produces(MediaType.TEXT_PLAIN)
public Response translateHello(@PathParam("lang") final String lang) {
  /* START CUSTOM INSTRUMENTATION */
  final ScopedSpan span = tracer.startScopedSpan("query-repository");
  span.annotate("started-query");
  span.tag("lang", Optional.ofNullable(lang).orElse(""));
  final String hello = repository.find(lang);
  span.annotate("finished-query");
  span.finish();
  /* END CUSTOM INSTRUMENTATION */
  return Response.ok(hello).build();
}

代码示例来源:origin: io.zipkin.java/zipkin-server

@Override
public V execute() throws IOException {
 ScopedSpan span = tracer.startScopedSpan(name);
 try {
  return delegate.execute();
 } catch (RuntimeException | IOException | Error e) {
  span.error(e);
  throw e;
 } finally {
  span.finish();
 }
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

@Test public void makesChildOfCurrentSpan() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 RecordedRequest request = server.takeRequest();
 assertThat(request.getHeader("x-b3-traceId"))
   .isEqualTo(parent.context().traceIdString());
 assertThat(request.getHeader("x-b3-parentspanid"))
   .isEqualTo(parent.context().spanIdString());
 assertThat(Arrays.asList(takeSpan(), takeSpan()))
   .extracting(Span::kind)
   .containsOnly(null, Span.Kind.CLIENT);
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

@Test public void propagatesExtra_newTrace() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 assertThat(server.takeRequest().getHeader(EXTRA_KEY))
   .isEqualTo("joey");
 // we report one in-process and one RPC client span
 assertThat(Arrays.asList(takeSpan(), takeSpan()))
   .extracting(Span::kind)
   .containsOnly(null, Span.Kind.CLIENT);
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

@Test public void propagatesExtra_unsampledTrace() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE);
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 assertThat(server.takeRequest().getHeader(EXTRA_KEY))
   .isEqualTo("joey");
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

@Test public void redirect() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse().setResponseCode(302)
   .addHeader("Location: " + url("/bar")));
 server.enqueue(new MockResponse().setResponseCode(404)); // hehe to a bad location!
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  get(client, "/foo");
 } catch (RuntimeException e) {
  // some think 404 is an exception
 } finally {
  parent.finish();
 }
 Span client1 = takeSpan();
 Span client2 = takeSpan();
 assertThat(Arrays.asList(client1.tags().get("http.path"), client2.tags().get("http.path")))
   .contains("/foo", "/bar");
 assertThat(takeSpan().kind()).isNull(); // local
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

server.enqueue(new MockResponse());
ScopedSpan parent = tracer.startScopedSpan("test");
try {
 getAsync(client, "/items/1");
ScopedSpan otherSpan = tracer.startScopedSpan("test2");
try {
 for (int i = 0; i < 2; i++) {

相关文章