github.com/epsagon/epsagon-go@v1.39.0/example/fiber_middleware/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/epsagon/epsagon-go/epsagon"
     8  	epsagonfiber "github.com/epsagon/epsagon-go/wrappers/fiber"
     9  	epsagonhttp "github.com/epsagon/epsagon-go/wrappers/net/http"
    10  	"github.com/gofiber/fiber/v2"
    11  )
    12  
    13  func main() {
    14  	config := epsagon.NewTracerConfig(
    15  		"fiber-example", "",
    16  	)
    17  	config.MetadataOnly = false
    18  	app := fiber.New()
    19  	// Match all routes
    20  	epsagonMiddleware := &epsagonfiber.FiberEpsagonMiddleware{
    21  		Config: config,
    22  	}
    23  	app.Use(epsagonMiddleware.HandlerFunc())
    24  	app.Post("/", func(c *fiber.Ctx) error {
    25  		// any call wrapped by Epsagon should receive the user context from the fiber context
    26  		client := http.Client{Transport: epsagonhttp.NewTracingTransport(c.UserContext())}
    27  		client.Get(fmt.Sprintf("https://epsagon.com/"))
    28  		return c.SendString("Hello, World 👋!")
    29  	})
    30  
    31  	app.Listen("0.0.0.0:3000")
    32  }