-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Implement transport level error handlers #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
913a66a
Add error handler implementation to the log package
sagikazarmark 1363386
Add error handler to http transport
sagikazarmark 9b720a5
Add error handler to amqp transport
sagikazarmark d40f4a1
Add error handler to awslambda transport
sagikazarmark d04ede9
Add error handler to grpc transport
sagikazarmark fbb4816
Add error handler to nats transport
sagikazarmark 295ec34
Move error handler interfaces to transport package
sagikazarmark 9085cc5
Move log error handler to transport package
sagikazarmark 66de09e
Remove error logger precedence
sagikazarmark de8921e
Improve documentation wording
sagikazarmark 2961581
Adjust transport package documentation
sagikazarmark 13f01e7
Remove ignore error
sagikazarmark 38bc660
Update examples
sagikazarmark 087defb
Add context to the error handler signature
sagikazarmark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.