Skip to content

feat(mongo): add SpanNameResolver for customizable span naming#7986

Merged
dmathieu merged 34 commits into
open-telemetry:mainfrom
Azer0s:feat/mongo-span-name-resolver
Nov 5, 2025
Merged

feat(mongo): add SpanNameResolver for customizable span naming#7986
dmathieu merged 34 commits into
open-telemetry:mainfrom
Azer0s:feat/mongo-span-name-resolver

Conversation

@Azer0s
Copy link
Copy Markdown
Contributor

@Azer0s Azer0s commented Oct 7, 2025

This PR adds a SpanNameResolver function to the monitor options in order to customize the span name to the users needs. This is especially relevant when dealing with multiple database instances, having to prefix spans, or generally needing to customize the span name.

@Azer0s Azer0s requested a review from a team as a code owner October 7, 2025 08:04
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Oct 7, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@Azer0s Azer0s force-pushed the feat/mongo-span-name-resolver branch 4 times, most recently from fc23cbf to 0dd6c01 Compare October 7, 2025 08:15
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/config.go Outdated
@Azer0s Azer0s force-pushed the feat/mongo-span-name-resolver branch from 0dd6c01 to e528e47 Compare October 7, 2025 08:16
@Azer0s Azer0s force-pushed the feat/mongo-span-name-resolver branch from e528e47 to 807588d Compare October 7, 2025 08:19
@dmathieu
Copy link
Copy Markdown
Member

dmathieu commented Oct 7, 2025

This will need a changelog entry.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.0%. Comparing base (6f1f946) to head (e0988ce).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7986   +/-   ##
=====================================
  Coverage   80.9%   81.0%           
=====================================
  Files        194     194           
  Lines      13073   13081    +8     
=====================================
+ Hits       10588   10596    +8     
  Misses      2107    2107           
  Partials     378     378           
Files with missing lines Coverage Δ
...godb.org/mongo-driver/v2/mongo/otelmongo/config.go 100.0% <100.0%> (ø)
...ngodb.org/mongo-driver/v2/mongo/otelmongo/mongo.go 90.7% <100.0%> (-0.2%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Azer0s
Copy link
Copy Markdown
Contributor Author

Azer0s commented Oct 7, 2025

This will need a changelog entry.

I added one

Comment thread CHANGELOG.md Outdated
Co-authored-by: Damien Mathieu <42@dmathieu.com>
@Azer0s Azer0s force-pushed the feat/mongo-span-name-resolver branch 2 times, most recently from 8c36929 to 8a811ee Compare October 7, 2025 13:29
@Azer0s Azer0s requested a review from dmathieu October 7, 2025 13:47
@Azer0s Azer0s force-pushed the feat/mongo-span-name-resolver branch from df66b8e to ac9e992 Compare October 7, 2025 15:05
@Azer0s
Copy link
Copy Markdown
Contributor Author

Azer0s commented Oct 7, 2025

@dmathieu could you please merge? :)

@dmathieu
Copy link
Copy Markdown
Member

dmathieu commented Oct 7, 2025

We require 2 approvals to merge.

@Azer0s
Copy link
Copy Markdown
Contributor Author

Azer0s commented Oct 8, 2025

Ping @prestonvasquez :)

Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/config.go Outdated
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/example_test.go Outdated
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/mongo.go Outdated
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/mongo_test.go Outdated
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/mongo_test.go Outdated
Azer0s and others added 5 commits November 4, 2025 22:25
Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
@Azer0s Azer0s requested a review from prestonvasquez November 5, 2025 08:59
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/mongo.go Outdated
Comment thread instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/example_test.go Outdated
@Azer0s
Copy link
Copy Markdown
Contributor Author

Azer0s commented Nov 5, 2025

@dmathieu the pipeline is currently failing (as far as I can see, nothing I broke) and I don't have the permission to merge or restart the pipeline. Could you do that please? :)

@Azer0s
Copy link
Copy Markdown
Contributor Author

Azer0s commented Nov 5, 2025

@dmathieu I think we're ready to merge! 🥳

@dmathieu
Copy link
Copy Markdown
Member

dmathieu commented Nov 5, 2025

We require 2 approvals to merge.

@Azer0s
Copy link
Copy Markdown
Contributor Author

Azer0s commented Nov 5, 2025

@prestonvasquez could you approve?

if collection, err := extractCollection(evt); err == nil && collection != "" {
spanName = collection + "."

collection, err := extractCollection(evt)
Copy link
Copy Markdown
Member

@flc1125 flc1125 Nov 5, 2025

Choose a reason for hiding this comment

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

In fact, when using the default SpanNameFormatter, we executed the extractCollection method twice. Is there a better way?

Secondly, it seems that users cannot access the collection information. Unless it implements a similar logic itself.

Copy link
Copy Markdown
Member

@dmathieu dmathieu Nov 5, 2025

Choose a reason for hiding this comment

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

See #7986 (comment)
That helper method should be made available by the mongo SDK, not by us.

Copy link
Copy Markdown
Member

@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.

LGTM, thanks @Azer0s 👍

@dmathieu dmathieu merged commit 01ec8a6 into open-telemetry:main Nov 5, 2025
36 of 45 checks passed
@MrAlias MrAlias mentioned this pull request Dec 8, 2025
@MrAlias MrAlias added this to the v1.39.0 milestone Dec 8, 2025
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.

6 participants