io.opentracing.Tracer.SpanBuilder Java Examples

The following examples show how to use io.opentracing.Tracer.SpanBuilder. 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: TenantClientImplTest.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Sets up the fixture.
 */
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {

    final SpanContext spanContext = mock(SpanContext.class);

    span = mock(Span.class);
    when(span.context()).thenReturn(spanContext);
    final SpanBuilder spanBuilder = HonoClientUnitTestHelper.mockSpanBuilder(span);

    tracer = mock(Tracer.class);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);

    vertx = mock(Vertx.class);
    final ProtonReceiver receiver = HonoClientUnitTestHelper.mockProtonReceiver();
    sender = HonoClientUnitTestHelper.mockProtonSender();

    final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
    connection = HonoClientUnitTestHelper.mockHonoConnection(vertx, config);
    when(connection.getTracer()).thenReturn(tracer);

    cache = mock(ExpiringValueCache.class);
    client = new TenantClientImpl(connection, sender, receiver);
}
 
Example #2
Source File: RequestHandler.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
public void beforeRequest(Object request, Context context) {
  logger.info("before send {}", request);

  // we cannot use active span because we don't know in which thread it is executed
  // and we cannot therefore activate span. thread can come from common thread pool.
  SpanBuilder spanBuilder =
      tracer
          .buildSpan(OPERATION_NAME)
          .ignoreActiveSpan()
          .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);

  if (parentContext != null) {
    spanBuilder.asChildOf(parentContext);
  }

  context.put("span", spanBuilder.start());
}
 
Example #3
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 #4
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 #5
Source File: SQL.java    From enmasse with Apache License 2.0 6 votes vote down vote up
public static Span startSqlSpan(final Tracer tracer, final SpanContext context, final String operationName, final Consumer<Tracer.SpanBuilder> customizer) {

        if (tracer == null || context == null) {
            return null;
        }

        final SpanBuilder builder = TracingHelper
                .buildChildSpan(tracer, context, operationName, SQL.class.getSimpleName())
                .withTag(Tags.DB_TYPE.getKey(), "sql");

        if (customizer != null) {
            customizer.accept(builder);
        }

        return builder.start();

    }
 
Example #6
Source File: LoadWorker.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String doGeneralGetCall(String url, SpanContext parent, String kindOfSpanReference) {
	Request request = new Request.Builder().url(url).get().build();

	SpanBuilder spanBuilder = getTracer().buildSpan("GET: " + url);
	spanBuilder.addReference(kindOfSpanReference, parent);
	Span span = spanBuilder.start();

	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		Response response = httpClient.newCall(request).execute();
		if (!response.isSuccessful()) {
			Logger.log("Failed to call GET:" + url);
			return null;
		}
		return response.body().string();
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
	} finally {
		span.finish();
	}
	return null;
}
 
Example #7
Source File: LoadWorker.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Customer registerRandomCustomer(SpanContext parent) {
	String newCustomerJSon = getNewCustomerJSonString();
	RequestBody body = RequestBody.create(JSON, newCustomerJSon);
	Request request = new Request.Builder().url(urlCustomer + "/customers").put(body).build();

	SpanBuilder spanBuilder = getTracer().buildSpan("Create random user");
	spanBuilder.asChildOf(parent);
	Span span = spanBuilder.start();

	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		Response response = httpClient.newCall(request).execute();
		if (!response.isSuccessful()) {
			Logger.log("Failed to create customer " + newCustomerJSon);
			return null;
		}
		return Customer.fromJSon(response.body().string());
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
	} finally {
		span.finish();
	}
	return null;
}
 
Example #8
Source File: SpanBuilderShim.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@Override
public SpanBuilder withTag(String key, Number value) {
  // TODO - Verify only the 'basic' types are supported/used.
  if (value instanceof Integer
      || value instanceof Long
      || value instanceof Short
      || value instanceof Byte) {
    this.spanBuilderAttributeKeys.add(key);
    this.spanBuilderAttributeValues.add(AttributeValue.longAttributeValue(value.longValue()));
  } else if (value instanceof Float || value instanceof Double) {
    this.spanBuilderAttributeKeys.add(key);
    this.spanBuilderAttributeValues.add(AttributeValue.doubleAttributeValue(value.doubleValue()));
  } else {
    throw new IllegalArgumentException("Number type not supported");
  }

  return this;
}
 
Example #9
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 #10
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 #11
Source File: DeviceConnectionClientImplTest.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Sets up the fixture.
 */
@BeforeEach
public void setUp() {

    final SpanContext spanContext = mock(SpanContext.class);

    span = mock(Span.class);
    when(span.context()).thenReturn(spanContext);
    final SpanBuilder spanBuilder = HonoClientUnitTestHelper.mockSpanBuilder(span);

    final Tracer tracer = mock(Tracer.class);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);

    final Vertx vertx = mock(Vertx.class);
    final ProtonReceiver receiver = HonoClientUnitTestHelper.mockProtonReceiver();
    sender = HonoClientUnitTestHelper.mockProtonSender();

    final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
    final HonoConnection connection = HonoClientUnitTestHelper.mockHonoConnection(vertx, config);
    when(connection.getTracer()).thenReturn(tracer);

    client = new DeviceConnectionClientImpl(connection, Constants.DEFAULT_TENANT, sender, receiver);
}
 
Example #12
Source File: TracingChannelInterceptor.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Message<?> preSendServerSpan(final Message<?> message) {
  final String destination = (String)message.getHeaders().get(SIMP_DESTINATION);
  final SpanBuilder spanBuilder = tracer
    .buildSpan(destination != null ? destination : UNKNOWN_DESTINATION)
    .withTag(Tags.SPAN_KIND.getKey(), spanKind)
    .withTag(Tags.COMPONENT.getKey(), WEBSOCKET);

  final Map<String,List<String>> nativeHeaders = (Map<String,List<String>>)message.getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS);
  SpanContext spanContext = null;
  if (nativeHeaders != null)
    spanContext = tracer.extract(Builtin.TEXT_MAP, new NativeHeadersExtractAdapter(nativeHeaders));

  if (spanContext == null)
    spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(message.getHeaders()));

  if (spanContext != null)
    spanBuilder.asChildOf(spanContext);

  final Span span = spanBuilder.start();
  return MessageBuilder.fromMessage(message).setHeader(OPENTRACING_SPAN, span).build();
}
 
Example #13
Source File: SpanBuilderShim.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@Override
public SpanBuilder addReference(String referenceType, SpanContext referencedContext) {
  if (referencedContext == null) {
    return this;
  }

  // TODO - Use referenceType
  SpanContextShim contextShim = getContextShim(referencedContext);

  if (parentSpan == null && parentSpanContext == null) {
    parentSpanContext = contextShim;
  } else {
    parentLinks.add(contextShim.getSpanContext());
  }

  return this;
}
 
Example #14
Source File: SpanBuilderWrapperTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
void addReferenceOnParentSpanContextNull() {
    MockTracer delegateTracer = new MockTracer();
    TracerWrapper tracerWrapper = new TracerWrapper(delegateTracer);
    String operationName = "addReferenceOnParentSpanContextNull";
    SpanBuilderWrapper spanBuilderWrapper = new SpanBuilderWrapper(tracerWrapper, operationName,
            delegateTracer.buildSpan(operationName));

    SpanBuilder spanBuilder = spanBuilderWrapper.addReference(References.CHILD_OF, null);
    assertSame(spanBuilderWrapper, spanBuilder);
    assertNull(spanBuilderWrapper.parentId());
}
 
Example #15
Source File: SpanBuilderWrapperTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
void asChildOfOnParentSpanContextNull() {
    MockTracer delegateTracer = new MockTracer();
    TracerWrapper tracerWrapper = new TracerWrapper(delegateTracer);
    String operationName = "asChildOfOnParentSpanContextNull";
    SpanBuilderWrapper spanBuilderWrapper = new SpanBuilderWrapper(tracerWrapper, operationName,
            delegateTracer.buildSpan(operationName));

    SpanBuilder spanBuilder = spanBuilderWrapper.asChildOf((SpanContext) null);
    assertSame(spanBuilderWrapper, spanBuilder);
    assertNull(spanBuilderWrapper.parentId());
}
 
Example #16
Source File: SpanBuilderWrapperTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
void asChildOfOnParentSpanNull() {
    MockTracer delegateTracer = new MockTracer();
    TracerWrapper tracerWrapper = new TracerWrapper(delegateTracer);
    String operationName = "asChildOfOnParentSpanNull";
    SpanBuilderWrapper spanBuilderWrapper = new SpanBuilderWrapper(tracerWrapper, operationName,
            delegateTracer.buildSpan(operationName));

    SpanBuilder spanBuilder = spanBuilderWrapper.asChildOf((Span) null);
    assertSame(spanBuilderWrapper, spanBuilder);
    assertNull(spanBuilderWrapper.parentId());
}
 
Example #17
Source File: SpanBuilderWrapperTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
void asChildOfOnParentSpan() {
    MockTracer delegateTracer = new MockTracer();
    Span parentSpan = delegateTracer.buildSpan("parentSpan").start();
    TracerWrapper tracerWrapper = new TracerWrapper(delegateTracer);
    String operationName = "asChildOfOnParentSpan";
    SpanBuilderWrapper spanBuilderWrapper = new SpanBuilderWrapper(tracerWrapper, operationName,
            delegateTracer.buildSpan(operationName));

    SpanBuilder spanBuilder = spanBuilderWrapper.asChildOf(parentSpan);
    assertSame(spanBuilderWrapper, spanBuilder);
    assertNotNull(spanBuilderWrapper.parentId());
    assertEquals(parentSpan.context().toSpanId(), spanBuilderWrapper.parentId());
}
 
Example #18
Source File: OpenTracingHelper.java    From java-agent with Apache License 2.0 5 votes vote down vote up
@Override
public SpanBuilder addReference(String type, SpanContext ctx) {
    if (ctx != null) {
        spanBuilder.addReference(type, ctx);
    }
    return this;
}
 
Example #19
Source File: LoadWorker.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String removeOwner(RealizedOrder realizedOrder, SpanContext ctx) {
	System.out.println("User " + realizedOrder.getCustomer() + " picked up order #"
			+ realizedOrder.getOrder().getOrderId() + ". Now removing customer.");

	Customer customer = realizedOrder.getCustomer();
	String url = urlCustomer + "/customers/" + customer.getId();
	Request request = new Request.Builder().url(url).delete().build();

	SpanBuilder spanBuilder = getTracer().buildSpan("DELETE: " + url);
	spanBuilder.addReference(References.FOLLOWS_FROM, ctx);
	Span span = spanBuilder.start();

	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		Response response = httpClient.newCall(request).execute();
		if (!response.isSuccessful()) {
			Logger.log("Failed to call DELETE:" + url);
			return null;
		}
		System.out.println("User " + realizedOrder.getCustomer() + " removed.");
		// FIXME: Get from return value
		return String.valueOf(customer.getId());
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
	} finally {
		span.finish();
	}
	return null;
}
 
