Java Code Examples for brave.handler.MutableSpan#tag()

The following examples show how to use brave.handler.MutableSpan#tag() . 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: MutableSpanBenchmarks.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
public static MutableSpan newBigClientSpan() {
  MutableSpan span = new MutableSpan();
  span.name("getuserinfobyaccesstoken");
  span.kind(Span.Kind.CLIENT);
  span.remoteServiceName("abasdasgad.hsadas.ism");
  span.remoteIpAndPort("219.235.216.11", 0);
  span.startTimestamp(1533706251750057L);
  span.finishTimestamp(1533706251935296L);
  span.tag("address.local", "/10.1.2.3:59618");
  span.tag("address.remote", "abasdasgad.hsadas.ism/219.235.216.11:8080");
  span.tag("http.host", "abasdasgad.hsadas.ism");
  span.tag("http.method", "POST");
  span.tag("http.path", "/thrift/shopForTalk");
  span.tag("http.status_code", "200");
  span.tag("http.url", "tbinary+h2c://abasdasgad.hsadas.ism/thrift/shopForTalk");
  span.tag("instanceId", "line-wallet-api");
  span.tag("phase", "beta");
  span.tag("siteId", "shop");
  return span;
}
 
Example 2
Source File: ConvertingSpanReporterTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test public void replacesTag() {
  MutableSpan span = new MutableSpan(context, null);

  span.tag("1", "1");
  span.tag("foo", "bar");
  span.tag("2", "2");
  span.tag("foo", "baz");
  span.tag("3", "3");

  spanReporter.report(span);
  assertThat(spans.get(0).tags()).containsOnly(
      entry("1", "1"),
      entry("foo", "baz"),
      entry("2", "2"),
      entry("3", "3")
  );
}
 
Example 3
Source File: SpanMetricsCustomizer.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override public boolean end(TraceContext context, MutableSpan span, Cause cause) {
  if (cause != Cause.FINISHED) return true;

  Tag nameTag = nameToTag.get(span.name());
  if (nameTag == null) return true; // no tag

  // Example of adding a correlated tag. Note that in spans, we don't add a negative one (None)
  Tag errorTag = exception(span.error());
  if (errorTag != EXCEPTION_NONE) {
    span.tag("exception", errorTag.getValue());
  }

  // Look or create up a timer that records duration against
  registry.timer(metricName, Arrays.asList(nameTag, errorTag))
    // Timestamps are derived from a function of clock time and nanos offset
    .record(span.finishTimestamp() - span.startTimestamp(), TimeUnit.MICROSECONDS);
  return true;
}
 
Example 4
Source File: MutableSpanBenchmarks.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
public static MutableSpan newServerSpan() {
  MutableSpan span = new MutableSpan();
  span.name("get /");
  span.kind(Span.Kind.SERVER);
  span.remoteIpAndPort("::1", 63596);
  span.startTimestamp(1533706251750057L);
  span.finishTimestamp(1533706251935296L);
  span.tag("http.method", "GET");
  span.tag("http.path", "/");
  span.tag("mvc.controller.class", "Frontend");
  span.tag("mvc.controller.method", "callBackend");
  return span;
}
 
Example 5
Source File: ConvertingSpanReporterTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test public void doesntOverwriteErrorTag() {
  MutableSpan span = new MutableSpan(context, null);

  span.error(ERROR);
  span.tag("error", "");

  spanReporter.report(span);

  assertThat(spans.get(0).tags())
      .containsOnly(entry("error", ""));
}
 
Example 6
Source File: IntegrationTestSpanHandler.java    From brave with Apache License 2.0 5 votes vote down vote up
public IntegrationTestSpanHandler() {
  // OrphanTracker detects to see if it should add "brave.flushed" or not, as it is used in
  // production some times and avoiding this could be helpful. This forces a failed match,
  // so that we can detect orphans even when no data was added.
  MutableSpan intentionallyWrongDefaultSpan = new MutableSpan();
  intentionallyWrongDefaultSpan.tag("not", "me");
  orphanTracker = OrphanTracker.newBuilder()
      .defaultSpan(intentionallyWrongDefaultSpan)
      // This will not be exactly the right timestamp when Tracing.Builder.clock is overridden.
      // However, it is rare to override this in an integration test and complex to pass it.
      .clock(Platform.get().clock())
      // Make sure CI can see when things leak: Intentional leak tests shouldn't use this handler.
      .logLevel(Level.WARNING).build();
}
 
Example 7
Source File: DefaultTagsTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public boolean end(TraceContext context, MutableSpan span, Cause cause) {
  if (context.isLocalRoot()) {
    // pretend these are sourced from the environment
    span.tag("env", "prod");
    span.tag("region", "east");
  }
  return true;
}
 
Example 8
Source File: TagTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void tag_mutableSpan() {
  when(parseValue.apply(input, context)).thenReturn("value");

  tag.tag(input, context, mutableSpan);

  verify(parseValue).apply(input, context);
  verifyNoMoreInteractions(parseValue); // doesn't parse twice

  MutableSpan expected = new MutableSpan();
  expected.tag("key", "value");
  assertThat(mutableSpan).isEqualTo(expected);
}
 
Example 9
Source File: TagTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void tag_mutableSpan_nullContext() {
  when(parseValue.apply(eq(input), isNull())).thenReturn("value");

  tag.tag(input, null, mutableSpan);

  verify(parseValue).apply(input, null);
  verifyNoMoreInteractions(parseValue); // doesn't parse twice

  MutableSpan expected = new MutableSpan();
  expected.tag("key", "value");
  assertThat(mutableSpan).isEqualTo(expected);
}
 
Example 10
Source File: TagTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void tag_mutableSpan_empty() {
  when(parseValue.apply(input, context)).thenReturn("");

  tag.tag(input, context, mutableSpan);

  verify(parseValue).apply(input, context);
  verifyNoMoreInteractions(parseValue); // doesn't parse twice

  MutableSpan expected = new MutableSpan();
  expected.tag("key", "");
  assertThat(mutableSpan).isEqualTo(expected);
}
 
Example 11
Source File: ConvertingSpanReporter.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
void maybeAddErrorTag(MutableSpan span) {
  // span.tag(key) iterates: check if we need to first!
  if (span.error() == null) return;
  if (span.tag("error") == null) errorTag.tag(span.error(), null, span);
}
 
Example 12
Source File: NoopAwareSpanHandlerBenchmarks.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public boolean end(TraceContext context, MutableSpan span, Cause cause) {
  span.tag("one", "");
  return true;
}
 
Example 13
Source File: NoopAwareSpanHandlerBenchmarks.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public boolean end(TraceContext context, MutableSpan span, Cause cause) {
  span.tag("two", "");
  return true;
}
 
Example 14
Source File: NoopAwareSpanHandlerBenchmarks.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public boolean end(TraceContext context, MutableSpan span, Cause cause) {
  span.tag("three", "");
  return true;
}