apm-agent-java icon indicating copy to clipboard operation
apm-agent-java copied to clipboard

Add support mongodb driver sync 5.x

Open burl21 opened this issue 1 year ago • 2 comments

We have noticed that spans are not being created for MongoDB, and according to the documentation, support is currently available only for MongoDB Driver v3 and v4.

@Bean
// Micrometer
MongoClientSettingsBuilderCustomizer mongoMetricsSynchronousContextProvider(
    ObservationRegistry registry) {
  return (clientSettingsBuilder) ->
      clientSettingsBuilder
          .contextProvider(ContextProviderFactory.create(registry))
          .addCommandListener(new MongoObservationCommandListener(registry));
  }

Stack

  • spring boot v3.4.2
  • mongodb driver sync v5.2.1
  • Elastic APM agent v1.52.1
  • Jdk v23

burl21 avatar Jan 27 '25 13:01 burl21

As an alternative, this is supported by OpenTelemetry instrumentation, even if there is no explicit instrumentation for 5.x, the 4.x version seems to remain. While I did not run an exhaustive test, the initial testing with a simple spring-boot example application worked as expected with dedicated spans for MongoDB, so I think we can assume it should work for most cases.

That means using any of the following agents for instrumentation allows to work-around this limitation.

  • Elastic distribution, aka EDOT https://github.com/elastic/elastic-otel-java
  • OpenTelemetry instrumentation https://github.com/open-telemetry/opentelemetry-java-instrumentation

SylvainJuge avatar Feb 06 '25 11:02 SylvainJuge

Driver 4.x is not compatible with MongoDB 8.0. We need support for 5.x!

ysokolovski avatar Apr 24 '25 18:04 ysokolovski

Hi !

I have good news, it turns out that the implementation of the 5.x driver is very close to the 4.x which allows to reuse existing instrumentation.

I've opened https://github.com/elastic/apm-agent-java/pull/4139 PR to add support for it, if you have the ability to test with this snapshot it would be great as it helps to know if it works as expected in your applications, or if we have any missing entry point in the driver that we need to cover. For the basic use-cases, I'm pretty confident it should work as I've extended the coverage of integration test by adding 4.7.0 to 5.5.0 versions.

If you have any issue with this snapshot, don't hesitate to provide feedback on the PR or this issue.

SylvainJuge avatar Jul 03 '25 12:07 SylvainJuge