io.opentracing.References Java Examples

The following examples show how to use io.opentracing.References. 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: OrderManager.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void run() {
	SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("orderJob");
	spanBuilder.withTag(RobotOrder.KEY_ORDER_ID, String.valueOf(order.getOrderId()));
	spanBuilder.addReference(References.FOLLOWS_FROM, parent.context());
	Span span = spanBuilder.start();
	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		Customer customer = validateUser(order.getCustomerId(), scope.span().context());
		Collection<CompletableFuture<Robot>> robots = dispatch(order.getLineItems(), scope.span().context());
		CompletableFuture<Void> allOf = CompletableFuture.allOf(robots.toArray(new CompletableFuture[0]));
		allOf.get();
		List<Robot> collect = robots.stream().map((robot) -> get(robot)).collect(Collectors.toList());

		// TODO verify that all list items got realized - otherwise add errors for the ones missing etc
		completedOrders.put(order.getOrderId(),
				new RealizedOrder(order, customer, collect.toArray(new Robot[0]), null));
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
		completedOrders.put(order.getOrderId(), new RealizedOrder(order, null, null, t));
	} finally {
		span.finish();
		parent.finish();
	}
	orderQueue.remove(order.getOrderId());
}
 
Example #2
Source File: Actor.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
public Future<?> tell(final String message) {
  final Span parent = tracer.scopeManager().activeSpan();
  phaser.register();
  return executor.submit(
      () -> {
        Span child =
            tracer
                .buildSpan("received")
                .addReference(References.FOLLOWS_FROM, parent.context())
                .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
                .start();
        try (Scope scope = tracer.activateSpan(child)) {
          phaser.arriveAndAwaitAdvance(); // child tracer started
          child.log("received " + message);
          phaser.arriveAndAwaitAdvance(); // assert size
        } finally {
          child.finish();
        }

        phaser.arriveAndAwaitAdvance(); // child tracer finished
        phaser.arriveAndAwaitAdvance(); // assert size
      });
}
 
Example #3
Source File: MockTracerTest.java    From opentracing-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testFollowFromReference() {
    MockTracer tracer = new MockTracer(MockTracer.Propagator.TEXT_MAP);
    final MockSpan precedent = tracer.buildSpan("precedent").start();

    final MockSpan followingSpan = tracer.buildSpan("follows")
        .addReference(References.FOLLOWS_FROM, precedent.context())
        .start();

    assertEquals(precedent.context().spanId(), followingSpan.parentId());
    assertEquals(1, followingSpan.references().size());

    final MockSpan.Reference followsFromRef = followingSpan.references().get(0);

    assertEquals(new MockSpan.Reference(precedent.context(), References.FOLLOWS_FROM), followsFromRef);
}
 
Example #4
Source File: MockTracerTest.java    From opentracing-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiReferences() {
    MockTracer tracer = new MockTracer(MockTracer.Propagator.TEXT_MAP);
    final MockSpan parent = tracer.buildSpan("parent").start();
    final MockSpan precedent = tracer.buildSpan("precedent").start();

    final MockSpan followingSpan = tracer.buildSpan("follows")
        .addReference(References.FOLLOWS_FROM, precedent.context())
        .asChildOf(parent.context())
        .start();

    assertEquals(parent.context().spanId(), followingSpan.parentId());
    assertEquals(2, followingSpan.references().size());

    final MockSpan.Reference followsFromRef = followingSpan.references().get(0);
    final MockSpan.Reference parentRef = followingSpan.references().get(1);

    assertEquals(new MockSpan.Reference(precedent.context(), References.FOLLOWS_FROM), followsFromRef);
    assertEquals(new MockSpan.Reference(parent.context(), References.CHILD_OF), parentRef);
}
 
