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

The following examples show how to use brave.handler.MutableSpan#localIp() . 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: PendingSpansTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Before public void init() {
  MutableSpan defaultSpan = new MutableSpan();
  defaultSpan.localServiceName("favistar");
  defaultSpan.localIp("1.2.3.4");
  Clock clock = () -> this.clock.incrementAndGet() * 1000L;
  SpanHandler orphanTracker =
      OrphanTracker.newBuilder().defaultSpan(defaultSpan).clock(clock).build();
  pendingSpans = new PendingSpans(defaultSpan, clock, new SpanHandler() {
    @Override
    public boolean begin(TraceContext ctx, MutableSpan span, @Nullable TraceContext parent) {
      contexts.add(ctx);
      return orphanTracker.begin(ctx, span, parent);
    }

    @Override public boolean end(TraceContext ctx, MutableSpan span, Cause cause) {
      orphanTracker.end(ctx, span, cause);
      spans.end(ctx, span, cause);
      return true;
    }
  }, new AtomicBoolean());
}
 
Example 2
Source File: TracingFactoryBeanTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void localEndpoint() {
  context = new XmlBeans(""
    + "<bean id=\"localEndpoint\" class=\"brave.spring.beans.EndpointFactoryBean\">\n"
    + "  <property name=\"serviceName\" value=\"brave-webmvc-example\"/>\n"
    + "  <property name=\"ip\" value=\"1.2.3.4\"/>\n"
    + "  <property name=\"port\" value=\"8080\"/>\n"
    + "</bean>"
    , ""
    + "<bean id=\"tracing\" class=\"brave.spring.beans.TracingFactoryBean\">\n"
    + "  <property name=\"localEndpoint\" ref=\"localEndpoint\"/>\n"
    + "</bean>"
  );

  MutableSpan defaultSpan = new MutableSpan();
  defaultSpan.localServiceName("brave-webmvc-example");
  defaultSpan.localIp("1.2.3.4");
  defaultSpan.localPort(8080);

  assertThat(context.getBean("tracing", Tracing.class))
    .extracting("tracer.pendingSpans.defaultSpan")
    .isEqualTo(defaultSpan);
}
 
Example 3
Source File: TracingFactoryBeanTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Test public void endpoint() {
  context = new XmlBeans(""
    + "<bean id=\"endpoint\" class=\"brave.spring.beans.EndpointFactoryBean\">\n"
    + "  <property name=\"serviceName\" value=\"brave-webmvc-example\"/>\n"
    + "  <property name=\"ip\" value=\"1.2.3.4\"/>\n"
    + "  <property name=\"port\" value=\"8080\"/>\n"
    + "</bean>"
    , ""
    + "<bean id=\"tracing\" class=\"brave.spring.beans.TracingFactoryBean\">\n"
    + "  <property name=\"endpoint\" ref=\"endpoint\"/>\n"
    + "</bean>"
  );

  MutableSpan defaultSpan = new MutableSpan();
  defaultSpan.localServiceName("brave-webmvc-example");
  defaultSpan.localIp("1.2.3.4");
  defaultSpan.localPort(8080);

  assertThat(context.getBean("tracing", Tracing.class))
    .extracting("tracer.pendingSpans.defaultSpan")
    .isEqualTo(defaultSpan);
}
 
Example 4
Source File: ZipkinSpanHandlerTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Before public void init() {
  defaultSpan = new MutableSpan();
  defaultSpan.localServiceName("Aa");
  defaultSpan.localIp("1.2.3.4");
  defaultSpan.localPort(80);
  handler = new ZipkinSpanHandler(spans, Tags.ERROR, false);
}
 
Example 5
Source File: ConvertingSpanReporterTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Before public void init() {
  defaultSpan = new MutableSpan(context, null);
  defaultSpan.localServiceName("Aa");
  defaultSpan.localIp("1.2.3.4");
  defaultSpan.localPort(80);
  spanReporter = new ConvertingSpanReporter(spans, Tags.ERROR);
}
 
Example 6
Source File: TracerTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void localServiceName_ignoredWhenGivenLocalEndpoint() {
  Endpoint endpoint = Endpoint.newBuilder().ip("1.2.3.4").serviceName("my-bar").build();
  tracer = Tracing.newBuilder().localServiceName("my-foo").endpoint(endpoint).build().tracer();

  MutableSpan defaultSpan = new MutableSpan();
  defaultSpan.localServiceName("my-bar");
  defaultSpan.localIp("1.2.3.4");
  assertThat(tracer).extracting("pendingSpans.defaultSpan").isEqualTo(defaultSpan);
}
 
Example 7
Source File: OrphanTrackerTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Before public void setup() {
  defaultSpan = new MutableSpan();
  defaultSpan.localServiceName(TracerTest.class.getSimpleName());
  defaultSpan.localIp("127.0.0.1");
  span = new MutableSpan(context, defaultSpan); // same as how PendingSpans initializes

  tracker = orphanTrackerWithFakeLogger();
}
 
Example 8
Source File: ConvertingSpanReporter.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
static Span convert(MutableSpan span) {
  Span.Builder result = Span.newBuilder()
      .traceId(span.traceId())
      .parentId(span.parentId())
      .id(span.id())
      .name(span.name());

  long start = span.startTimestamp(), finish = span.finishTimestamp();
  result.timestamp(start);
  if (start != 0 && finish != 0L) result.duration(Math.max(finish - start, 1));

  // use ordinal comparison to defend against version skew
  Kind kind = span.kind();
  if (kind != null) {
    result.kind(BRAVE_TO_ZIPKIN_KIND.get(kind));
  }

  String localServiceName = span.localServiceName(), localIp = span.localIp();
  if (localServiceName != null || localIp != null) {
    result.localEndpoint(Endpoint.newBuilder()
        .serviceName(localServiceName)
        .ip(localIp)
        .port(span.localPort())
        .build());
  }

  String remoteServiceName = span.remoteServiceName(), remoteIp = span.remoteIp();
  if (remoteServiceName != null || remoteIp != null) {
    result.remoteEndpoint(Endpoint.newBuilder()
        .serviceName(remoteServiceName)
        .ip(remoteIp)
        .port(span.remotePort())
        .build());
  }

  span.forEachTag(Consumer.INSTANCE, result);
  span.forEachAnnotation(Consumer.INSTANCE, result);
  if (span.shared()) result.shared(true);
  if (span.debug()) result.debug(true);
  return result.build();
}