Skip to content

Commit

Permalink
fix(echo): return nil from middleware to handle error only once (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleynguyen committed Oct 5, 2020
1 parent e3d25a6 commit 8244cc7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed

- The `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho.Middleware` no longer sends duplicate errors to the global `ErrorHandler`. (#377, #364)
- The import comment in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is now correctly quoted. (#379)

## [0.12.0] - 2020-09-25
Expand Down Expand Up @@ -124,7 +125,6 @@ This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-tel
- Update dependabot configuration to correctly check all included packages. (#131)
- Update `RELEASING.md` with correct `tag.sh` command. (#130)


## [0.8.0] - 2020-07-10

This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.8.0) dependency to v0.8.0, includes minor fixes, and new instrumentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Middleware(service string, opts ...Option) echo.MiddlewareFunc {
span.SetAttributes(attrs...)
span.SetStatus(spanStatus, spanMessage)

return err
return nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,23 @@ func TestError(t *testing.T) {
assert.Equal(t, codes.Internal, span.Status)
}

func TestErrorOnlyHandledOnce(t *testing.T) {
router := echo.New()
timesHandlingError := 0
router.HTTPErrorHandler = func(e error, c echo.Context) {
timesHandlingError++
}
router.Use(Middleware("test-service"))
router.GET("/", func(c echo.Context) error {
return errors.New("Mock Error")
})
r := httptest.NewRequest(http.MethodGet, "/", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, r)

assert.Equal(t, 1, timesHandlingError)
}

func TestGetSpanNotInstrumented(t *testing.T) {
router := echo.New()
router.GET("/ping", func(c echo.Context) error {
Expand Down

0 comments on commit 8244cc7

Please sign in to comment.