class TracingCommandListener implements CommandListener {

  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));
    }
    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()));
  }

  public  TracingCommandListener();
  public  TracingCommandListener(Tracer tracer);

}