Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] MongoDB driver dependency mismatch with MongoDB.Driver 3.0 #2475

Closed
mribeiro-clearsale opened this issue Nov 4, 2024 · 7 comments
Closed
Labels
bug Something isn't working community question Further information is requested

Comments

@mribeiro-clearsale
Copy link

APM Agent version

Elastic.Apm.NetCoreAll 1.30.0

Environment

Operating system and version:

.NET 8

Describe the bug

We have been updating our MongoDB.Driver since we upgraded our MongoDB Cluster to 8.0 and we have new features that are only compatible with Driver 3.0.

This new driver version has some breaking changes:
MongoDB Driver 4.0 Breaking Changes

We are having issues with Elastic APM Agent because the MongoDB.Driver used is version 2.28

The error below occurs because we have MongoDB.Driver updated to 2.30 but Elastic.APM.NetCoreAll uses 2.28

Image

And this error occurs because one of the breaking changes to MongoDB.Driver

Image

To Reproduce

Steps to reproduce the behavior:

  1. Update MongoDB.Driver to 1.30.0
  2. Build application

Expected behavior

Upgrade MongoDB.Driver dependency on Elastic.APM.NetCoreAll

@mribeiro-clearsale mribeiro-clearsale added the bug Something isn't working label Nov 4, 2024
@stevejgordon
Copy link
Contributor

Hi, @mribeiro-clearsale. Our dependency targets the minimum supported version. I've tried to reproduce on our test project by updating that to target 2.30, and I see no compilation errors, even when the Elastic.Apm.MongoDb targets 2.28. Can you provide a minimal repro so we can investigate further? Your app should resolve to use the latest version. Unless those breaking changes impact the diagnostic events we observe, I can't immediately see why this would result in compilation errors in your code.

@stevejgordon stevejgordon added question Further information is requested and removed triage labels Nov 11, 2024
@mribeiro-clearsale
Copy link
Author

Hi, Steve. Thanks for the feedback. Actually, the problem occurs because in my application I reference the dependency Elastic.Apm.NetCoreAll which has a dependency on MongoDB.Driver.Core 2.29.0 through the dependency Elastic.Apm.MongoDb. In my application, I am trying to update the dependency of MongoDB.Driver to 2.30. When I do this, an error occurs due to two different versions of the same dependency, making it impossible for me to update the driver version to 2.30.

Image

Image

Also, we use MongoDbEventSubscriber to trace MongoDB events, but an incompatibility error occurs with the IEventSubscriber interface from MongoDB.Driver 3.0.

Image

@stevejgordon
Copy link
Contributor

@mribeiro-clearsale I don't believe our NetCoreAll package should cause the issue. Our package depends on a minimum version of 2.28.0, so I suspect something else is pinning your app to 2.29.0. I cannot reproduce this in a rudimentary attempt.

Using a new .NET 8 project:

csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.30.0" />
    <PackageReference Include="MongoDB.Driver" Version="2.30.0" />
  </ItemGroup>

</Project>

Program.cs

using Elastic.Apm.MongoDb;

var settings = new MongoDB.Driver.MongoClientSettings
{
    ClusterConfigurator = builder => builder.Subscribe(new MongoDbEventSubscriber())
};

Resolve packages:
Image

We require a minimal repro to assist further.

@mribeiro-clearsale
Copy link
Author

@stevejgordon thanks again for your reply.

I just created the repo that reproduces the problem:

https://github.com/mribeiro-clearsale/ElasticAPMMongoDBDependency/tree/master

What I found strange is that in your print the NetCoreAll dependency is with version 1.30 of MongoDB.Driver.Core. But I just updated the NetCoreAll lib to 1.30.1 and the dependency remained at 1.28 as you can see in this repo

Image

@mribeiro-clearsale
Copy link
Author

I managed to solve the problem and I have no clue what happens.

We were using version 2.28 and updated via Managed Nuget Packaged for Solutions. The csproj changed correctly to 2.30, but the dependencies of other packages that also depend on the driver did not change.

Even after performing a cleanup on the solution, the problem persists.

I changed the version manually in the csproj, going back to 2.28 and then back to 2.30 and it worked magically, the dependencies of all the libs were changed correctly, solving the problem.

Thank you for your attention @stevejgordon

@stevejgordon
Copy link
Contributor

You're welcome, @mribeiro-clearsale. I'm glad you managed to resolve it.

@callumgoodridge2
Copy link

I'm having a similar issue when trying to update my MongoDB.Driver to v3 and use the MongoDbEventSubscriber. I get: Argument type 'Elastic.Apm.MongoDb.MongoDbEventSubscriber' is not assignable to parameter type 'MongoDB.Driver.Core.Events.IEventSubscriber'. This is because MongoDB.Driver.Core v2.28.0 is implicitly installed from Elastic.Apm.NetCoreAll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants