Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Request ID is empty with go-chi imported with major version suffix #71

Open
MarshalX opened this issue Feb 10, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@MarshalX
Copy link

MarshalX commented Feb 10, 2023

Describe the bug
chizap can't properly get the request id value from the context due to working with another major version of go-chi

To Reproduce
Steps to reproduce the behavior:

  1. Install go-chi with major version suffix like /v5 (github.com/go-chi/chi/v5)
  2. Build and run small example below
package main

import (
	"fmt"
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"go.uber.org/zap"
	"moul.io/chizap"
)

func main() {
	logger, _ := zap.NewProduction()

	r := chi.NewRouter()
	r.Use(middleware.RequestID)
	r.Use(chizap.New(logger, &chizap.Opts{
		WithReferer:   true,
		WithUserAgent: true,
	}))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Request ID: %s", middleware.GetReqID(r.Context()))
	})

	http.ListenAndServe(":3000", r)
}

Expected behavior
The request id should be presented in logs

Versions (please complete the following information, if relevant):

  • Software version: the latest
  • OS: macOS
  • Golang version 1.19.5

Additional context
I'm new in Go and idk how to contribute to your project, but I maybe know why it doesn't work. Each version of go-chi creates its own type (link to src). My project works on chi/v5 and writes the value to the context by own RequestIDKey. When chizap tries to read the value from the same context it attempts to read the value by RequestIDKey from chi version v1.5.4 (according to your go.mod). It doesn't exist and logs contain the empty request id.

@MarshalX MarshalX added the bug Something isn't working label Feb 10, 2023
@GrimAnEye
Copy link

+1

1 similar comment
@stanlyzoolo
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants