APISonar


io.opentracing.Span.log

> io > opentracing > Span > log
io APIs opentracing APIs Span APIs log APIs

Example 1
private final Span span;

    public Span log(Map<String, ?> fields) {
        span.log(fields);
        return this;
    }
Example 2
private Span delegate;

	public Span log(String event) {
		delegate = delegate.log(event);
		return this;
	}
Example 3
public void traceWithAsync(@Suspended final AsyncResponse asyncResponse, @Context ContainerRequestContext context) {
        final Span span = OpenTracingUtils.getRequestSpan(context).orElseThrow(() -> new RuntimeException("tracing failed"));
        span.log("In the resource method.");
        Executors.newSingleThreadExecutor().submit(() -> {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                span.log("Interrupted");
                e.printStackTrace();
            }
            span.log("Resuming");
            asyncResponse.resume("OK");
        });
        span.log("Before exiting the resource method");
    }
Example 4
private Span span;

  public void doPart(String name) {
    try (Scope scope = tracer.scopeManager().activate(span)) {
      span.log("part: " + name);
    }
  }
Example 5
public Response appLevelLogging(@Context ContainerRequestContext context) throws InterruptedException {
        final Span resourceSpan = OpenTracingUtils
                .getRequestSpan(context)
                .orElseThrow(() -> new RuntimeException("Tracing has failed"));

        resourceSpan.log("Starting expensive operation.");
        // Do the business
        Thread.sleep(200);
        resourceSpan.log("Expensive operation finished.");
        resourceSpan.setTag("expensiveOperationSuccess", true);

        return Response.ok("SUCCESS").build();
    }
Example 6
public void timeline(String message) {
        final Span current = tracer.activeSpan();
        if (current != null) {
            current.log(message);
        }
    }
Example 7
public Response childSpan(@Context ContainerRequestContext context) throws InterruptedException {
        final Span childSpan = OpenTracingUtils.getRequestChildSpan(context, "AppCreatedSpan");
        childSpan.log("Starting expensive operation.");
        // Do the business
        Thread.sleep(200);
        childSpan.log("Expensive operation finished.");
        childSpan.setTag("expensiveOperationSuccess", true);

        childSpan.finish();
        return Response.ok("SUCCESS").build();
    }
Example 8
public void testAddLogAfterFinish() {
        MockTracer tracer = new MockTracer();
        Span span = tracer.buildSpan("foo").start();
        span.finish();

        try {
            span.log("bar");
            Assert.fail();
        } catch (RuntimeException ex) {
        }
        Assert.assertEquals(1, tracer.finishedSpans().get(0).generatedErrors().size());
    }
Example 9
public static void logError(Span span, Throwable e) {
        HashMap<String, Object> fields = new HashMap<>();
        fields.put(Fields.ERROR_OBJECT, e);
        String message = e.getMessage();
        if (message != null) {
            fields.put(Fields.MESSAGE, message);
        }
        span.log(fields);
    }
Example 10
private void printHello(Span rootSpan, String helloStr) {
        Span span = tracer.buildSpan("printHello").asChildOf(rootSpan).start();
        try {
            System.out.println(helloStr);
            span.log(ImmutableMap.of("event", "println"));
        } finally {
            span.finish();
        }
    }
Example 11
private void onException(final RequestEvent event) {
        LOG.fine(() -> "onException(event=" + event.getType() + ")");
        final Scope activeScope = getAlreadyActiveScope();
        final Span activeSpan = activeScope.span();
        activeSpan.setTag(Tags.ERROR.getKey(), true);
        activeSpan.setTag(Tags.HTTP_STATUS.getKey(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
        activeSpan.log(Collections.singletonMap(Fields.EVENT, "error"));
        activeSpan.log(Collections.singletonMap(Fields.ERROR_OBJECT, event.getException()));
    }
Example 12
public static void logStreamCloseReason(final Span span, final String error) {
        if (error != null) {
            span.log(ImmutableMap.of("stream.close.reason", error));
        }
    }
Example 13
public void post(Span span, Exchange exchange, Endpoint endpoint) {
        if (exchange.isFailed()) {
            span.setTag(Tags.ERROR.getKey(), true);
            if (exchange.getException() != null) {
                Map<String, String> logEvent = new HashMap<>();
                logEvent.put("event", "error");
                logEvent.put("error.kind", "Exception");
                logEvent.put("message", exchange.getException().getMessage());
                span.log(logEvent);
            }
        }
    }
Example 14
public void error(Throwable throwable) {
        if (!span.isPresent()) {
            return;
        }

        Span theSpan = span.get();

        Tags.ERROR.set(theSpan, true);

        theSpan.log(CollectionsHelper.mapOf("event", "error",
                                            "error.object", throwable));
        theSpan.finish();
    }
Example 15
private void submit(final List<BatchItem> batch, final EventType eventType, final Span parentSpan)
            throws EventPublishingException {
        final Timeline activeTimeline = timelineService.getActiveTimeline(eventType);
        final String topic = activeTimeline.getTopic();
        final Span publishSpan = TracingService.getNewSpanWithParent(parentSpan, "publishing_to_kafka")
                .setTag(Tags.MESSAGE_BUS_DESTINATION.getKey(), topic);
        try {
            timelineService.getTopicRepository(eventType).syncPostBatch(topic, batch, eventType.getName());
        } catch (final EventPublishingException epe) {
            publishSpan.log(epe.getMessage());
            throw epe;
        } finally {
            publishSpan.finish();
        }
    }
Example 16
public Span start() {
        Span span = spanBuilder.start();
        span.log("sr");

        tags.forEach(tag -> tag.apply(span));

        return new ZipkinSpan(span);
    }