zipkin2.Span.name()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(139)

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

Span.name介绍

[英]Span name in lowercase, rpc method for example.

Conventionally, when the span name isn't known, name = "unknown".
[中]

代码示例

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

@Test
public void defaultSpanNameIsMethodNameOrRoute() throws Exception {
 get("/foo");
 Span span = takeSpan();
 if (!span.name().equals("get")) {
  assertThat(span.name())
    .isEqualTo("get /foo");
 }
}

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

/**
 * Shows that by adding the request attribute "http.route" a layered framework can influence
 * any derived from the route, including the span name.
 */
@Test public void canSetCustomRoute() throws Exception {
 delegate = customHttpRoute;
 get("/foo");
 Span span = takeSpan();
 assertThat(span.name())
   .isEqualTo("get /foo");
}

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

/**
 * This tests both that a root path ends up as "/" (slash) not "" (empty), as well that less
 * typical OPTIONS methods can be traced.
 */
@Test public void options() throws Exception {
 assertThat(call("OPTIONS", "/").isSuccessful())
   .isTrue();
 Span span = takeSpan();
 // verify normal tags
 assertThat(span.tags())
   .containsEntry("http.method", "OPTIONS")
   .containsEntry("http.path", "/");
 // Either the span name is the method, or it is a route expression
 String name = span.name();
 if (name != null && !"options".equals(name)) {
  assertThat(name).isEqualTo("options /");
 }
}

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

@Test public void defaultSpanNameIsMethodName() throws Exception {
 server.enqueue(new MockResponse());
 get(client, "/foo");
 Span span = takeSpan();
 assertThat(span.name())
   .isEqualTo("get");
}

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

@Test public void post() throws Exception {
 String path = "/post";
 String body = "body";
 server.enqueue(new MockResponse());
 post(client, path, body);
 assertThat(server.takeRequest().getBody().readUtf8())
   .isEqualTo(body);
 Span span = takeSpan();
 assertThat(span.name())
   .isEqualTo("post");
}

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

/** If http route is supported, then the span name should include it */
@Test public void notFound() throws Exception {
 assertThat(call("GET", "/foo/bark").code())
   .isEqualTo(404);
 Span span = takeSpan();
 // verify normal tags
 assertThat(span.tags())
   .hasSize(4)
   .containsEntry("http.method", "GET")
   .containsEntry("http.path", "/foo/bark")
   .containsEntry("http.status_code", "404")
   .containsKey("error"); // as 404 is an error
 // Either the span name is the method, or it is a route expression
 String name = span.name();
 if (name != null && !"get".equals(name)) {
  assertThat(name).isEqualTo("get not_found");
 }
}

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

private void routeBasedRequestNameIncludesPathPrefix(String prefix) throws Exception {
 Response request1 = get(prefix + "/1?foo");
 Response request2 = get(prefix + "/2?bar");
 // get() doesn't check the response, check to make sure the server didn't 500
 assertThat(request1.isSuccessful()).isTrue();
 assertThat(request2.isSuccessful()).isTrue();
 // Reading the route parameter from the response ensures the test endpoint is correct
 assertThat(request1.body().string())
   .isEqualTo("1");
 assertThat(request2.body().string())
   .isEqualTo("2");
 Span span1 = takeSpan(), span2 = takeSpan();
 // verify that the path and url reflect the initial request (not a route expression)
 assertThat(span1.tags())
   .containsEntry("http.method", "GET")
   .containsEntry("http.path", prefix + "/1")
   .containsEntry("http.url", url(prefix + "/1?foo"));
 assertThat(span2.tags())
   .containsEntry("http.method", "GET")
   .containsEntry("http.path", prefix + "/2")
   .containsEntry("http.url", url(prefix + "/2?bar"));
 // We don't know the exact format of the http route as it is framework specific
 // However, we know that it should match both requests and include the common part of the path
 Set<String> routeBasedNames = new LinkedHashSet<>(Arrays.asList(span1.name(), span2.name()));
 assertThat(routeBasedNames).hasSize(1);
 assertThat(routeBasedNames.iterator().next())
   .startsWith("get " + prefix)
   .doesNotEndWith("/") // no trailing slashes
   .doesNotContain("//"); // no duplicate slashes
}

代码示例来源:origin: line/armeria

