Skip to content
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

Merged
merged 1 commit into from
May 18, 2020

Conversation

otternq
Copy link
Contributor

@otternq otternq commented May 17, 2020

Ensure the final err value is reported to recordCallStats' annonymous function instead of nil.

Stats were always reporting GoSQLStatus as OK even when queries failed. This change will allow the status to be ERROR and for GoSQLError to be populated.

Copy link
Member

@odeke-em odeke-em left a 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
Comment on lines 136 to 141
var recordCallStatsFunc = recordCallStats(ctx, "go.sql.ping", c.options.InstanceName)
defer func() {
recordCallStatsFunc(err)
}()
Copy link
Member

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.
@otternq otternq force-pushed the record-call-stats branch from ec0b126 to 9f4c7ea Compare May 17, 2020 23:57
@otternq
Copy link
Contributor Author

otternq commented May 18, 2020

Thanks for the review @odeke-em, I've changed the commit message and applied your suggestions.

@odeke-em odeke-em changed the title Change err scoping for recordCallStats call observability: fix err access scope to correctly retrieve it on defer May 18, 2020
Copy link
Member

@odeke-em odeke-em left a 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!

@odeke-em odeke-em merged commit b6f4ab8 into opencensus-integrations:master May 18, 2020
@odeke-em
Copy link
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!

@yancl
Copy link
Contributor

yancl commented May 18, 2020

Thanks for your info, @odeke-em :)

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.

3 participants