Skip to content

Commit

Permalink
fix: should use fiber.HeaderXRequestID (#23)
Browse files Browse the repository at this point in the history
* fix: should use fiber.HeaderXRequestID as default request id header key

* fix: typo

---------

Co-authored-by: neo-f <itsneo1990@gmail.com>
  • Loading branch information
Tian Pengfei and neo-f authored Jun 5, 2024
1 parent 463cdf1 commit ca9a1d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
go get github.com/samber/slog-fiber

# Fiber v3 (beta)
go get github.com/samber/slog-echo@fiber-v3
go get github.com/samber/slog-fiber@fiber-v3
```

**Compatibility**: go >= 1.21
Expand Down
9 changes: 4 additions & 5 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package slogfiber

import (
"context"
"log/slog"
"net/http"
"strings"
"sync"
"time"

"log/slog"

"github.com/gofiber/fiber/v3"
"github.com/google/uuid"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -38,7 +37,7 @@ var (
}

// Formatted with http.CanonicalHeaderKey
RequestIDHeaderKey = "X-Request-Id"
RequestIDHeaderKey = fiber.HeaderXRequestID
)

type Config struct {
Expand Down Expand Up @@ -126,7 +125,7 @@ func NewWithConfig(logger *slog.Logger, config Config) fiber.Handler {
requestID = uuid.New().String()
}
c.Context().SetUserValue("request-id", requestID)
c.Set("X-Request-ID", requestID)
c.Set(RequestIDHeaderKey, requestID)
}

err := c.Next()
Expand Down Expand Up @@ -309,7 +308,7 @@ func AddCustomAttributes(c fiber.Ctx, attr slog.Attr) {
}

func extractTraceSpanID(ctx context.Context, withTraceID bool, withSpanID bool) []slog.Attr {
if !(withTraceID || withSpanID) {
if !withTraceID && !withSpanID {
return []slog.Attr{}
}

Expand Down

0 comments on commit ca9a1d7

Please sign in to comment.