Example usage for com.mongodb.event CommandFailedEvent getThrowable

List of usage examples for com.mongodb.event CommandFailedEvent getThrowable

Introduction

In this page you can find the example usage for com.mongodb.event CommandFailedEvent getThrowable.

Prototype

public Throwable getThrowable() 

Source Link

Document

Gets the throwable cause of the failure

Usage

From source file:com.google.cloud.trace.mongodb.TracingCommandListener.java

License:Open Source License

public void commandFailed(CommandFailedEvent event) {
    MongoDBCommandTraceContext commandContext = contexts.get();
    if (commandContext == null || commandContext.getRequestId() != event.getRequestId()) {
        // The context doesn't match the requestId for the event so don't make any endSpan() or
        // annotate() calls. Drop the context since it likely can't be used again.
        contexts.remove();/*from  w  ww . j  a va  2  s  . c o  m*/
        return;
    }
    Labels.Builder labels = Labels.builder();
    labels.add(MongoLabels.STATUS, "FAILURE");
    labels.add(MongoLabels.ERROR, event.getThrowable().getMessage());
    tracer.annotateSpan(commandContext.getContext(), labels.build());
    tracer.endSpan(commandContext.getContext());
    contexts.remove();
}

From source file:io.opentracing.contrib.mongo.TracingCommandListener.java

License:Apache License

@Override
public void commandFailed(CommandFailedEvent event) {
    Span span = cache.remove(event.getRequestId());
    if (span != null) {
        onError(span, event.getThrowable());
        span.finish();//  w  w  w .ja v a  2 s  .co  m
    }
}

From source file:org.eclipse.ditto.services.utils.persistence.mongo.monitoring.KamonCommandListener.java

License:Open Source License

@Override
public void commandFailed(final CommandFailedEvent event) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(//  w w w .  j  ava2  s  .  c  o m
                "Failed execution of command '{}' with id {} "
                        + "on connection '{}' to server '{}'  after {}ms with exception '{}'",
                event.getCommandName(), event.getRequestId(),
                event.getConnectionDescription().getConnectionId(),
                event.getConnectionDescription().getServerAddress(),
                event.getElapsedTime(TimeUnit.MILLISECONDS), event.getThrowable());
    }

    final long elapsedTime = event.getElapsedTime(TimeUnit.NANOSECONDS);
    final String commandName = event.getCommandName();
    recordElapsedTime(elapsedTime, commandName);
}