@Test(timeout = 20000)
public void shouldSubmitSpanWhenRequestIsSampled() throws Exception {
  final SpanCollectingReporter reporter = testServiceInvocation(1.0f);
  // check span name
  final Span span = reporter.spans().take();
  assertThat(span.name()).isEqualTo(TEST_METHOD);
  // check kind
  assertThat(span.kind()).isSameAs(Kind.SERVER);
  // only one span should be submitted
  assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull();
  // check # of annotations (we add wire annotations)
  assertThat(span.annotations()).hasSize(2);
  // check tags
  assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of(
      "http.host", "foo.com",
      "http.method", "POST",
      "http.path", "/hello/trustin",
      "http.status_code", "200",
      "http.url", "none+h2c://foo.com/hello/trustin"));
  // check service name
  assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE);
}

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

assertThat(span.name())
  .isEqualTo("get /foo");

代码示例来源:origin: line/armeria

assertThat(spans).allMatch(s -> "hello".equals(s.name()));

代码示例来源:origin: line/armeria

@Test(timeout = 20000)
public void shouldSubmitSpanWhenSampled() throws Exception {
  final SpanCollectingReporter reporter = new SpanCollectingReporter();
  final Tracing tracing = Tracing.newBuilder()
                  .localServiceName(TEST_SERVICE)
                  .spanReporter(reporter)
                  .sampler(Sampler.create(1.0f))
                  .build();
  testRemoteInvocation(tracing, null);
  // check span name
  final Span span = reporter.spans().take();
  assertThat(span.name()).isEqualTo(TEST_SPAN);
  // check kind
  assertThat(span.kind()).isSameAs(Kind.CLIENT);
  // only one span should be submitted
  assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull();
  // check # of annotations (we add wire annotations)
  assertThat(span.annotations()).hasSize(2);
  // check tags
  assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of(
      "http.host", "foo.com",
      "http.method", "POST",
      "http.path", "/hello/armeria",
      "http.status_code", "200",
      "http.url", "none+h2c://foo.com/hello/armeria"));
  // check service name
  assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE);
  // check remote service name
  assertThat(span.remoteServiceName()).isEqualTo("foo.com");
}

代码示例来源:origin: line/armeria

assertThat(spans).allMatch(s -> "hello".equals(s.name()));

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpanIsCreatedUsingAsyncInvocation() {
  final Response r = createWebClient("/bookstore/books/async").get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/async"));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("processing books"));
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  final Future<Response> f = client.async().get();
  final Response r = f.get(1, TimeUnit.SECONDS);
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
  assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
  assertThatTraceHeadersArePresent(r, false);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewInnerSpanIsCreated() {
  final SpanId spanId = fromRandom();
  final Response r = withTrace(createWebClient("/bookstore/books"), spanId).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
  assertThatTraceIsPresent(r, spanId);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatInnerSpanIsCreatedUsingPseudoAsyncInvocation() {
  final SpanId spanId = fromRandom();
  final Response r = withTrace(createWebClient("/bookstore/books/pseudo-async"), spanId).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/pseudo-async"));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("processing books"));
  assertThatTraceIsPresent(r, spanId);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvided() {
  final Response r = createWebClient("/bookstore/books", braveClientProvider).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
  assertThatTraceHeadersArePresent(r, false);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatOuterSpanIsCreatedUsingAsyncInvocation() {
  final SpanId spanId = fromRandom();
  final Response r = withTrace(createWebClient("/bookstore/books/async/notrace"), spanId).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/books/async/notrace"));
  assertThatTraceIsPresent(r, spanId);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatCurrentSpanIsAnnotatedWithKeyValue() {
  final SpanId spanId = fromRandom();
  final Response r = withTrace(createWebClient("/bookstore/book/1"), spanId).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/book/1"));
  assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasEntry("book-id", "1"));
  assertThatTraceIsPresent(r, spanId);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpanIsCreatedWhenNotProvided() {
  final Response r = createWebClient("/bookstore/books").get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
  assertFalse(r.getHeaders().containsKey(SPAN_ID_NAME));
  assertFalse(r.getHeaders().containsKey(TRACE_ID_NAME));
  assertFalse(r.getHeaders().containsKey(SAMPLED_NAME));
  assertFalse(r.getHeaders().containsKey(PARENT_SPAN_ID_NAME));
}

相关文章