Skip to content

Do not report ErrSkip in metrics as error #386

Closed

Description

@ncthompson

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

  1. added
    enhancement
    on Nov 20, 2024
  2. XSAM commented on Nov 20, 2024

    @XSAM
    Owner

    Hi @ncthompson, this is a good catch! Thanks for raising this.

    Feel free to create a PR for this.

  3. added a commit that references this issue on Feb 10, 2025
    cc367ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions