Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow configuring a TextMapPropagator for SQLCommenter#540

Merged
XSAM merged 1 commit intoXSAM:mainfrom
simonbos:option-textmappropagator
Dec 15, 2025
Merged

Allow configuring a TextMapPropagator for SQLCommenter#540
XSAM merged 1 commit intoXSAM:mainfrom
simonbos:option-textmappropagator

Conversation

@simonbos
Copy link
Contributor

This allows users to not rely on the global TextMapPropagator. It might be enough to close #192 because then users are free to implement a custom propagator which is specific for the SQLCommenter use case without polluting the global TextMapPropagator.

@simonbos simonbos requested a review from XSAM as a code owner September 12, 2025 15:08
@codecov
Copy link

codecov bot commented Sep 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.7%. Comparing base (a22bd53) to head (318a6d3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #540     +/-   ##
=======================================
+ Coverage   86.5%   86.7%   +0.1%     
=======================================
  Files         16      16             
  Lines        746     752      +6     
=======================================
+ Hits         646     652      +6     
  Misses        74      74             
  Partials      26      26             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@simonbos simonbos force-pushed the option-textmappropagator branch from 3e43cf6 to 53a2d0f Compare September 12, 2025 15:25
@XSAM
Copy link
Owner

XSAM commented Sep 19, 2025

Hi @simonbos, thanks for creating this PR.

I am not sure it can address #192 as it seems to require dynamic key-value based on query. The propagator can only propagate static values without the support of special context tools provided to users.

But it is useful to add an API for user to replacement the propagator used for sql commenter (related PR open-telemetry/semantic-conventions#2495).

Could you add tests for cases to cover the new options with sql commenter enabled ? It probably can catch the nil pointer issue when this new option is not setup.

Please also update the changelog file.

@simonbos simonbos force-pushed the option-textmappropagator branch 2 times, most recently from f358e07 to 53a45c3 Compare October 26, 2025 16:52
@simonbos
Copy link
Contributor Author

Hi @XSAM , sorry for the late reply 🙏

The propagator can only propagate static values without the support of special context tools provided to users.

I am not an expert, but I think users of the package could create a custom propagator similar to the propagation.Baggage propagator and inject some custom context value at the application level? Although that is arguably a bit of work so I am all for having better out-of-the box support in otelsql itself 👍

Could you add tests for cases to cover the new options with sql commenter enabled ? It probably can catch the nil pointer issue when this new option is not setup.

  • I added an extra test case for the nil case to the commenter_test, any other test case you would like to see?
  • Can you clarify the nil pointer issue? The code defaults to the existing behavior of otel.GetTextMapPropagator() when it's not setup.

Copy link
Owner

@XSAM XSAM left a comment

Choose a reason for hiding this comment

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

I added an extra test case for the nil case to the commenter_test, any other test case you would like to see?

Could you add a test case for the new added option in TestOptions from option_test.go?

Regarding the nil issue, I could find the issue anymore. It could be my misread.

@simonbos simonbos force-pushed the option-textmappropagator branch from 53a45c3 to d3cc8a7 Compare November 23, 2025 13:40
@simonbos simonbos force-pushed the option-textmappropagator branch from d3cc8a7 to 318a6d3 Compare November 23, 2025 13:43
@simonbos
Copy link
Contributor Author

Sorry for the delay, I added the test case and added the experimental clarification.

Copy link
Owner

@XSAM XSAM left a comment

Choose a reason for hiding this comment

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

@simonbos thanks for your contribution!

@XSAM XSAM merged commit 756e691 into XSAM:main Dec 15, 2025
20 of 28 checks passed
@XSAM XSAM mentioned this pull request Dec 16, 2025
XSAM added a commit that referenced this pull request Dec 16, 2025
### ⚠️ Notice ⚠️

This release contains breaking changes:

- `RegisterDBStatsMetrics` now returns `(metric.Registration, error)`
(previously returned only `error`) so callers can `Unregister()` the
callback and avoid memory leaks.
- If you need to unregister: `reg, err := RegisterDBStatsMetrics(...)` +
`defer reg.Unregister()`.
- If you do not need to unregister: `_, err :=
RegisterDBStatsMetrics(...)`.
- `WithAttributes` now appends attributes when specified multiple times
(previously overwrote existing attributes).
- If you relied on overwriting: consolidate your attributes into a
single `WithAttributes(...)` call.

### Added

- `WithTextMapPropagator` allows customization of the OTel text map
propagator used by SQLCommenter. (#540)
This is an experimental feature and may be changed or removed in a later
release.

### Removed

- Drop support for [Go 1.23]. (#533)

### Changed

- Reduce allocations and improve performance when creating spans. (#549)
- Reduce allocations when recording metrics. (#550)
- `RegisterDBStatsMetrics` now returns a `metric.Registration` so
callbacks can be unregistered. (#580)
- `WithAttributes` now accumulates attributes across multiple calls
instead of overwriting. (#576)
- Upgrade OTel to `v1.39.0`. (#583)

[Go 1.23]: https://go.dev/doc/go1.23
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.

Ability to add more comments with the Commenter Feature

2 participants