Example #5
Source File: MockTracerTest.java    From opentracing-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiReferencesBaggage() {
    MockTracer tracer = new MockTracer(MockTracer.Propagator.TEXT_MAP);
    final MockSpan parent = tracer.buildSpan("parent").start();
    parent.setBaggageItem("parent", "foo");
    final MockSpan precedent = tracer.buildSpan("precedent").start();
    precedent.setBaggageItem("precedent", "bar");

    final MockSpan followingSpan = tracer.buildSpan("follows")
        .addReference(References.FOLLOWS_FROM, precedent.context())
        .asChildOf(parent.context())
        .start();

    assertEquals("foo", followingSpan.getBaggageItem("parent"));
    assertEquals("bar", followingSpan.getBaggageItem("precedent"));
}
 
Example #6
Source File: Actor.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
public Future<String> ask(final String message) {
  final Span parent = tracer.scopeManager().activeSpan();
  phaser.register();
  Future<String> future =
      executor.submit(
          () -> {
            Span span =
                tracer
                    .buildSpan("received")
                    .addReference(References.FOLLOWS_FROM, parent.context())
                    .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
                    .start();
            try {
              phaser.arriveAndAwaitAdvance(); // child tracer started
              phaser.arriveAndAwaitAdvance(); // assert size
              return "received " + message;
            } finally {
              span.finish();

              phaser.arriveAndAwaitAdvance(); // child tracer finished
              phaser.arriveAndAwaitAdvance(); // assert size
            }
          });
  return future;
}
 
Example #7
Source File: SpringKafkaAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void onMessageEnter(final Object record) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder builder = tracer
    .buildSpan("onMessage")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER);

  if (record instanceof ConsumerRecord) {
    final ConsumerRecord<?,?> consumerRecord = (ConsumerRecord<?,?>)record;
    final SpanContext spanContext = TracingKafkaUtils.extractSpanContext(consumerRecord.headers(), tracer);
    if (spanContext != null)
      builder.addReference(References.FOLLOWS_FROM, spanContext);
  }

  final Span span = builder.start();
  LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span));
}
 
Example #8
Source File: Actor.java    From opentracing-java with Apache License 2.0 6 votes vote down vote up
public void tell(final String message) {
  final Span parent = tracer.scopeManager().activeSpan();
  phaser.register();
  executor.submit(
      new Runnable() {
        @Override
        public void run() {
          Span child = tracer
              .buildSpan("received")
              .addReference(References.FOLLOWS_FROM, parent.context())
              .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
              .start();
          try (Scope scope = tracer.activateSpan(child)) {
            phaser.arriveAndAwaitAdvance(); // child tracer started
            child.log("received " + message);
            phaser.arriveAndAwaitAdvance(); // assert size
          } finally {
            child.finish();
          }

          phaser.arriveAndAwaitAdvance(); // child tracer finished
          phaser.arriveAndAwaitAdvance(); // assert size
        }
      });
}
 
Example #9
Source File: Promise.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
public void success(final T result) {
  for (final SuccessCallback<T> callback : successCallbacks) {
    context.submit(
        () -> {
          Span childSpan =
              tracer
                  .buildSpan("success")
                  .addReference(References.FOLLOWS_FROM, parentSpan.context())
                  .withTag(Tags.COMPONENT.getKey(), "success")
                  .start();
          try (Scope childScope = tracer.activateSpan(childSpan)) {
            callback.accept(result);
          } finally {
            childSpan.finish();
          }
          context.getPhaser().arriveAndAwaitAdvance(); // trace reported
        });
  }
}
 
Example #10
Source File: Promise.java    From opentracing-java with Apache License 2.0 6 votes vote down vote up
public void success(final T result) {
  for (final SuccessCallback<T> callback : successCallbacks) {
    context.submit(
        new Runnable() {
          @Override
          public void run() {
            Span childSpan = tracer
                .buildSpan("success")
                .addReference(References.FOLLOWS_FROM, parentSpan.context())
                .withTag(Tags.COMPONENT.getKey(), "success")
                .start();
            try (Scope childScope = tracer.activateSpan(childSpan)) {
              callback.accept(result);
            } finally {
              childSpan.finish();
            }
            context.getPhaser().arriveAndAwaitAdvance(); // trace reported
          }
        });
  }
}
 
