com.mongodb.event.CommandStartedEvent Java Examples
The following examples show how to use
com.mongodb.event.CommandStartedEvent.
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: KamonCommandListener.java From ditto with Eclipse Public License 2.0 | 5 votes |
@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()); } }
Example #2
Source File: TraceMongoDbAutoConfigurationTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Override public void customize(MongoClientSettings.Builder clientSettingsBuilder) { super.customize(clientSettingsBuilder); CommandListener listener = clientSettingsBuilder.build().getCommandListeners() .get(0); listener.commandStarted(new CommandStartedEvent(0, null, "", "", BDDMockito.mock(BsonDocument.class))); listener.commandSucceeded(new CommandSucceededEvent(1, null, "", BDDMockito.mock(BsonDocument.class), 100)); }
Example #3
Source File: TraceMongoCommandListener.java From brave with Apache License 2.0 | 5 votes |
/** * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but * all callbacks happen on the same thread. */ @Override public void commandStarted(CommandStartedEvent event) { Span span = threadLocalSpan.next(); if (span == null || span.isNoop()) return; String commandName = event.getCommandName(); String databaseName = event.getDatabaseName(); BsonDocument command = event.getCommand(); String collectionName = getCollectionName(command, commandName); span.name(getSpanName(commandName, collectionName)) .kind(CLIENT) .remoteServiceName("mongodb-" + databaseName) .tag("mongodb.command", commandName); if (collectionName != null) { span.tag("mongodb.collection", collectionName); } ConnectionDescription connectionDescription = event.getConnectionDescription(); if (connectionDescription != null) { ConnectionId connectionId = connectionDescription.getConnectionId(); if (connectionId != null) { span.tag("mongodb.cluster_id", connectionId.getServerId().getClusterId().getValue()); } try { InetSocketAddress socketAddress = connectionDescription.getServerAddress().getSocketAddress(); span.remoteIpAndPort(socketAddress.getAddress().getHostAddress(), socketAddress.getPort()); } catch (MongoSocketException ignored) { } } span.start(); }
Example #4
Source File: TraceMongoCommandListenerTest.java From brave with Apache License 2.0 | 5 votes |
CommandStartedEvent createCommandStartedEvent() { return new CommandStartedEvent( 1, createConnectionDescription(), "dbName", "insert", LONG_COMMAND ); }