use of com.mongodb.connection.ConnectionId in project brave by openzipkin.
the class TraceMongoCommandListener method commandStarted.
/**
* 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) {
String databaseName = event.getDatabaseName();
// don't trace commands like "endSessions"
if ("admin".equals(databaseName))
return;
Span span = threadLocalSpan.next();
if (span == null || span.isNoop())
return;
String commandName = event.getCommandName();
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();
}
Aggregations