@@ -49,8 +49,11 @@ type Config struct {
4949 // Skipper defines a function to skip middleware.
5050 Skipper middleware.Skipper
5151
52- // OnErrorFn is used to specify how errors are handled in the middleware.
53- OnError OnErrorFunc
52+ // OnNextError is used to specify how errors returned from the next middleware / handler are handled.
53+ OnNextError OnErrorFunc
54+
55+ // OnExtractionError is used to specify how errors returned from request extraction are handled.
56+ OnExtractionError OnErrorFunc
5457
5558 // TracerProvider allows overriding the default tracer provider.
5659 TracerProvider oteltrace.TracerProvider
@@ -119,11 +122,6 @@ func (config Config) ToMiddleware() (echo.MiddlewareFunc, error) {
119122 if config .Skipper == nil {
120123 config .Skipper = middleware .DefaultSkipper
121124 }
122- if config .OnError == nil {
123- config .OnError = func (c * echo.Context , err error ) {
124- c .Logger ().Error ("otel middleware error" , "error" , err )
125- }
126- }
127125
128126 var serverHost string
129127 var serverPort int
@@ -175,7 +173,9 @@ func (config Config) ToMiddleware() (echo.MiddlewareFunc, error) {
175173 ClientAddress : c .RealIP (),
176174 }
177175 if err := ev .ExtractRequest (request ); err != nil {
178- config .OnError (c , err )
176+ if config .OnExtractionError != nil {
177+ config .OnExtractionError (c , err )
178+ }
179179 }
180180 spanAttributes := ev .SpanStartAttributes ()
181181 if config .SpanStartAttributes != nil {
@@ -217,7 +217,9 @@ func (config Config) ToMiddleware() (echo.MiddlewareFunc, error) {
217217 if err != nil {
218218 span .SetAttributes (semconv .ErrorType (err ))
219219 span .SetStatus (codes .Error , err .Error ())
220- config .OnError (c , err )
220+ if config .OnNextError != nil {
221+ config .OnNextError (c , err )
222+ }
221223 }
222224
223225 resp , status := echo .ResolveResponseStatus (c .Response (), err )
0 commit comments