Repository navigation
feat: introduce Commenter interface - #633
boekkooi-impossiblecloud wants to merge 1 commit into
Conversation
|
@boekkooi-impossiblecloud Hey, sorry for the late response. Could you provide a use case where users want to use a different comment style? |
|
Hey @XSAM No worries, I'm already thankful you took the time to review this PR 😄. In my case I needed a way to add specific comments to the end of all prepare queries which contains specific environment information (e.g. we have a shared set of repositories that are used by multiple workers and we needed to trace which worker called which prepared queries) but we also need to keep the tracing info for query calls. As the use case is a bit more custom I think the interface makes sense but if you have a better Idea I'm game 😄 Thanks again and have a great day |
ccc2a53 to
e25866e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #633 +/- ##
=======================================
+ Coverage 89.9% 90.1% +0.2%
=======================================
Files 16 16
Lines 608 622 +14
=======================================
+ Hits 547 561 +14
Misses 61 61 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This allows users of the library to use their own custom commenter. This can be useful when different comments are prefered for Queries and Prepared statements.
e25866e to
d3dfae1
Compare
|
Hey @boekkooi-impossiblecloud, if the goal is to add specific key/values to the comment, a custom propagator already does that today, so the new interface isn’t needed. For instance, type staticAttrs map[string]string
func (s staticAttrs) Inject(_ context.Context, c propagation.TextMapCarrier) {
for k, v := range s {
c.Set(k, v)
}
}
func (staticAttrs) Extract(ctx context.Context, _ propagation.TextMapCarrier) context.Context { return ctx }
func (s staticAttrs) Fields() []string { /* keys */ }
otelsql.Open("mysql", dsn,
otelsql.WithSQLCommenter(true),
otelsql.WithTextMapPropagator(propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
staticAttrs{"service.name": "shoppingcart"},
)),
)
// SELECT * FROM songs /*traceparent='…',service.name='shoppingcart'*/ |
|
Hey @XSAM Thanks for your response! I looked into using the existing commenter feature but it has some limitations. In the case of a prepared statements we have to ensure that the query send to the driver is always identical (aka has no traceID/parentTrace) to ensure we re-use the same prepared statement but for a normal Query/Exec we want to include the traceID/parentTrace in order to make your own life easier when debugging a trace. Sadly the scenario above it not possible with the current commenter which is why I propose this interface (or did I miss something?) |
Good day!
This PR introduces the Commenter interface which allows users to use their own custom SQL commenter.
This can be useful when different comments are preferred for SQL statements.
Thanks for having a look and please let me know what you think.
Have a great weekend.