Skip to content

Commit 812b3ff

Browse files
committed
feat: include tracing only for the recording spans
1 parent 0a948b0 commit 812b3ff

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

middleware.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sloggin
22

33
import (
4+
"context"
45
"log/slog"
56
"net/http"
67
"strings"
@@ -168,7 +169,7 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc {
168169
}
169170

170171
// otel
171-
baseAttributes = append(baseAttributes, extractTraceSpanID(c, config.WithTraceID, config.WithSpanID)...)
172+
baseAttributes = append(baseAttributes, extractTraceSpanID(c.Request.Context(), config.WithTraceID, config.WithSpanID)...)
172173

173174
// request body
174175
requestAttributes = append(requestAttributes, slog.Int("length", br.bytes))
@@ -283,12 +284,11 @@ func AddCustomAttributes(c *gin.Context, attr slog.Attr) {
283284
}
284285
}
285286

286-
func extractTraceSpanID(c *gin.Context, withTraceID bool, withSpanID bool) []slog.Attr {
287+
func extractTraceSpanID(ctx context.Context, withTraceID bool, withSpanID bool) []slog.Attr {
287288
if !(withTraceID || withSpanID) {
288289
return []slog.Attr{}
289290
}
290291

291-
ctx := c.Request.Context()
292292
span := trace.SpanFromContext(ctx)
293293
if !span.IsRecording() {
294294
return []slog.Attr{}

0 commit comments

Comments
 (0)