-
Notifications
You must be signed in to change notification settings - Fork 71
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
otelgorm replaces (but does not restore) context from statement #84
Comments
I don't see why this would not work. Do you want to give it a chance?
Is not |
I did try it out, and it did work. My concern is with plugin ordering (see below).
Not sure I fully understand the question. If you're asking if
In the example above, anything that |
Got you. The order of callbacks seems to be important to end spans in the correct order, but it probably should still work given that you pop the previous context from the current context like in Matryoshka dolls. Anyway, this is up to you. Just trying to help. |
The otelgorm package utilizes replacement the statement context when the
before
is called...opentelemetry-go-extra/otelgorm/otelgorm.go
Lines 97 to 101 in fcc6618
However, the statement context is never restored to its original in the corresponding
after()
call. Thus, after the execution of the query finishes, if thedb.Statement
object is reused, then the context of the statement will still be using the context corresponding to the now-ended span.The following is a failing test case:
In
do
, you can see two separate queries being run (withRows()
andCount()
). To me, the spans generated for these two queries should have the same parent. Instead, otelgorm is making the span of the second query a child of the first. If I added a third execution using thequery
value, that span would be a child of the second. Ideally, the plugin would restore the statement back to it's original so the statement could be reused.The only way I could think of doing this was to store the original context in the newly derived context, and then during the
after
callback pop it out. But that seemed error prone given that Gorm doesn't enforce the ordering of callbacks, so we'd have to hope another callback isn't trying to do the same thing but with a different ordering.The text was updated successfully, but these errors were encountered: