Skip to content

Conversation

@ysolomchenko
Copy link
Contributor

@ysolomchenko ysolomchenko commented Dec 2, 2024

Why

Transitioning to bytecode instrumentation because the MongoDB.Driver and MongoDB.Driver.Core libraries are being merged into a single MongoDB.Driver library starting from version 3.0.0

Fixes #3738

What

Bytecode instrumentation for MongoDB with following attributes:

  • db.system
  • db.collection.name
  • db.namespace
  • db.operation.name
  • server.address
  • server.port
  • network.peer.address
  • network.peer.port

The implementation targets MongoDB.Driver and MongoDB.Driver.Core versions from 2.7.0 to the latest.

Tests

Manual + CI

Checklist

  • CHANGELOG.md is updated.
  • Documentation is updated.
  • New features are covered by tests.

@Kielek
Copy link
Member

Kielek commented Dec 3, 2024

You might be interested in following pieces of code:

  • <ItemGroup>
    <!-- MongoDB.Driver.Core is required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="MongoDB.Driver.Core" ExcludeAssets="all" />
    <!-- AWSSDK.Core is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="AWSSDK.Core" ExcludeAssets="all" />
    <!-- "AWSSDK.SecurityToken is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="AWSSDK.SecurityToken" ExcludeAssets="all" />
    <!-- DnsClient is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="DnsClient" ExcludeAssets="all" />
    <!-- MongoDB.Bson is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="MongoDB.Bson" ExcludeAssets="all" />
    <!-- MongoDB.Libmongocrypt is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="MongoDB.Libmongocrypt" ExcludeAssets="all" />
    <!-- Snappier is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="Snappier" ExcludeAssets="all" />
    <!-- System.Net.Http is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Net.Http" ExcludeAssets="all" />
    <!-- System.Runtime.InteropServices.RuntimeInformation is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" ExcludeAssets="all" />
    <!-- System.Security.Cryptography.Algorithms is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Security.Cryptography.Algorithms" ExcludeAssets="all" />
    <!-- System.Security.Cryptography.Encoding is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Security.Cryptography.Encoding" ExcludeAssets="all" />
    <!-- System.Security.Cryptography.Primitives is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Security.Cryptography.Primitives" ExcludeAssets="all" />
    <!-- System.Security.Cryptography.X509Certificates is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Security.Cryptography.X509Certificates" ExcludeAssets="all" />
    <!-- System.Text.Encoding.CodePages is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="System.Text.Encoding.CodePages" ExcludeAssets="all" />
    <!-- SharpCompress is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="SharpCompress" ExcludeAssets="all" />
    <!-- ZstdSharp.Port is tranistive dependency required by MongoDB.Driver.Core.Extensions.DiagnosticSources. -->
    <PackageReference Include="ZstdSharp.Port" ExcludeAssets="all" />
    </ItemGroup>
  • <!-- Versions from CommonExcludedAssets.props -->
    <ItemGroup>
    <PackageVersion Include="AWSSDK.Core" Version="3.7.100.14" />
    <PackageVersion Include="AWSSDK.SecurityToken" Version="3.7.100.14" />
    <PackageVersion Include="DnsClient" Version="1.6.1" />
    <PackageVersion Include="Microsoft.Win32.SystemEvents" Version="4.7.0" />
    <PackageVersion Include="MongoDB.Bson" Version="2.28.0" />
    <PackageVersion Include="MongoDB.Driver.Core" Version="2.28.0" />
    <PackageVersion Include="MongoDB.Libmongocrypt" Version="1.11.0" />
    <PackageVersion Include="Pipelines.Sockets.Unofficial" Version="2.2.8" />
    <PackageVersion Include="SharpCompress" Version="0.30.1" />
    <PackageVersion Include="Snappier" Version="1.0.0" />
    <PackageVersion Include="StackExchange.Redis" Version="2.6.122" />
    <PackageVersion Include="System.Drawing.Common" Version="4.7.2" />
    <PackageVersion Include="System.Net.Http" Version="4.3.4" />
    <PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
    <PackageVersion Include="System.Security.Cryptography.Algorithms" Version="4.3.0" />
    <PackageVersion Include="System.Security.Cryptography.Encoding" Version="4.3.0" />
    <PackageVersion Include="System.Security.Cryptography.Primitives" Version="4.3.0" />
    <PackageVersion Include="System.Security.Cryptography.X509Certificates" Version="4.3.0" />
    <PackageVersion Include="System.Text.Encoding.CodePages" Version="5.0.0" />
    <PackageVersion Include="System.Windows.Extensions" Version="4.7.0" />
    <PackageVersion Include="ZstdSharp.Port" Version="0.7.3" />
    </ItemGroup>
  • <InstrumentationTarget
    Include="MongoDB.Driver.Core"
    Condition="!$(SkippedInstrumentations.Contains('MongoDB.Driver.Core'))"
    TargetNuGetPackageVersionRange="[2.28.0, 3.0.0)"
    InstrumentationNuGetPackageId="MongoDB.Driver.Core.Extensions.DiagnosticSources"
    InstrumentationNuGetPackageVersion="1.5.0" />
  • Library MongoDB.Driver.Core.Extensions.DiagnosticSources is under the following copyright:
    Copyright MongoDB.Driver.Core.Extensions.DiagnosticSources Authors under Apache
    License Version 2.0
    (<https://github.com/jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources/blob/master/LICENSE>).
  • Changelog, full doc review (search MongoDB in md files).

@ysolomchenko ysolomchenko marked this pull request as ready for review December 5, 2024 08:57
@ysolomchenko ysolomchenko requested a review from a team as a code owner December 5, 2024 08:57
collector.Expect(MongoDBInstrumentationScopeName);
}

collector.Expect(MongoDBInstrumentationScopeName, span => ValidateSpan(span));
Copy link
Contributor

Choose a reason for hiding this comment

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

For older versions of MongoDb, is all of the data the same before and after this change? If not, are we concerned about any attributes changing?

Copy link
Contributor Author

@ysolomchenko ysolomchenko Dec 9, 2024

Choose a reason for hiding this comment

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

Here is example for operation: find

Attributes for older version:

  • db.system: mongodb
  • db.connection_id: { ServerId : { ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }, LocalValue : 3, ServerValue : "12" }
  • db.name: test-db
  • db.mongodb.collection: employees
  • db.operation: find
  • network.transport: tcp
  • server.address: localhost
  • server.port: 27017
  • db.statement: { "find" : "employees", "filter" : { }, "$db" : "test-db", "lsid" : { "id" : CSUUID("a3dc2d19-04fe-43f9-9b88-24a1ddd6af2a") } }

Attributes for new bytecode instrumentation:

  • db.system: mongodb
  • db.collection.name: employees
  • db.namespace: test-db
  • db.operation.name: find
  • network.peer.address: ::1
  • server.address: localhost
  • server.port: 27017
  • network.peer.port: 27017

db.connection_id and db.statement are not part of the latest semantic conventions. The only difference is that we currently don't have network.transport for this case, but I will add it in the next version of the bytecode MongoDB instrumentation.

Some attribute names have been updated to align with the latest semantic conventions

  • db.name -> db.namespace
  • db.mongodb.collection -> db.collection.name
  • db.operation -> db.operation.name

Copy link
Contributor

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

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

LGTM

@Kielek Kielek merged commit 253f173 into open-telemetry:main Dec 10, 2024
38 checks passed
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.

Support MongoDB.Driver 3.0.0+

4 participants