diff --git a/hook/trace/hook.go b/hook/trace/hook.go index afc456d..9f4b7b0 100644 --- a/hook/trace/hook.go +++ b/hook/trace/hook.go @@ -84,6 +84,10 @@ func (h *Hook) After(ctx context.Context, evt *otsql.Event) { return } + if evt.Err != nil && errors.Is(evt.Err, driver.ErrSkip) && h.IgnoreErrSkip { + return + } + code, err := codes.Ok, evt.Err if err != nil { span.RecordError(err) diff --git a/hook/trace/option.go b/hook/trace/option.go index 40102e3..fc14206 100644 --- a/hook/trace/option.go +++ b/hook/trace/option.go @@ -63,6 +63,9 @@ type Options struct { // InstanceName identifies database. InstanceName string + + // IgnoreErrSkip, if set to true, the current span will be ignored when event get ErrSkip + IgnoreErrSkip bool } func newOptions(opts []Option) *Options { @@ -191,3 +194,10 @@ func WithSpanNameFormatter(formatter func(context.Context, string, string) strin o.SpanNameFormatter = formatter } } + +// WithIgnoreErrSkip if set to true, the current span will be ignored when event get ErrSkip +func WithIgnoreErrSkip(b bool) Option { + return func(o *Options) { + o.IgnoreErrSkip = b + } +}