Example #20
Source File: LoadWorker.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private RobotOrder postOrder(Customer c, List<RobotOrderLineItem> lineItems, SpanContext parent) {
	String url = urlOrder + "/orders/new";
	JsonObjectBuilder jsonBodyBuilder = Json.createObjectBuilder();
	jsonBodyBuilder.add(Customer.KEY_CUSTOMER_ID, String.valueOf(c.getId()));

	JsonArrayBuilder lineItemBuilder = Json.createArrayBuilder();
	for (RobotOrderLineItem lineItem : lineItems) {
		lineItemBuilder.add(lineItem.toJSon());
	}

	jsonBodyBuilder.add(RobotOrder.KEY_LINE_ITEMS, lineItemBuilder);
	String bodyStr = jsonBodyBuilder.build().toString();
	RequestBody body = RequestBody.create(JSON, bodyStr);

	Request request = new Request.Builder().url(url).post(body).build();

	SpanBuilder spanBuilder = getTracer().buildSpan("POST: " + url);
	spanBuilder.asChildOf(parent);
	Span span = spanBuilder.start();

	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		Response response = httpClient.newCall(request).execute();
		if (!response.isSuccessful()) {
			Logger.log("Failed to call POST:" + url);
			Logger.log("Response: " + response.body().string());
			return null;
		}
		return RobotOrder.fromJSon(response.body().string());
	} catch (IOException e) {
		span.log(OpenTracingUtil.getSpanLogMap(e));
	} finally {
		span.finish();
	}
	return null;
}
 
Example #21
Source File: OpenTracingManager.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
protected void doStartSpanWithParent(SpanBuilder spanBuilder, String id) {
    Span parentSpan = getSpan();

    if (parentSpan != null) {
        spanBuilder.asChildOf(parentSpan);
    }

    doStartSpan(spanBuilder, id);
}
 
Example #22
Source File: Factory.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Robot createChassis(long serialNumber, String robotTypeId, SpanContext spanContext) {
	SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("creatingChassis");
	spanBuilder.asChildOf(spanContext);
	spanBuilder.withTag(RobotType.KEY_ROBOT_TYPE, robotTypeId);
	try (Scope scope = spanBuilder.startActive(true)) {
		Logger.log("Creating robot chassis!");
		// Takes 70 ms to create a robot chassis. Yep, it's a kick ass robot factory.
		Utils.sleep(70);
		return new Robot(serialNumber, robotTypeId, null);
	}
}
 
Example #23
Source File: OrderManager.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Long get() {
	SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("buildRobotRequest");
	spanBuilder.withTag(RobotType.KEY_ROBOT_TYPE, lineItem.getRobotTypeId());
	spanBuilder.withTag(Robot.KEY_COLOR, lineItem.getColor().toString());
	spanBuilder.asChildOf(parent);
	Span span = spanBuilder.start();

	try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
		FormBody.Builder formBuilder = new FormBody.Builder();
		formBuilder.add(RobotType.KEY_ROBOT_TYPE, lineItem.getRobotTypeId());
		formBuilder.add(Robot.KEY_COLOR, lineItem.getColor().toString());

		Request req = new Request.Builder().url(FACTORY_SERVICE_LOCATION + "/factory/buildrobot")
				.post(formBuilder.build()).build();

		try {
			Response response = httpClient.newCall(req).execute();
			return parseSerial(response.body().string());
		} catch (Throwable e) {
			span.log(OpenTracingUtil.getSpanLogMap(e));
		}
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
	} finally {
		span.finish();
	}
	return -1L;
}
 
