Repository navigation
Description
Problem Statement
We are making use of the the otelsql lib to track SQL metrics for our product. We use sql_latency_milliseconds_count and filter on app_name_db_sql_latency_milliseconds_count{status!="ok"} to track any errors that occur on our transaction to create an alert. The problem is that ErrSkip is now logged as the same priority of error as an actual database connection issue. The current context of the metric also does not indicate if it is an ErrSkip or something more serious.
Proposed Solution
Change out recordMetric (https://github.com/XSAM/otelsql/blob/main/utils.go#L55C6-L55C18) to something like:
switch err {
case nil:
attributes = append(attributes, queryStatusKey.String("ok"))
case driver.ErrSkip:
if !opts.DisableErrSkip {
attributes = append(attributes, queryStatusKey.String("error"))
} else {
attributes = append(attributes, queryStatusKey.String("ok"))
}
default:
attributes = append(attributes, queryStatusKey.String("error"))
}
So you can decide on logging ErrSkip as an error or not
Alternatives
Another solution is to add the ability to optionally append error specific attributes to the error metric. So something like the InstrumentAttributesGetter (https://github.com/XSAM/otelsql/blob/main/utils.go#L69) but InstrumentErrorAttributesGetter(err error) so the error itself can be filtered out later in Prometheus.
Prior Art
The spans section of this library already has an exception for the ErrSkip case.
https://github.com/XSAM/otelsql/blob/main/utils.go#L33
https://github.com/XSAM/otelsql/blob/main/utils.go#L69
Additional Context
I am willing do make the changes, I just want to confirm that this is something that makes sense for this library.
Activity
XSAM commentedon Nov 20, 2024
Hi @ncthompson, this is a good catch! Thanks for raising this.
Feel free to create a PR for this.
Add DisableSkipErrMetrics to disable ErrSkip metrics
Add DisableSkipErrMetrics to disable ErrSkip metrics
Add DisableSkipErrMetrics to disable ErrSkip metrics
Add DisableSkipErrMeasurement to disable ErrSkip metrics
Add DisableSkipErrMetrics to disable ErrSkip metrics (XSAM#389)