-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement transport level error handlers (#863)
* Add error handler implementation to the log package * Add error handler to http transport * Add error handler to amqp transport * Add error handler to awslambda transport * Add error handler to grpc transport * Add error handler to nats transport * Move error handler interfaces to transport package * Move log error handler to transport package * Remove error logger precedence * Improve documentation wording * Adjust transport package documentation * Remove ignore error * Update examples * Add context to the error handler signature
- Loading branch information
1 parent
22a2d43
commit 3c77e8c
Showing
15 changed files
with
161 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// Package transport contains bindings to concrete transports. | ||
// Package transport contains helpers applicable to all supported transports. | ||
package transport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package transport | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-kit/kit/log" | ||
) | ||
|
||
// ErrorHandler receives a transport error to be processed for diagnostic purposes. | ||
// Usually this means logging the error. | ||
type ErrorHandler interface { | ||
Handle(ctx context.Context, err error) | ||
} | ||
|
||
// LogErrorHandler is a transport error handler implementation which logs an error. | ||
type LogErrorHandler struct { | ||
logger log.Logger | ||
} | ||
|
||
func NewLogErrorHandler(logger log.Logger) *LogErrorHandler { | ||
return &LogErrorHandler{ | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (h *LogErrorHandler) Handle(ctx context.Context, err error) { | ||
h.logger.Log("err", err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package transport_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/transport" | ||
) | ||
|
||
func TestLogErrorHandler(t *testing.T) { | ||
var output []interface{} | ||
|
||
logger := log.Logger(log.LoggerFunc(func(keyvals ...interface{}) error { | ||
output = append(output, keyvals...) | ||
return nil | ||
})) | ||
|
||
errorHandler := transport.NewLogErrorHandler(logger) | ||
|
||
err := errors.New("error") | ||
|
||
errorHandler.Handle(context.Background(), err) | ||
|
||
if output[1] != err { | ||
t.Errorf("expected an error log event: have %v, want %v", output[1], err) | ||
} | ||
} |
Oops, something went wrong.