Skip to content

Commit

Permalink
ignore gorm.ErrRecordNotFound and other errors from otelsql/otel.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiufeng committed Apr 6, 2022
1 parent 01faa43 commit 978ef25
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion otelgorm/otelgorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package otelgorm

import (
"database/sql"
"database/sql/driver"
"fmt"
"io"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -134,7 +136,14 @@ func (p *otelPlugin) after() gormHookFunc {
}

span.SetAttributes(attrs...)
if tx.Error != nil {
switch tx.Error {
case nil,
gorm.ErrRecordNotFound,
driver.ErrSkip,
io.EOF, // end of rows iterator
sql.ErrNoRows:
// ignore
default:
span.RecordError(tx.Error)
span.SetStatus(codes.Error, tx.Error.Error())
}
Expand Down

0 comments on commit 978ef25

Please sign in to comment.