-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcus Cobden
committed
Aug 23, 2018
1 parent
80ff076
commit efd9930
Showing
2 changed files
with
28 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/opentracing-contrib/go-stdlib/nethttp" | ||
"github.com/opentracing/opentracing-go" | ||
) | ||
|
||
// Tracer is a middleware which traces incoming requests. | ||
type Tracer struct{} | ||
|
||
// Wrap implements Interface | ||
func (t Tracer) Wrap(next http.Handler) http.Handler { | ||
traceHandler := nethttp.Middleware(opentracing.GlobalTracer(), next) | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
var maybeTracer http.Handler | ||
// Don't try and trace websocket requests because nethttp.Middleware | ||
// doesn't support http.Hijack yet | ||
if IsWSHandshakeRequest(r) { | ||
maybeTracer = next | ||
} else { | ||
maybeTracer = traceHandler | ||
} | ||
maybeTracer.ServeHTTP(w, r) | ||
}) | ||
} |
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