-
Notifications
You must be signed in to change notification settings - Fork 27
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
observability: fix err access scope to correctly retrieve it on defer #43
observability: fix err access scope to correctly retrieve it on defer #43
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
driver.go
Outdated
var recordCallStatsFunc = recordCallStats(ctx, "go.sql.ping", c.options.InstanceName) | ||
defer func() { | ||
recordCallStatsFunc(err) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Thanks for the review @odeke-em, I've changed the commit message and applied your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you @otternq, LGTM!
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! |
Thanks for your info, @odeke-em :) |
Ensure the final
err
value is reported to recordCallStats' annonymous function instead ofnil
.Stats were always reporting
GoSQLStatus
asOK
even when queries failed. This change will allow the status to beERROR
and forGoSQLError
to be populated.