observability: fix err access scope to correctly retrieve it on defer#43
Merged
odeke-em merged 1 commit intoopencensus-integrations:masterfrom May 18, 2020
Merged
Conversation
odeke-em
requested changes
May 17, 2020
Member
odeke-em
left a comment
There was a problem hiding this comment.
Thank you for catching this bug @otternq and for submitting this PR.
I have posted up some suggestions, please take a look. Could you also update
the commit subject and message to
observability: fix err access scope to correctly retrieve it on defer
Fixes a bug in which we mistakenly used the earliest value of err
which was always nil, when measuring latency. The fix here is
to invoke the latency measuring closure inside a defer to correctly
capture the latest value of the named err value.
Comment on lines
+136
to
+141
| var recordCallStatsFunc = recordCallStats(ctx, "go.sql.ping", c.options.InstanceName) | ||
| defer func() { | ||
| recordCallStatsFunc(err) | ||
| }() |
Member
There was a problem hiding this comment.
onDeferWithErr := recordCallStats(ctx, "go.sql.ping", c.options.InstanceName)
defer func() {
// Invoking this function in a defer so that we can capture
// the value of err as set on function exit.
onDeferWithErr(err)
}()Fixes a bug in which we mistakenly used the earliest value of err which was always nil, when measuring latency. The fix here is to invoke the latency measuring closure inside a defer to correctly capture the latest value of the named err value.
ec0b126 to
9f4c7ea
Compare
Contributor
Author
|
Thanks for the review @odeke-em, I've changed the commit message and applied your suggestions. |
Member
|
And thank you again @otternq, I have cut release https://github.com/opencensus-integrations/ocsql/releases/tag/v0.1.6 @a8m @yancl @lwc y'all might wanna upgrade to the latest release, thanks! |
Contributor
|
Thanks for your info, @odeke-em :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ensure the final
errvalue is reported to recordCallStats' annonymous function instead ofnil.Stats were always reporting
GoSQLStatusasOKeven when queries failed. This change will allow the status to beERRORand forGoSQLErrorto be populated.