Skip to content

Commit

Permalink
fix(otelgorm): ignore gorm.ErrRecordNotFound and other errors from ot…
Browse files Browse the repository at this point in the history
…elsql/otel.go (#48)

Co-authored-by: jixiufeng <jixiufeng@luojilab.com>
  • Loading branch information
jixiuf and jixiufeng committed Apr 6, 2022
1 parent 01faa43 commit 1c5d1f7
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 1c5d1f7

Please sign in to comment.