Skip to content

observability: fix err access scope to correctly retrieve it on defer#43

Merged
odeke-em merged 1 commit intoopencensus-integrations:masterfrom
otternq:record-call-stats
May 18, 2020
Merged

observability: fix err access scope to correctly retrieve it on defer#43
odeke-em merged 1 commit intoopencensus-integrations:masterfrom
otternq:record-call-stats

Conversation

@otternq
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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