Java Code Examples for brave.handler.MutableSpan#localServiceName()
The following examples show how to use
brave.handler.MutableSpan#localServiceName() .
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 |
@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: TracingTest.java From brave with Apache License 2.0 | 6 votes |
@Test public void spanHandler_dataChangesVisibleToZipkin() { String serviceNameOverride = "favistar"; SpanHandler spanHandler = new SpanHandler() { @Override public boolean end(TraceContext context, MutableSpan span, Cause cause) { span.localServiceName(serviceNameOverride); return true; } }; List<zipkin2.Span> zipkinSpans = new ArrayList<>(); try (Tracing tracing = Tracing.newBuilder() .spanReporter(zipkinSpans::add) .addSpanHandler(spanHandler) .build()) { tracing.tracer().newTrace().start().finish(); } assertThat(zipkinSpans.get(0).localServiceName()).isEqualTo(serviceNameOverride); }
Example 3
Source File: TracingFactoryBeanTest.java From brave with Apache License 2.0 | 6 votes |
@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 4
Source File: TracingFactoryBeanTest.java From brave with Apache License 2.0 | 6 votes |
@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 5
Source File: ZipkinSpanHandlerTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@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 6
Source File: ConvertingSpanReporterTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@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 7
Source File: TracerTest.java From brave with Apache License 2.0 | 5 votes |
@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 8
Source File: OrphanTrackerTest.java From brave with Apache License 2.0 | 5 votes |
@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 9
Source File: ConvertingSpanReporter.java From zipkin-reporter-java with Apache License 2.0 | 4 votes |
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(); }