feat: include tracing only for the recording spans
This commit is contained in:
+3
-3
@@ -1,6 +1,7 @@
|
|||||||
package sloggin
|
package sloggin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -168,7 +169,7 @@ func NewWithConfig(logger *slog.Logger, config Config) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// otel
|
// otel
|
||||||
baseAttributes = append(baseAttributes, extractTraceSpanID(c, config.WithTraceID, config.WithSpanID)...)
|
baseAttributes = append(baseAttributes, extractTraceSpanID(c.Request.Context(), config.WithTraceID, config.WithSpanID)...)
|
||||||
|
|
||||||
// request body
|
// request body
|
||||||
requestAttributes = append(requestAttributes, slog.Int("length", br.bytes))
|
requestAttributes = append(requestAttributes, slog.Int("length", br.bytes))
|
||||||
@@ -283,12 +284,11 @@ func AddCustomAttributes(c *gin.Context, attr slog.Attr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractTraceSpanID(c *gin.Context, withTraceID bool, withSpanID bool) []slog.Attr {
|
func extractTraceSpanID(ctx context.Context, withTraceID bool, withSpanID bool) []slog.Attr {
|
||||||
if !(withTraceID || withSpanID) {
|
if !(withTraceID || withSpanID) {
|
||||||
return []slog.Attr{}
|
return []slog.Attr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := c.Request.Context()
|
|
||||||
span := trace.SpanFromContext(ctx)
|
span := trace.SpanFromContext(ctx)
|
||||||
if !span.IsRecording() {
|
if !span.IsRecording() {
|
||||||
return []slog.Attr{}
|
return []slog.Attr{}
|
||||||
|
|||||||
Reference in New Issue
Block a user