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

Fix MongoDB instrumentation for 2.29.0+ #3668

Merged
merged 2 commits into from
Sep 27, 2024
Merged

Conversation

Kielek
Copy link
Contributor

@Kielek Kielek commented Sep 26, 2024

Why

Fixes #3667 (comment)

What

Fixes loading MongoDB related assemblies.

MongoDB.Driver.Core 2.28.0+ are signed. What is more MongoDB does not follow recommendation about Assembly Versioning and Assembly Version is Equal to Library version (2.28.0.0 and 2.29.0.0).

MongoDB.Driver.Core.Extensions.DiagnosticSources references MongoDB.Driver.Core v2.28.0.
When the test application is using MongoDB.Driver.Core v2.28.0. It leads to following error:

[2024-09-26T06:23:46.2073304Z] [Debug] EventSource=OpenTelemetry-AutoInstrumentation-Loader, Message=Requester [<null>] requested [MongoDB.Driver.Core, Version=2.28.0.0, Culture=neutral, PublicKeyToken=94992a530f44e321] 
[2024-09-26T06:23:46.2920125Z] [Debug] EventSource=OpenTelemetry-AutoInstrumentation-Loader, Message=Requester [<null>] requested [MongoDB.Driver.Core, Version=2.28.0.0, Culture=neutral, PublicKeyToken=94992a530f44e321] 
[2024-09-26T06:23:46.3390112Z] [Error] Could not load file or assembly 'MongoDB.Driver.Core, Version=2.28.0.0, Culture=neutral, PublicKeyToken=94992a530f44e321' or one of its dependencies. The system cannot find the file specified.
Exception: Could not load file or assembly 'MongoDB.Driver.Core, Version=2.28.0.0, Culture=neutral, PublicKeyToken=94992a530f44e321' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'MongoDB.Driver.Core, Version=2.28.0.0, Culture=neutral, PublicKeyToken=94992a530f44e321' or one of its dependencies. The system cannot find the file specified.
File name: 'MongoDB.Driver.Core, Version=2.28.0.0, Culture=neutral, PublicKeyToken=94992a530f44e321'
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB.MongoClientIntegration.GetInstrumentationOptions()
   at OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB.MongoClientIntegration.GetClusterConfiguratorExpression()
   at OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB.MongoClientIntegration.OnMethodBegin[TTarget,TMongoClientSettings](TTarget instance, TMongoClientSettings settings)
   at OpenTelemetry.AutoInstrumentation.CallTarget.Handlers.BeginMethodHandler`3.Invoke(TTarget instance, TArg1& arg1)
   at MongoDB.Driver.MongoClient..ctor(MongoClientSettings settings)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Workaround - ignore versioning check and load assembly manually by the name (from the application context).

Alternatives

  1. Fully drop references to MongoDB.Driver.Core.Extensions.DiagnosticSources and implement instrumentation as a bytecode (we need it already partially to enable instrumentation). It can be done before release or as the follow up.

  2. Revert changes from: MongoDB.Driver.Core - support only 2.28.0+ #3604 and GraphQL support for 8.0+ #3615. It might be not the best option if we check download statistics from the last 6 weeks.

  3. Implement instrumentation on the MongoDB side, but it not short term solution.

Tests

Tested locally, as tests for MongoDB on .NET Framework are not executed in the pipeline.

Checklist

  • [ ] CHANGELOG.md is updated.
  • [ ] Documentation is updated.
  • New features are covered by tests - as a part of release process.

@Kielek Kielek requested a review from a team as a code owner September 26, 2024 10:45
@Kielek
Copy link
Contributor Author

Kielek commented Sep 26, 2024

@nrcventura, @zacharycmontoya, @rajkumar-rangaraj, @pjanotti

What is your opinion? Do you see any better options?

@Kielek Kielek mentioned this pull request Sep 26, 2024
6 tasks
@nrcventura
Copy link
Member

I think that this proposed workaround makes sense in the short and medium term. I do not think we should use alternatives 1 and 2. In the long term it would be good to pursue alternative 3.

@nrcventura
Copy link
Member

If the newer versions of the library break backwards compatibility, we may need to consider a different approach, or potentially dropping support for certain versions.

Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kielek I think the workaround is acceptable.

Copy link
Contributor

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @pjanotti, this is an acceptable workaround.

@Kielek
Copy link
Contributor Author

Kielek commented Sep 27, 2024

Thank you guys. Merging and moving forward with release.

@Kielek Kielek merged commit baf1f78 into open-telemetry:main Sep 27, 2024
41 checks passed
@Kielek Kielek deleted the mongodb-fix branch September 27, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants