Java Code Examples for io.opentracing.Tracer.SpanBuilder#withTag()
The following examples show how to use
io.opentracing.Tracer.SpanBuilder#withTag() .
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: SpymemcachedAgentIntercept.java From java-specialagent with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public static Object get(final Object key, final Object callback) { final SpanBuilder spanBuilder = spanBuilder("get"); if (key instanceof Collection) { final Iterator<? extends CharSequence> iterator = ((Collection<? extends CharSequence>)key).iterator(); final StringBuilder builder = new StringBuilder(); for (int i = 0; iterator.hasNext(); ++i) { if (i > 0) builder.append(','); builder.append(iterator.next()); } spanBuilder.withTag("keys", builder.toString()); } else { spanBuilder.withTag("key", key.toString()).start(); } final Span span = spanBuilder.start(); return WrapperProxy.wrap(callback, new TracingGetOperationCallback((GetOperation.Callback)callback, span)); }
Example 2
Source File: OrderManager.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 3
Source File: SpymemcachedAgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
public static Object tracingCallback(final String operation, final Object key, final Object callback) { final SpanBuilder spanBuilder = spanBuilder(operation); if (key != null) spanBuilder.withTag("key", key.toString()); final Span span = spanBuilder.start(); return WrapperProxy.wrap(callback, new TracingOperationCallback((OperationCallback)callback, span)); }
Example 4
Source File: AkkaAgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
public static Object aroundReceiveStart(final Object thiz, final Object message) { if (!(message instanceof TracedMessage) && LocalSpanContext.get(COMPONENT_NAME) != null) { LocalSpanContext.get(COMPONENT_NAME).increment(); return message; } final Tracer tracer = GlobalTracer.get(); final SpanBuilder spanBuilder = tracer .buildSpan("receive") .withTag(Tags.COMPONENT, COMPONENT_NAME) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER); final TracedMessage<?> tracedMessage; if (message instanceof TracedMessage) { tracedMessage = (TracedMessage<?>)message; spanBuilder.addReference(References.FOLLOWS_FROM, tracedMessage.spanContext(tracer)); } else { tracedMessage = null; spanBuilder.withTag(Tags.MESSAGE_BUS_DESTINATION, ((AbstractActor)thiz).getSelf().path().toString()); } final Span span = spanBuilder.start(); final Scope scope = tracer.activateSpan(span); LocalSpanContext.set(COMPONENT_NAME, span, scope); return tracedMessage != null ? tracedMessage.getMessage() : message; }
Example 5
Source File: KafkaStreamsAgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
public static void onNextRecordExit(final Object record) { if (record == null) return; if (LocalSpanContext.get(COMPONENT_NAME) != null) { LocalSpanContext.get(COMPONENT_NAME).increment(); return; } final Tracer tracer = GlobalTracer.get(); final StampedRecord stampedRecord = (StampedRecord)record; final SpanBuilder spanBuilder = tracer.buildSpan("consume") .withTag(Tags.COMPONENT, COMPONENT_NAME) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER) .withTag(Tags.PEER_SERVICE, "kafka") .withTag("partition", stampedRecord.partition()) .withTag("offset", stampedRecord.offset()); if (stampedRecord.topic() != null) spanBuilder.withTag(Tags.MESSAGE_BUS_DESTINATION, stampedRecord.topic()); final SpanContext parentContext = TracingKafkaUtils.extractSpanContext(stampedRecord.value.headers(), tracer); if (parentContext != null) spanBuilder.asChildOf(parentContext); final Span span = spanBuilder.start(); LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span)); }
Example 6
Source File: OrderCompletionMonitor.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void run() { if (isDone) { scheduledFuture.cancel(false); return; } SpanBuilder buildSpan = GlobalTracer.get().buildSpan("pickupOrderAttempt"); buildSpan.withTag(RobotOrder.KEY_ORDER_ID, String.valueOf(order.getOrderId())); buildSpan.addReference(References.FOLLOWS_FROM, parent); try (Scope scope = buildSpan.startActive(true)) { okhttp3.HttpUrl.Builder httpBuilder = HttpUrl.parse(pickupLocation).newBuilder(); httpBuilder.addQueryParameter(RobotOrder.KEY_ORDER_ID, String.valueOf(order.getOrderId())); Request request = new Request.Builder().url(httpBuilder.build()).build(); try { Response response = httpClient.newCall(request).execute(); String body = response.body().string(); if (response.isSuccessful() && !body.isEmpty()) { isDone = true; RealizedOrder realizedOrder = RealizedOrder.fromJSon(body); future.complete(realizedOrder); scheduledFuture.cancel(false); } } catch (IOException e) { e.printStackTrace(); scheduledFuture.cancel(false); } } }
Example 7
Source File: Factory.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Robot paintRobot(Robot robotToPaint, Color paint, SpanContext spanContext) { SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("paintingRobot"); spanBuilder.asChildOf(spanContext); spanBuilder.withTag(Robot.KEY_COLOR, paint.toString()); try (Scope scope = spanBuilder.startActive(true)) { Logger.log("Painting robot!"); // Takes 50 ms to paint a robot. Yep, it's a kick ass robot factory. Utils.sleep(50); return new Robot(robotToPaint.getSerialNumber(), robotToPaint.getRobotType(), paint); } }
Example 8
Source File: Factory.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 9
Source File: OrderManager.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void run() { if (isDone) { scheduledFuture.cancel(false); return; } SpanBuilder spanBuilder = GlobalTracer.get().buildSpan("pickupFromFactoryAttempt"); spanBuilder.withTag(Robot.KEY_SERIAL_NUMBER, String.valueOf(serial)); spanBuilder.asChildOf(parent); Span span = spanBuilder.start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) { okhttp3.HttpUrl.Builder httpBuilder = HttpUrl.parse(FACTORY_SERVICE_LOCATION + "/factory/pickup") .newBuilder(); httpBuilder.addQueryParameter(Robot.KEY_SERIAL_NUMBER, String.valueOf(serial)); Request request = new Request.Builder().url(httpBuilder.build()).build(); try { Response response = httpClient.newCall(request).execute(); String body = response.body().string(); if (response.isSuccessful() && !body.isEmpty()) { isDone = true; Robot robot = Robot.fromJSon(body); future.complete(robot); scheduledFuture.cancel(false); } } catch (IOException e) { span.log(OpenTracingUtil.getSpanLogMap(e)); scheduledFuture.cancel(false); } } catch (Throwable t) { span.log(OpenTracingUtil.getSpanLogMap(t)); throw t; } finally { span.finish(); } }
Example 10
Source File: OrderManager.java From problematic-microservices with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 11
Source File: DefaultTagPair.java From opentracing-toolbox with MIT License | 4 votes |
@Override public void tag(final SpanBuilder builder) { builder.withTag(tag, value); }