Populate db.url for MongoDB spans.
MODIFY
instrumentation/mongo/mongo-3.1/src/test/groovy/MongoClientTest.groovy
instrumentation/mongo/mongo-3.1/src/test/groovy/MongoClientTest.groovy
@@ -267,6 +267,7 @@ class MongoClientTest extends MongoBaseTest {
"$Tags.DB_STATEMENT" {
it.replace(" ", "") == statement
}
+ "$Tags.DB_URL" "mongodb://localhost:"+port
"$Tags.DB_TYPE" "mongo"
"$Tags.DB_INSTANCE" instance
}

MODIFY
instrumentation/mongo/mongo-3.7/src/test/groovy/MongoClientTest.groovy
instrumentation/mongo/mongo-3.7/src/test/groovy/MongoClientTest.groovy
@@ -271,6 +271,7 @@ class MongoClientTest extends MongoBaseTest {
it.replace(" ", "") == statement
}
"$Tags.DB_TYPE" "mongo"
+ "$Tags.DB_URL" "mongodb://localhost:"+port
"$Tags.DB_INSTANCE" instance
}
}

MODIFY
instrumentation/mongo/mongo-async-3.3/src/test/groovy/MongoAsyncClientTest.groovy
instrumentation/mongo/mongo-async-3.3/src/test/groovy/MongoAsyncClientTest.groovy
@@ -302,6 +302,7 @@ class MongoAsyncClientTest extends MongoBaseTest {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" port
+ "$Tags.DB_URL" "mongodb://localhost:"+port
"$Tags.DB_STATEMENT" statementEval
"$Tags.DB_TYPE" "mongo"
"$Tags.DB_INSTANCE" instance

MODIFY
instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/auto/instrumentation/mongo/MongoClientDecorator.java
instrumentation/mongo/mongo-common/src/main/java/io/opentelemetry/auto/instrumentation/mongo/MongoClientDecorator.java
*/
package io.opentelemetry.auto.instrumentation.mongo;
+import com.mongodb.ServerAddress;
import com.mongodb.connection.ClusterId;
import com.mongodb.connection.ConnectionDescription;
import com.mongodb.connection.ConnectionId;
@@ -58,6 +59,23 @@ public class MongoClientDecorator extends DatabaseClientDecorator<CommandStarted
return null;
}
+ @Override
+ protected String dbUrl(final CommandStartedEvent event) {
+ final ConnectionDescription connectionDescription = event.getConnectionDescription();
+ if (connectionDescription != null) {
+ final ServerAddress sa = connectionDescription.getServerAddress();
+ if (sa != null) {
+ // https://docs.mongodb.com/manual/reference/connection-string/
+ final String host = sa.getHost();
+ final int port = sa.getPort();
+ if (host != null && port != 0) {
+ return "mongodb://" + host + ":" + port;
+ }
+ }
+ }
+ return null;
+ }
+
@Override
protected String dbInstance(final CommandStartedEvent event) {
// Use description if set.

Populate db.url for MongoDB spans. (#280)