From 7917fa77b9e0c5f28d097c20a4f703056680bdf8 Mon Sep 17 00:00:00 2001 From: Andre Duffeck Date: Wed, 20 Dec 2023 09:32:57 +0100 Subject: [PATCH] Also log the traceid alongside the request id (#8023) * Also log the traceid alongside the request id * Add changelog --- changelog/unreleased/fix-empty-traceids.md | 1 + services/proxy/pkg/middleware/accesslog.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/changelog/unreleased/fix-empty-traceids.md b/changelog/unreleased/fix-empty-traceids.md index 6a7658db3a1..f758c15b682 100644 --- a/changelog/unreleased/fix-empty-traceids.md +++ b/changelog/unreleased/fix-empty-traceids.md @@ -2,4 +2,5 @@ Bugfix: Fix empty trace ids We changed the default tracing to produce non-empty traceids. +https://github.com/owncloud/ocis/pull/8023 https://github.com/owncloud/ocis/pull/8017 diff --git a/services/proxy/pkg/middleware/accesslog.go b/services/proxy/pkg/middleware/accesslog.go index 00afc71c436..e51faeb4bb0 100644 --- a/services/proxy/pkg/middleware/accesslog.go +++ b/services/proxy/pkg/middleware/accesslog.go @@ -6,6 +6,7 @@ import ( "github.com/go-chi/chi/v5/middleware" "github.com/owncloud/ocis/v2/ocis-pkg/log" + "go.opentelemetry.io/otel/trace" ) // AccessLog is a middleware to log http requests at info level logging. @@ -19,9 +20,11 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler { wrap := middleware.NewWrapResponseWriter(w, r.ProtoMajor) next.ServeHTTP(wrap, r) + spanContext := trace.SpanContextFromContext(r.Context()) logger.Info(). Str("proto", r.Proto). Str(log.RequestIDString, requestID). + Str("traceid", spanContext.TraceID().String()). Str("remote-addr", r.RemoteAddr). Str("method", r.Method). Int("status", wrap.Status()).