mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 19:59:37 -06:00
fix requestid
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/middleware"
|
||||
chimiddleware "github.com/go-chi/chi/middleware"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
)
|
||||
|
||||
@@ -18,7 +20,7 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler {
|
||||
|
||||
logger.Info().
|
||||
Str("proto", r.Proto).
|
||||
Str("request", r.Header.Get("X-Request-ID")).
|
||||
Str("request", ExtractRequestID(r.Context())).
|
||||
Str("remote-addr", r.RemoteAddr).
|
||||
Str("method", r.Method).
|
||||
Int("status", wrap.Status()).
|
||||
@@ -29,3 +31,14 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractRequestID extracts the request ID from the context. Since we now use the go-chi middleware to write the request
|
||||
// id, this is propagated using the context, therefore read it from there.
|
||||
func ExtractRequestID(ctx context.Context) string {
|
||||
var requestId string
|
||||
if v, ok := ctx.Value(chimiddleware.RequestIDKey).(string); ok {
|
||||
requestId = v
|
||||
}
|
||||
|
||||
return requestId
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis/proxy/pkg/middleware"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
@@ -229,7 +231,7 @@ func (p *MultiHostReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request
|
||||
span.SetAttributes(
|
||||
attribute.KeyValue{
|
||||
Key: "x-request-id",
|
||||
Value: attribute.StringValue(r.Header.Get("X-Request-ID")),
|
||||
Value: attribute.StringValue(middleware.ExtractRequestID(r.Context())),
|
||||
})
|
||||
|
||||
pkgtrace.Propagator.Inject(ctx, propagation.HeaderCarrier(r.Header))
|
||||
|
||||
Reference in New Issue
Block a user