github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/w3ctrace/middleware.go (about)

     1  // (c) Copyright IBM Corp. 2021
     2  // (c) Copyright Instana Inc. 2020
     3  
     4  package w3ctrace
     5  
     6  import "net/http"
     7  
     8  // TracingHandlerFunc is an HTTP middleware that forwards the W3C context found in request
     9  // with the response
    10  func TracingHandlerFunc(handler http.HandlerFunc) http.HandlerFunc {
    11  	return func(w http.ResponseWriter, req *http.Request) {
    12  		if trCtx, err := Extract(req.Header); err == nil {
    13  			Inject(trCtx, w.Header())
    14  		}
    15  
    16  		handler(w, req)
    17  	}
    18  }