Skip to content

Commit c8bb0de

Browse files
committed
1 parent 7e567e0 commit c8bb0de

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ Attributes will be injected in log payload.
107107
Other global parameters:
108108

109109
```go
110-
sloghttp.TraceIDKey = "trace-id"
111-
sloghttp.SpanIDKey = "span-id"
110+
sloghttp.TraceIDKey = "trace_id"
111+
sloghttp.SpanIDKey = "span_id"
112112
sloghttp.RequestBodyMaxSize = 64 * 1024 // 64KB
113113
sloghttp.ResponseBodyMaxSize = 64 * 1024 // 64KB
114114
sloghttp.HiddenRequestHeaders = map[string]struct{}{ ... }

middleware.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var customAttributesCtxKey = customAttributesCtxKeyType{}
2020
var requestIDCtxKey = requestIDCtxKeyType{}
2121

2222
var (
23-
TraceIDKey = "trace-id"
24-
SpanIDKey = "span-id"
23+
TraceIDKey = "trace_id"
24+
SpanIDKey = "span_id"
2525
RequestIDKey = "id"
2626

2727
RequestBodyMaxSize = 64 * 1024 // 64KB
@@ -252,12 +252,12 @@ func NewWithConfig(logger *slog.Logger, config Config) func(http.Handler) http.H
252252
}
253253
}
254254

255-
// GetRequestID returns the request identifier
255+
// GetRequestID returns the request identifier.
256256
func GetRequestID(r *http.Request) string {
257257
return GetRequestIDFromContext(r.Context())
258258
}
259259

260-
// GetRequestIDFromContext returns the request identifier from the context
260+
// GetRequestIDFromContext returns the request identifier from the context.
261261
func GetRequestIDFromContext(ctx context.Context) string {
262262
requestID := ctx.Value(requestIDCtxKey)
263263
if id, ok := requestID.(string); ok {
@@ -267,6 +267,7 @@ func GetRequestIDFromContext(ctx context.Context) string {
267267
return ""
268268
}
269269

270+
// AddCustomAttributes adds custom attributes to the request context.
270271
func AddCustomAttributes(r *http.Request, attr slog.Attr) {
271272
v := r.Context().Value(customAttributesCtxKey)
272273
if v == nil {

0 commit comments

Comments
 (0)