-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenTracing command listener to Mongo client.
- Loading branch information
Showing
10 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...b-client/deployment/src/test/java/io/quarkus/mongodb/MongoTracingCommandListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.client.MongoClient; | ||
|
||
import io.opentracing.mock.MockSpan; | ||
import io.opentracing.mock.MockTracer; | ||
import io.opentracing.util.GlobalTracer; | ||
import io.opentracing.util.GlobalTracerTestUtil; | ||
import io.quarkus.mongodb.tracing.MongoTracingCommandListener; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Test the inclusion and config of the {@link MongoTracingCommandListener}. | ||
* | ||
* @see io.quarkus.smallrye.opentracing.deployment.TracingTest | ||
*/ | ||
public class MongoTracingCommandListenerTest extends MongoTestBase { | ||
|
||
@Inject | ||
MongoClient client; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class)) | ||
.withConfigurationResource("application-tracing-mongo.properties"); | ||
|
||
static MockTracer mockTracer = new MockTracer(); | ||
static { | ||
GlobalTracer.register(mockTracer); | ||
} | ||
|
||
@BeforeEach | ||
public void before() { | ||
mockTracer.reset(); | ||
} | ||
|
||
@AfterAll | ||
public static void afterAll() { | ||
GlobalTracerTestUtil.resetGlobalTracer(); | ||
} | ||
|
||
@AfterEach | ||
void cleanup() { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
void testClientInitialization() { | ||
assertThat(mockTracer.finishedSpans()).hasSize(0); | ||
|
||
assertThat(client.listDatabaseNames().first()).isNotEmpty(); | ||
|
||
assertThat(mockTracer.finishedSpans()).hasSize(1); | ||
MockSpan span = mockTracer.finishedSpans().get(0); | ||
assertThat(span.operationName()).isEqualTo("listDatabases"); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
extensions/mongodb-client/deployment/src/test/resources/application-tracing-mongo.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
quarkus.mongodb.connection-string=mongodb://localhost:27018 | ||
quarkus.mongodb.tracing.enabled=true | ||
|
||
|
||
quarkus.jaeger.enabled=true | ||
quarkus.jaeger.service-name=tracing-test | ||
quarkus.jaeger.sampler-param=1 | ||
quarkus.jaeger.sampler-type=const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...-client/runtime/src/main/java/io/quarkus/mongodb/tracing/MongoTracingCommandListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.mongodb.tracing; | ||
|
||
import com.mongodb.event.CommandFailedEvent; | ||
import com.mongodb.event.CommandListener; | ||
import com.mongodb.event.CommandStartedEvent; | ||
import com.mongodb.event.CommandSucceededEvent; | ||
|
||
import io.opentracing.contrib.mongo.common.TracingCommandListener; | ||
import io.opentracing.util.GlobalTracer; | ||
import io.vertx.core.logging.Logger; | ||
import io.vertx.core.logging.LoggerFactory; | ||
|
||
/** | ||
* Command Listener for Mongo client delegated to {@link TracingCommandListener}. | ||
* | ||
*/ | ||
public class MongoTracingCommandListener implements CommandListener { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MongoTracingCommandListener.class); | ||
|
||
private TracingCommandListener delegate; | ||
|
||
public MongoTracingCommandListener() { | ||
this.delegate = new TracingCommandListener.Builder(GlobalTracer.get()).build(); | ||
LOGGER.debug("TracingCommandListener Delegate created"); | ||
} | ||
|
||
@Override | ||
public void commandStarted(CommandStartedEvent event) { | ||
LOGGER.trace("commandStarted event " + event.getCommandName()); | ||
delegate.commandStarted(event); | ||
} | ||
|
||
@Override | ||
public void commandFailed(CommandFailedEvent event) { | ||
LOGGER.trace("commandFailed event " + event.getCommandName()); | ||
delegate.commandFailed(event); | ||
} | ||
|
||
@Override | ||
public void commandSucceeded(CommandSucceededEvent event) { | ||
LOGGER.trace("commandSucceded event " + event.getCommandName()); | ||
delegate.commandSucceeded(event); | ||
} | ||
|
||
} |