Example #24
Source File: LoadWorker.java    From problematic-microservices with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void doFullRegisterOrderAndRemove() throws InterruptedException, ExecutionException {
	SpanBuilder spanBuilder = getTracer().buildSpan("fullSystemTest");
	final Span span = spanBuilder.start();
	try {
		SpanContext parentContext = span.context();

		// Register 
		CompletableFuture<Customer> newCustomer = CompletableFuture
				.supplyAsync(() -> registerRandomCustomer(parentContext));
		// Maybe not get the types and colors over and over. Looks pretty in the traces though...
		CompletableFuture<RobotType[]> availableTypes = CompletableFuture
				.supplyAsync(() -> getAllTypes(parentContext));
		CompletableFuture<Color[]> availableColors = CompletableFuture
				.supplyAsync(() -> getAllColors(parentContext));
		CompletableFuture.allOf(newCustomer, availableTypes, availableColors);

		Customer customer = newCustomer.get();

		// First completion stage done. Now we can create the order
		List<RobotOrderLineItem> lineItems = createRandomOrder(availableTypes.get(), availableColors.get());
		CompletableFuture<RobotOrder> robotOrderCompletable = CompletableFuture
				.supplyAsync(() -> postOrder(customer, lineItems, parentContext));

		// Rest will happen asynchrously when data is available...
		CompletableFuture<RealizedOrder> realizedOrderFuture = new CompletableFuture<RealizedOrder>();
		// When we have the order, we schedule the polling for an available order...
		robotOrderCompletable
				.thenAccept((order) -> awaitOrderCompletion(order, realizedOrderFuture, parentContext));
		// Once the order is realized, we will remove the customer.
		realizedOrderFuture.thenApply((realizedOrder) -> removeOwner(realizedOrder, parentContext))
				.thenAccept((customerId) -> span.finish());
	} catch (Throwable t) {
		span.log(OpenTracingUtil.getSpanLogMap(t));
		throw t;
	}
}
 
Example #25
Source File: TracingSupportingHonoResourceTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets up the fixture.
 */
@BeforeEach
public void setUp() {
    final Span span = mock(Span.class);
    spanBuilder = mock(SpanBuilder.class, RETURNS_SELF);
    when(spanBuilder.start()).thenReturn(span);
    tracer = mock(Tracer.class);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    resource = new TracingSupportingHonoResource(tracer, "test", "adapter") {
        @Override
        protected Future<ResponseCode> handlePost(final CoapExchange exchange, final Span currentSpan) {
            return Future.succeededFuture(ResponseCode.CHANGED);
        }
    };
}
 
Example #26
Source File: SpanBuilderWrapperTest.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Test
void asChildOfOnParentSpanContext() {
    MockTracer delegateTracer = new MockTracer();
    Span parentSpan = delegateTracer.buildSpan("parentSpan").start();
    TracerWrapper tracerWrapper = new TracerWrapper(delegateTracer);
    String operationName = "asChildOfOnParentSpanContext";
    SpanBuilderWrapper spanBuilderWrapper = new SpanBuilderWrapper(tracerWrapper, operationName,
            delegateTracer.buildSpan(operationName));

    SpanBuilder spanBuilder = spanBuilderWrapper.asChildOf(parentSpan.context());
    assertSame(spanBuilderWrapper, spanBuilder);
    assertNotNull(spanBuilderWrapper.parentId());
    assertEquals(parentSpan.context().toSpanId(), spanBuilderWrapper.parentId());
}
 
Example #27
Source File: ProxySpanBuilder.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Override
public <T> SpanBuilder withTag(final Tag<T> tag, final T value) {
    final TagInterceptor interceptor = plugins.interceptors().tags();
    final TagListener listener = plugins.listeners().tags();

    interceptor.intercept(tag, value).forEach(pair -> {
        pair.tag(delegate);
        pair.notify(listener, this);
    });

    return this;
}
 
Example #28
Source File: SpanBuilderWrapper.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public SpanBuilder addReference(String referenceType, SpanContext referencedContext) {
	delegate.addReference(referenceType, referencedContext);
	if (referencedContext == null) {
		return this;
	}
	parentId = referencedContext.toSpanId();
	return this;
}
 
Example #29
Source File: SpanBuilderWrapper.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public SpanBuilder asChildOf(Span parent) {
	delegate.asChildOf(parent);
	if (parent == null) {
		return this;
	}
	parentId = parent.context().toSpanId();
	return this;
}
 
Example #30
Source File: SpanBuilderWrapper.java    From java-jfr-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public SpanBuilder asChildOf(SpanContext parent) {
	delegate.asChildOf(parent);
	if (parent == null) {
		return this;
	}
	parentId = parent.toSpanId();
	return this;
}