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

feat: adding instrumentation support for mongo-driver/v2 #6539

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

AlaricWhitney
Copy link

Adding the mongo-driver/v2 instrumentation.

This is a copy/paste of the v1 instrumentation, and was modified to adhere to the mongo-driver/v2 requirements.

Notable differences:

  • mtest was removed in v2. Replaced with drivertest in the unit testing.

This addresses PR #6419

@AlaricWhitney AlaricWhitney requested a review from a team as a code owner December 28, 2024 17:52
Copy link

linux-foundation-easycla bot commented Dec 28, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 83.73984% with 20 lines in your changes missing coverage. Please review.

Project coverage is 75.5%. Comparing base (2719357) to head (407eea4).

Files with missing lines Patch % Lines
...ngodb.org/mongo-driver/v2/mongo/otelmongo/mongo.go 80.2% 13 Missing and 5 partials ⚠️
...rg/mongo-driver/v2/mongo/otelmongo/test/version.go 60.0% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##            main   #6539    +/-   ##
======================================
  Coverage   75.5%   75.5%            
======================================
  Files        206     210     +4     
  Lines      19181   19304   +123     
======================================
+ Hits       14484   14593   +109     
- Misses      4259    4270    +11     
- Partials     438     441     +3     
Files with missing lines Coverage Δ
...godb.org/mongo-driver/v2/mongo/otelmongo/config.go 100.0% <100.0%> (ø)
...odb.org/mongo-driver/v2/mongo/otelmongo/version.go 100.0% <100.0%> (ø)
...rg/mongo-driver/v2/mongo/otelmongo/test/version.go 60.0% <60.0%> (ø)
...ngodb.org/mongo-driver/v2/mongo/otelmongo/mongo.go 80.2% <80.2%> (ø)

... and 1 file with indirect coverage changes

@dmathieu
Copy link
Member

cc @prestonvasquez for review?

Copy link
Contributor

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

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

@AlaricWhitney Thank you for putting this together. I wanted to let you know that I'll be reviewing this in stages, as my schedule allows.

Comment on lines 12 to 14
// This code was originally based on the following:
// - https://github.com/DataDog/dd-trace-go/tree/02f0449efa3cb382d499fadc873957385dcb2192/contrib/go.mongodb.org/mongo-driver/mongo
// - https://github.com/DataDog/dd-trace-go/tree/v1.23.3/ddtrace/ext
Copy link
Contributor

Choose a reason for hiding this comment

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

We should update this to note that the code was copied from a specific instance of the v1 instrumentation.

Copy link
Author

Choose a reason for hiding this comment

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

I've updated it to reference the commit version that it was based on.

// SemVersion is the semantic version to be supplied to tracer/meter creation.
//
// Deprecated: Use [Version] instead.
func SemVersion() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

@dmathieu Can this be excluded in v2?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, this is a new package. We shouldn't introduce methods that are already deprecated.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good. I'll remove it.

package otelmongo // import "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo"

// Version is the current release version of the mongo-driver instrumentation.
func Version() string {
Copy link
Contributor

@prestonvasquez prestonvasquez Jan 22, 2025

Choose a reason for hiding this comment

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

This should probably start at 0.1.0 per SEMVAR: semver.org#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase

@dmathieu Unless there is an open telemetry-specific requirement? This also mentions something about being updated by the pre_releash.sh script during release. Where does that script live? Does it need to include v2/mongo/otelmongo? Should this file be excluded altogether, i.e. does the script generate the entire file?

Copy link
Member

Choose a reason for hiding this comment

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

Versions are specified here: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/versions.yaml
We have commonly not started at 0.1.0 for new instrumentations, but at the version where we're currently at.

Copy link
Member

Choose a reason for hiding this comment

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

The release procedure is detailed here: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md
The pre_release script has been moved to a make command.

Copy link
Author

Choose a reason for hiding this comment

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

I can update the version to 0.60.0, and let the the pre_release script update it to the correct value if I'm understanding the process correctly.

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package test_test
Copy link
Contributor

@prestonvasquez prestonvasquez Jan 22, 2025

Choose a reason for hiding this comment

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

Suggest removing this file along with the test. If it gets autogenerated as part of pre-release automation, so bet it.

Copy link
Author

Choose a reason for hiding this comment

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

Great! I'll remove the test.

@jakenmbe
Copy link

can this pr merge? I need use it in my project

@dmathieu
Copy link
Member

Not until all review comments have been closed an it has been approved.

@AlaricWhitney
Copy link
Author

@prestonvasquez @dmathieu This should be ready for review.

Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

Could you add this new package to the CODEOWNERS file too?

This looks good. I don't have the required mongo knowledge to assert proper behavior though, so I'll let @prestonvasquez weigh on that.

@@ -13,6 +13,7 @@ The next release will require at least [Go 1.23].

### Added

- Add instrumentation support for `go.mongodb.org/mongo-driver/v2` in `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo`(#6539)
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this entry to be last in the section?


"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a new package, we should rely on the latest semantic conventions (1.30.0) right away, let's not make things harder by forcing a migration right away :)

/*
Package test validates the otelmongo V2 instrumentation with the default SDK.

This package is in a separate module from the instrumentation it tests to
Copy link
Member

Choose a reason for hiding this comment

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

Having this in a test subpackage shouldn't be required anymore, and we're in the process of removing that folder for every instrumentation.
Since this is a new one, could we avoid creating it altogether?

See #6763 as similar work for otelhttp.

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