Example #11
Source File: SpringRabbitMQAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void onMessageEnter(final Object msg) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder builder = tracer
    .buildSpan("onMessage")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER);

  final Message message = (Message)msg;
  if (message.getMessageProperties() != null) {
    final Map<String,Object> headers = message.getMessageProperties().getHeaders();
    final SpanContext spanContext = tracer.extract(Builtin.TEXT_MAP, new HeadersMapExtractAdapter(headers));
    if (spanContext != null)
      builder.addReference(References.FOLLOWS_FROM, spanContext);
  }

  final Span span = builder.start();
  LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span));
}
 
Example #12
Source File: TracedCallable.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Override
public V call() throws Exception {
  final Tracer tracer = GlobalTracer.get();
  if (verbose) {
    final Span span = tracer
      .buildSpan("callable")
      .withTag(Tags.COMPONENT, "java-concurrent")
      .addReference(References.FOLLOWS_FROM, parent.context())
      .start();
    try (final Scope scope = tracer.activateSpan(span)) {
      return delegate.call();
    }
    finally {
      span.finish();
    }
  }

  try (final Scope scope = tracer.activateSpan(parent)) {
    return delegate.call();
  }
}
 
Example #13
Source File: Client.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
public Future<Object> send(final Object message) {
  final SpanContext parentSpanContext = tracer.activeSpan().context();

  return executor.submit(
      () -> {
        logger.info("Child thread with message '{}' started", message);

        Span span =
            tracer
                .buildSpan("subtask")
                .addReference(References.FOLLOWS_FROM, parentSpanContext)
                .start();
        try (Scope subtaskScope = tracer.activateSpan(span)) {
          // Simulate work - make sure we finish *after* the parent Span.
          parentDoneLatch.await();
        } finally {
          span.finish();
        }

        logger.info("Child thread with message '{}' finished", message);
        return message + "::response";
      });
}
 
Example #14
Source File: Factory.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void run() {
	SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("inProduction");
	spanBuilder.addReference(References.FOLLOWS_FROM, parent.context());
	Span span = spanBuilder.start();
	span.setTag(Robot.KEY_SERIAL_NUMBER, String.valueOf(serialNumber));
	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		Robot chassis = createChassis(serialNumber, robotTypeId, scope.span().context());
		// Takes some time to roll the robot over to the painting
		Utils.sleep(10);
		Robot paintedRobot = paintRobot(chassis, paint, scope.span().context());
		completedRobots.put(paintedRobot.getSerialNumber(), paintedRobot);
		jobsInProduction.remove(serialNumber);
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
		throw t;
	} finally {
		span.finish();
		parent.finish();
	}
}
 
Example #15
Source File: TracingSupportingHonoResourceTest.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Verifies that the resource uses the SpanContext extracted from a CoAP request
 * as the parent of the newly created Span.
 */
@Test
public void testHandleRequestExtractsParentTraceContext() {

    final SpanContext extractedContext = mock(SpanContext.class);
    when(tracer.extract(eq(Format.Builtin.BINARY), any(Binary.class))).thenReturn(extractedContext);

    final Request request = new Request(Code.POST);
    request.getOptions().addOption(new Option(CoapOptionInjectExtractAdapter.OPTION_TRACE_CONTEXT));
    final Exchange exchange = new Exchange(request, Origin.REMOTE, mock(Executor.class));
    resource.handleRequest(exchange);

    verify(tracer).buildSpan(eq(Code.POST.toString()));
    verify(spanBuilder).withTag(eq(Tags.SPAN_KIND.getKey()), eq(Tags.SPAN_KIND_SERVER.toString()));
    verify(spanBuilder).addReference(eq(References.CHILD_OF), eq(extractedContext));
}
 
Example #16
Source File: APMTracerReferenceTest.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleExtractedFollowsFrom() {
    APMTracerTest.TestTraceRecorder testTraceReporter = new APMTracerTest.TestTraceRecorder();
    Tracer tracer = new APMTracer(testTraceReporter);

    SpanContext spanCtx = extractedTraceState(tracer, TEST_APM_ID1);

    Span span = tracer.buildSpan("root")
            .addReference(References.FOLLOWS_FROM, spanCtx)
            .start();
    span.finish();

    assertEquals(1, testTraceReporter.getTraces().size());

    Trace trace = testTraceReporter.getTraces().get(0);
    assertEquals(1, trace.getNodes().size());
    assertEquals(Consumer.class, trace.getNodes().get(0).getClass());
    assertEquals(((Consumer) trace.getNodes().get(0)).getCorrelationIds().get(0),
            new CorrelationIdentifier(Scope.Interaction, TEST_APM_ID1));
    assertEquals(0, ((Consumer) trace.getNodes().get(0)).getNodes().size());
}
 
Example #17
Source File: SofaTracer.java    From sofa-tracer with Apache License 2.0 6 votes vote down vote up
@Override
public Tracer.SpanBuilder addReference(String referenceType, SpanContext referencedContext) {
    if (referencedContext == null) {
        return this;
    }
    if (!(referencedContext instanceof SofaTracerSpanContext)) {
        return this;
    }
    if (!References.CHILD_OF.equals(referenceType)
        && !References.FOLLOWS_FROM.equals(referenceType)) {
        return this;
    }
    if (references.isEmpty()) {
        // Optimization for 99% situations, when there is only one parent
        references = Collections.singletonList(new SofaTracerSpanReferenceRelationship(
            (SofaTracerSpanContext) referencedContext, referenceType));
    } else {
        if (references.size() == 1) {
            //To ensure order
            references = new ArrayList<>(references);
        }
        references.add(new SofaTracerSpanReferenceRelationship(
            (SofaTracerSpanContext) referencedContext, referenceType));
    }
    return this;
}
 
Example #18
Source File: SpringJmsAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void onMessageEnter(final Object msg) {
  if (LocalSpanContext.get(COMPONENT_NAME) != null) {
    LocalSpanContext.get(COMPONENT_NAME).increment();
    return;
  }

  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder builder = tracer
    .buildSpan("onMessage")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER);

  SpanContext spanContext = null;
  if (msg instanceof SpanContextContainer)
    spanContext = ((SpanContextContainer)msg).getSpanContext();

  if (spanContext == null)
    spanContext = TracingMessageUtils.extract((Message)msg, tracer);

  if (spanContext != null)
    builder.addReference(References.FOLLOWS_FROM, spanContext);

  final Span span = builder.start();
  LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span));
}
 
Example #19
Source File: PulsarClientAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static void buildConsumerSpan(final Consumer<?> consumer, final Message<?> message) {
  final Tracer tracer = GlobalTracer.get();
  final SpanContext parentContext = tracer.extract(Builtin.TEXT_MAP, new TextMapAdapter(message.getProperties()));

  final SpanBuilder spanBuilder = tracer
    .buildSpan("receive")
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER)
    .withTag("topic", consumer.getTopic())
    .withTag("subscription", consumer.getSubscription())
    .withTag(Tags.PEER_SERVICE, "pulsar");

  if (parentContext != null)
    spanBuilder.addReference(References.FOLLOWS_FROM, parentContext);

  spanBuilder.start().finish();
}
 
Example #20
Source File: APMSpanTest.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindPrimaryReferenceSingleChildOfSpanContextWithOtherRefs() {
    Tracer tracer = new APMTracer();

    SpanContext spanCtx1 = extractSpanContext(tracer, TEST_APM_ID1);

    Reference ref1 = new Reference(References.CHILD_OF, spanCtx1);

    Span span2 = tracer.buildSpan("test2").start();
    Reference ref2 = new Reference(References.FOLLOWS_FROM, span2.context());

    Span span3 = tracer.buildSpan("test3").start();
    Reference ref3 = new Reference(References.CHILD_OF, span3.context());
    Span span4 = tracer.buildSpan("test4").start();
    Reference ref4 = new Reference(References.CHILD_OF, span4.context());

    assertEquals(ref1, APMSpan.findPrimaryReference(Arrays.asList(ref1, ref2, ref3, ref4)));
}
 
Example #21
Source File: TracedRunnable.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  final Tracer tracer = GlobalTracer.get();
  if (verbose) {
    final Span span = tracer
      .buildSpan("runnable")
      .withTag(Tags.COMPONENT, "java-concurrent")
      .addReference(References.FOLLOWS_FROM, parent.context())
      .start();
    try (final Scope scope = tracer.activateSpan(span)) {
      delegate.run();
    }
    finally {
      span.finish();
    }
  }
  else {
    try (final Scope scope = tracer.activateSpan(parent)) {
      delegate.run();
    }
  }
}
 
Example #22
Source File: PulsarFunctionsAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void handleMessageEnter(final Object function, final Object contextArg, final Object arg0) {
  final Tracer tracer = GlobalTracer.get();
  final SpanBuilder spanBuilder = tracer
    .buildSpan(getFunctionName(function, contextArg))
    .withTag(Tags.COMPONENT, COMPONENT_NAME)
    .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_SERVER);

  if (arg0 != null) {
    final Record<?> record = (Record<?>)arg0;
    final SpanContext spanContext = tracer.extract(Builtin.TEXT_MAP, new TextMapExtractAdapter(record.getProperties()));
    if (spanContext != null)
      spanBuilder.addReference(References.FOLLOWS_FROM, spanContext);
  }

  final Span span = spanBuilder.start();
  final Scope scope = tracer.activateSpan(span);

  LocalSpanContext.set(COMPONENT_NAME, span, scope);
}
 
Example #23
Source File: SkywalkingSpanBuilder.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Ignore the reference type. the span always the entry or has a parent span.
 */
@Override
public Tracer.SpanBuilder addReference(String referenceType, SpanContext referencedContext) {
    if (References.FOLLOWS_FROM.equals(referenceType)) {
        throw new IllegalArgumentException("only support CHILD_OF reference");
    }
    return asChildOf(referencedContext);
}
 
Example #24
Source File: DependenciesTest.java    From spark-dependencies with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleReferences() throws Exception {
  Tuple<Tracer, Flushable> s1Tuple = TracersGenerator.createJaeger("S1", collectorUrl);
  Tuple<Tracer, Flushable> s2Tuple = TracersGenerator.createJaeger("S2", collectorUrl);
  Tuple<Tracer, Flushable> s3Tuple = TracersGenerator.createJaeger("S3", collectorUrl);

  Span s1Span = s1Tuple.getA().buildSpan("foo")
      .ignoreActiveSpan()
      .start();
  Span s2Span = s2Tuple.getA().buildSpan("bar")
      .addReference(References.CHILD_OF, s1Span.context())
      .start();
  Span s3Span = s3Tuple.getA().buildSpan("baz")
      .addReference(References.CHILD_OF, s1Span.context())
      .addReference(References.FOLLOWS_FROM, s2Span.context())
      .start();

  s1Span.finish();
  s2Span.finish();
  s3Span.finish();
  s1Tuple.getB().flush();
  s2Tuple.getB().flush();
  s3Tuple.getB().flush();
  waitJaegerQueryContains("S1", "foo");
  waitJaegerQueryContains("S2", "bar");
  waitJaegerQueryContains("S3", "baz");

  deriveDependencies();

  Map<String, Map<String, Long>> expectedDependencies = new HashMap<>();
  Map<String, Long> s1Descendants = new HashMap<>();
  s1Descendants.put("S2", 1L);
  s1Descendants.put("S3", 1L);
  expectedDependencies.put("S1", s1Descendants);
  Map<String, Long> s2Descendants = new HashMap<>();
  s2Descendants.put("S3", 1L);
  expectedDependencies.put("S2", s2Descendants);
  assertDependencies(expectedDependencies);
}
 
