Skip to content

Conversation

Azer0s
Copy link

@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
Copy link

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

dmathieu commented Oct 7, 2025

This will need a changelog entry.

Copy link

codecov bot commented Oct 7, 2025

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #7986     +/-   ##
=======================================
+ Coverage   78.5%   78.6%   +0.1%     
=======================================
  Files        184     184             
  Lines      14673   14683     +10     
=======================================
+ Hits       11520   11543     +23     
+ Misses      2802    2789     -13     
  Partials     351     351             
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 88.4% <100.0%> (-0.2%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Azer0s
Copy link
Author

Azer0s commented Oct 7, 2025

This will need a changelog entry.

I added one

Co-authored-by: Damien Mathieu <[email protected]>
@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
Author

Azer0s commented Oct 7, 2025

@dmathieu could you please merge? :)

@dmathieu
Copy link
Member

dmathieu commented Oct 7, 2025

We require 2 approvals to merge.

@Azer0s
Copy link
Author

Azer0s commented Oct 8, 2025

Ping @prestonvasquez :)


// SpanNameFormatterFunc is a function that resolves the span name given the
// collection and command name.
type SpanNameFormatterFunc func(collection, command string) string
Copy link
Member

Choose a reason for hiding this comment

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

I cannot be certain, currently for reference only:

Why can't this part func(collection, command string) string be func(collection string, evt *event.CommandStartedEvent) string

cc @prestonvasquez

Copy link
Author

Choose a reason for hiding this comment

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

Another option would be to pass a formatter data struct like so:

type FormatterData struct {
    *event.CommandStartedEvent
    CollectionName string
}

But tbh I don't really see what added benefits that would bring, but I am also not opposed to implementing it ☺️

Copy link
Member

Choose a reason for hiding this comment

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

I don't know enough about mongo to say what we need.
But with HTTP instrumentations, we pass the *http.Request object, so folks can use anything within that struct to build the span name.

Copy link
Author

Choose a reason for hiding this comment

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

@dmathieu should I change the formatter function to accept an event alongside the collection name?

Copy link
Author

Choose a reason for hiding this comment

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

I still feel like a formatter data struct is more extendable

Copy link
Member

Choose a reason for hiding this comment

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

@prestonvasquez is currently on leave. I have emailed his coworkers. Let's wait a bit for their input.

Copy link
Author

Choose a reason for hiding this comment

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

@dmathieu Hi! Are there any updates on this?

@donkahlero
Copy link

I'd also would like to ask if there are any updates regarding this, as I am in need for this change, as well. Thx!

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