Example usage for com.mongodb.event CommandStartedEvent getCommand

List of usage examples for com.mongodb.event CommandStartedEvent getCommand

Introduction

In this page you can find the example usage for com.mongodb.event CommandStartedEvent getCommand.

Prototype

public BsonDocument getCommand() 

Source Link

Document

Gets the command document.

Usage

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

License:Open Source License

public void commandStarted(CommandStartedEvent event) {
    BsonDocument document = event.getCommand();
    Labels.Builder labels = Labels.builder();
    String commandName = event.getCommandName();
    labels.add(MongoLabels.COMMAND_NAME, commandName);
    String databaseName = event.getDatabaseName();
    labels.add(MongoLabels.DATABASE_NAME, databaseName);
    labels.add(MongoLabels.REQUEST_ID, Integer.toString(event.getRequestId()));
    if (document.containsKey("batchSize")) {
        int batchSize = document.getInt32("batchSize").getValue();
        labels.add(MongoLabels.BATCH_SIZE, Integer.toString(batchSize));
    }//from  ww  w  .  jav  a  2 s .co m
    String collectionKey = collectionKeyByCommand.get(commandName);
    if (collectionKey != null && document.containsKey(collectionKey)) {
        String collectionName = document.getString(collectionKey).getValue();
        labels.add(MongoLabels.COLLECTION_NAME, collectionName);
    }

    TraceContext context = tracer.startSpan(commandName);
    tracer.annotateSpan(context, labels.build());
    contexts.set(new MongoDBCommandTraceContext(context, event.getRequestId()));
}

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

License:Apache License

private static void decorate(Span span, CommandStartedEvent event) {
    Tags.COMPONENT.set(span, COMPONENT_NAME);
    Tags.DB_STATEMENT.set(span, event.getCommand().toString());
    Tags.DB_INSTANCE.set(span, event.getDatabaseName());

    Tags.PEER_HOSTNAME.set(span, event.getConnectionDescription().getServerAddress().getHost());

    InetAddress inetAddress = event.getConnectionDescription().getServerAddress().getSocketAddress()
            .getAddress();//from  w  ww.  jav  a2s.c o m

    if (inetAddress instanceof Inet4Address) {
        byte[] address = inetAddress.getAddress();
        Tags.PEER_HOST_IPV4.set(span, ByteBuffer.wrap(address).getInt());
    } else {
        Tags.PEER_HOST_IPV6.set(span, inetAddress.getHostAddress());
    }

    Tags.PEER_PORT.set(span, event.getConnectionDescription().getServerAddress().getPort());
    Tags.DB_TYPE.set(span, "mongo");
}

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

License:Open Source License

@Override
public void commandStarted(final CommandStartedEvent event) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Sent command '{}:{}' with id {} to database '{}' " + "on connection '{}' to server '{}'",
                event.getCommandName(), event.getCommand().get(event.getCommandName()), event.getRequestId(),
                event.getDatabaseName(), event.getConnectionDescription().getConnectionId(),
                event.getConnectionDescription().getServerAddress());
    }/*from ww  w  .  ja  va 2  s .  com*/
}