Example #25
Source File: Actor.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
public Future<String> ask(final String message) {
  final Span parent = tracer.scopeManager().activeSpan();
  phaser.register();
  Future<String> future =
      executor.submit(
          new Callable<String>() {
            @Override
            public String call() throws Exception {
              Span span = tracer
                  .buildSpan("received")
                  .addReference(References.FOLLOWS_FROM, parent.context())
                  .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
                  .start();
              try {
                phaser.arriveAndAwaitAdvance(); // child tracer started
                phaser.arriveAndAwaitAdvance(); // assert size
                return "received " + message;
              } finally {
                span.finish();

                phaser.arriveAndAwaitAdvance(); // child tracer finished
                phaser.arriveAndAwaitAdvance(); // assert size
              }
            }
          });
  return future;
}
 
Example #26
Source File: APMSpan.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
protected void initReferences(APMSpanBuilder builder, TraceRecorder recorder, ContextSampler sampler) {
    // Find primary reference
    Reference primaryRef = findPrimaryReference(builder.references);

    if (primaryRef != null) {
        // Primary reference found, so it will provide the main 'parent' relationship
        // to the existing trace instance. Other relationships will be recorded as
        // correlation identifiers.

        // Process references to extracted trace state
        if (primaryRef.getReferredTo() instanceof APMSpanBuilder) {
            initFromExtractedTraceState(builder, recorder, primaryRef, sampler);

        } else if (primaryRef.getReferredTo() instanceof APMSpan) {

            // Process references for direct ChildOf
            if (References.CHILD_OF.equals(primaryRef.getReferenceType())) {
                initChildOf(builder, primaryRef);

                // Process references for direct FollowsFrom
            } else if (References.FOLLOWS_FROM.equals(primaryRef.getReferenceType())) {
                initFollowsFrom(builder, recorder, primaryRef, sampler);
            }
        }
    } else {
        processNoPrimaryReference(builder, recorder, sampler);
    }
}
 
Example #27
Source File: TracingService.java    From nakadi with MIT License 5 votes vote down vote up
public static Span getNewSpanWithReference(final String operationName, final Long timeStamp,
                                           final SpanContext referenceSpanContext) {
    return GlobalTracer.get()
            .buildSpan(operationName)
            .addReference(References.FOLLOWS_FROM, referenceSpanContext)
            .withStartTimestamp(TimeUnit.MILLISECONDS.toMicros(timeStamp))
            .start();
}
 
Example #28
Source File: APMSpanTest.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindPrimaryReferenceSingleChildOfSpan() {
    Tracer tracer = new APMTracer();
    Span span = tracer.buildSpan("test").start();

    Reference ref = new Reference(References.CHILD_OF, span.context());
    assertEquals(ref, APMSpan.findPrimaryReference(Arrays.asList(ref)));
}
 
Example #29
Source File: OpenTracing0_33_BraveSpanBuilderTest.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
/** Ensures when the caller invokes with null, nothing happens */
@Test public void addReference_nullContext_noop() {
  BraveSpanBuilder builder = newSpanBuilder().addReference(References.CHILD_OF, null);

  assertThat(builder).usingRecursiveComparison()
      .isEqualTo(newSpanBuilder());
}
 
Example #30
Source File: BraveSpanBuilder.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
@Override public BraveSpanBuilder addReference(String type, SpanContext context) {
  if (reference != null || context == null) return this;
  if (References.CHILD_OF.equals(type) || References.FOLLOWS_FROM.equals(type)) {
    this.reference = (BraveSpanContext) context;
  }
  return this;
}