fiberprometheus icon indicating copy to clipboard operation
fiberprometheus copied to clipboard

Route.Path() is "/"

Open Meexe opened this issue 1 year ago • 2 comments

I use the v2 example from README

package main

import (
	"github.com/ansrivas/fiberprometheus/v2"
	"github.com/gofiber/fiber/v2"
)

func main() {
  app := fiber.New()

  // This here will appear as a label, one can also use
  // fiberprometheus.NewWith(servicename, namespace, subsystem )
  // or
  // NOTE: Following is not available in v1
  // labels := map[string]string{"custom_label1":"custom_value1", "custom_label2":"custom_value2"}
  // fiberprometheus.NewWithLabels(labels, namespace, subsystem )
  prometheus := fiberprometheus.New("my-service-name")
  prometheus.RegisterAt(app, "/metrics")
  app.Use(prometheus.Middleware)

  app.Get("/", func(c *fiber.Ctx) error {
    return c.SendString("Hello World")
  })

  app.Post("/some", func(c *fiber.Ctx) error {
    return c.SendString("Welcome!")
  })

  app.Listen(":3000")
}

Calling both localhost:3000 and localhost:3000/some creates metrics with "/" path, while I expect to get two different paths "/" and "/some". I added simple log to your middleware log.Printf("original url: %s, metrics path: %s", ctx.OriginalURL(), ctx.Route().Path), and this is the result:

2024/02/26 13:48:47 original url: /, metrics path: /
2024/02/26 13:48:52 original url: /some, metrics path: /

Meexe avatar Feb 26 '24 10:02 Meexe

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Apr 27 '24 02:04 github-actions[bot]

@ansrivas This was fixed by #197 The middleware needs a new release.

gaby avatar Apr 30 '24 03:04 gaby

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 30 '24 02:06 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Jul 11 '24 02:07 github-actions[bot]