diff --git a/otelfiber/README.md b/otelfiber/README.md index 200a05c5..5dd7e7d1 100644 --- a/otelfiber/README.md +++ b/otelfiber/README.md @@ -14,14 +14,14 @@ id: otelfiber Can be found on [OpenTelemetry Registry](https://opentelemetry.io/registry/instrumentation-go-fiber/). -**Note: Requires Go 1.19 and above** +**Note: Requires Go 1.21 and above** ## Install -This middleware supports Fiber v2. +This middleware supports Fiber v3. ``` -go get -u github.com/gofiber/contrib/otelfiber/v2 +go get -u github.com/gofiber/contrib/otelfiber/v3 ``` ## Signature @@ -36,15 +36,15 @@ You can configure the middleware using functional parameters | Function | Argument Type | Description | Default | | :------------------------ | :-------------------------------- | :--------------------------------------------------------------------------------- | :-------------------------------------------------------------------- | -| `WithNext` | `func(*fiber.Ctx) bool` | Define a function to skip this middleware when returned true .| nil | +| `WithNext` | `func(fiber.Ctx) bool` | Define a function to skip this middleware when returned true .| nil | | `WithTracerProvider` | `oteltrace.TracerProvider` | Specifies a tracer provider to use for creating a tracer. | nil - the global tracer provider is used | | `WithMeterProvider` | `otelmetric.MeterProvider` | Specifies a meter provider to use for reporting. | nil - the global meter provider is used | | `WithPort` | `int` | Specifies the value to use when setting the `net.host.port` attribute on metrics/spans. | Defaults to (`80` for `http`, `443` for `https`) | | `WithPropagators` | `propagation.TextMapPropagator` | Specifies propagators to use for extracting information from the HTTP requests. | If none are specified, global ones will be used | | `WithServerName` | `string` | Specifies the value to use when setting the `http.server_name` attribute on metrics/spans. | - | -| `WithSpanNameFormatter` | `func(*fiber.Ctx) string` | Takes a function that will be called on every request and the returned string will become the span Name. | Default formatter returns the route pathRaw | -| `WithCustomAttributes` | `func(*fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the span. | nil | -| `WithCustomMetricAttributes` | `func(*fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the metrics. | nil | +| `WithSpanNameFormatter` | `func(fiber.Ctx) string` | Takes a function that will be called on every request and the returned string will become the span Name. | Default formatter returns the route pathRaw | +| `WithCustomAttributes` | `func(fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the span. | nil | +| `WithCustomMetricAttributes` | `func(fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the metrics. | nil | | `WithCollectClientIP` | `bool` | Specifies whether to collect the client's IP address from the request. | true | ## Usage @@ -63,9 +63,9 @@ import ( "go.opentelemetry.io/otel/sdk/resource" - "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v3" - "github.com/gofiber/contrib/otelfiber" + "github.com/gofiber/contrib/otelfiber/v3" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" @@ -73,7 +73,7 @@ import ( //"go.opentelemetry.io/otel/exporters/jaeger" "go.opentelemetry.io/otel/propagation" sdktrace "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + semconv "go.opentelemetry.io/otel/semconv/v1.12.0" oteltrace "go.opentelemetry.io/otel/trace" ) @@ -91,11 +91,11 @@ func main() { app.Use(otelfiber.Middleware()) - app.Get("/error", func(ctx *fiber.Ctx) error { + app.Get("/error", func(ctx fiber.Ctx) error { return errors.New("abc") }) - app.Get("/users/:id", func(c *fiber.Ctx) error { + app.Get("/users/:id", func(c fiber.Ctx) error { id := c.Params("id") name := getUser(c.UserContext(), id) return c.JSON(fiber.Map{"id": id, name: name}) diff --git a/otelfiber/config.go b/otelfiber/config.go index ab588253..6a413620 100644 --- a/otelfiber/config.go +++ b/otelfiber/config.go @@ -1,7 +1,7 @@ package otelfiber import ( - "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v3" "go.opentelemetry.io/otel/attribute" otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/propagation" @@ -10,15 +10,15 @@ import ( // config is used to configure the Fiber middleware. type config struct { - Next func(*fiber.Ctx) bool + Next func(fiber.Ctx) bool TracerProvider oteltrace.TracerProvider MeterProvider otelmetric.MeterProvider Port *int Propagators propagation.TextMapPropagator ServerName *string - SpanNameFormatter func(*fiber.Ctx) string - CustomAttributes func(*fiber.Ctx) []attribute.KeyValue - CustomMetricAttributes func(*fiber.Ctx) []attribute.KeyValue + SpanNameFormatter func(fiber.Ctx) string + CustomAttributes func(fiber.Ctx) []attribute.KeyValue + CustomMetricAttributes func(fiber.Ctx) []attribute.KeyValue collectClientIP bool } @@ -35,7 +35,7 @@ func (o optionFunc) apply(c *config) { // WithNext takes a function that will be called on every // request, the middleware will be skipped if returning true -func WithNext(f func(ctx *fiber.Ctx) bool) Option { +func WithNext(f func(ctx fiber.Ctx) bool) Option { return optionFunc(func(cfg *config) { cfg.Next = f }) @@ -68,7 +68,7 @@ func WithMeterProvider(provider otelmetric.MeterProvider) Option { // WithSpanNameFormatter takes a function that will be called on every // request and the returned string will become the Span Name -func WithSpanNameFormatter(f func(ctx *fiber.Ctx) string) Option { +func WithSpanNameFormatter(f func(ctx fiber.Ctx) string) Option { return optionFunc(func(cfg *config) { cfg.SpanNameFormatter = f }) @@ -93,7 +93,7 @@ func WithPort(port int) Option { // WithCustomAttributes specifies a function that will be called on every // request and the returned attributes will be added to the span. -func WithCustomAttributes(f func(ctx *fiber.Ctx) []attribute.KeyValue) Option { +func WithCustomAttributes(f func(ctx fiber.Ctx) []attribute.KeyValue) Option { return optionFunc(func(cfg *config) { cfg.CustomAttributes = f }) @@ -101,7 +101,7 @@ func WithCustomAttributes(f func(ctx *fiber.Ctx) []attribute.KeyValue) Option { // WithCustomMetricAttributes specifies a function that will be called on every // request and the returned attributes will be added to the metrics. -func WithCustomMetricAttributes(f func(ctx *fiber.Ctx) []attribute.KeyValue) Option { +func WithCustomMetricAttributes(f func(ctx fiber.Ctx) []attribute.KeyValue) Option { return optionFunc(func(cfg *config) { cfg.CustomMetricAttributes = f }) diff --git a/otelfiber/doc.go b/otelfiber/doc.go index 4f97af7e..b8244c32 100644 --- a/otelfiber/doc.go +++ b/otelfiber/doc.go @@ -3,4 +3,4 @@ // // Currently, only the routing of a received message can be instrumented. To do // so, use the Middleware function. -package otelfiber // import" github.com/gofiber/contrib/otelfiber" +package otelfiber // import" github.com/gofiber/contrib/otelfiber/v3" diff --git a/otelfiber/example/go.mod b/otelfiber/example/go.mod index 051f394f..d85640c9 100644 --- a/otelfiber/example/go.mod +++ b/otelfiber/example/go.mod @@ -1,33 +1,32 @@ module github.com/gofiber/contrib/otelfiber/example -go 1.18 +go 1.21 -replace github.com/gofiber/contrib/otelfiber => ../ +replace github.com/gofiber/contrib/otelfiber/v3 => ../ require ( - github.com/gofiber/contrib/otelfiber v1.0.9 - github.com/gofiber/fiber/v2 v2.52.5 - go.opentelemetry.io/otel v1.24.0 - go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 - go.opentelemetry.io/otel/sdk v1.24.0 - go.opentelemetry.io/otel/trace v1.24.0 + github.com/gofiber/contrib/otelfiber/v3 v3.0.0 + github.com/gofiber/fiber/v3 v3.0.0-beta.3 + go.opentelemetry.io/otel v1.28.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 + go.opentelemetry.io/otel/sdk v1.28.0 + go.opentelemetry.io/otel/trace v1.28.0 ) require ( - github.com/andybalholm/brotli v1.0.5 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/google/uuid v1.5.0 // indirect - github.com/klauspost/compress v1.17.0 // indirect + github.com/gofiber/utils/v2 v2.0.0-beta.6 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/rivo/uniseg v0.4.4 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.51.0 // indirect + github.com/valyala/fasthttp v1.55.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - go.opentelemetry.io/contrib v1.20.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - golang.org/x/sys v0.17.0 // indirect + go.opentelemetry.io/contrib v1.28.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + golang.org/x/sys v0.21.0 // indirect ) diff --git a/otelfiber/example/go.sum b/otelfiber/example/go.sum index 0fa227f1..7dcdb55d 100644 --- a/otelfiber/example/go.sum +++ b/otelfiber/example/go.sum @@ -1,50 +1,52 @@ -github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo= -github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= +github.com/gofiber/fiber/v3 v3.0.0-beta.3 h1:7Q2I+HsIqnIEEDB+9oe7Gadpakh6ZLhXpTYz/L20vrg= +github.com/gofiber/fiber/v3 v3.0.0-beta.3/go.mod h1:kcMur0Dxqk91R7p4vxEpJfDWZ9u5IfvrtQc8Bvv/JmY= +github.com/gofiber/utils/v2 v2.0.0-beta.6 h1:ED62bOmpRXdgviPlfTmf0Q+AXzhaTUAFtdWjgx+XkYI= +github.com/gofiber/utils/v2 v2.0.0-beta.6/go.mod h1:3Kz8Px3jInKFvqxDzDeoSygwEOO+3uyubTmUa6PqY+0= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= -github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= -github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= -github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= +github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8= +github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -go.opentelemetry.io/contrib v1.20.0 h1:oXUiIQLlkbi9uZB/bt5B1WRLsrTKqb7bPpAQ+6htn2w= -go.opentelemetry.io/contrib v1.20.0/go.mod h1:gIzjwWFoGazJmtCaDgViqOSJPde2mCWzv60o0bWPcZs= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= -go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 h1:s0PHtIkN+3xrbDOpt2M8OTG92cWqUESvzh2MxiR5xY8= -go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0/go.mod h1:hZlFbDbRt++MMPCCfSJfmhkGIWnX1h3XjkfxZUjLrIA= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= -go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= -go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/contrib v1.28.0 h1:voxvZwQacGw3GVdlEoqUNnNq/yGuubRqgjNHZl61XPI= +go.opentelemetry.io/contrib v1.28.0/go.mod h1:Tmhw9grdWtmXy6DxZNpIAudzYJqLeEM2P6QTZQSRwU8= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 h1:EVSnY9JbEEW92bEkIYOVMw4q1WJxIAGoFTrtYOzWuRQ= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0/go.mod h1:Ea1N1QQryNXpCD0I1fdLibBAIpQuBkznMmkdKrapk1Y= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= +go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= +go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/otelfiber/example/server.go b/otelfiber/example/server.go index ab6eba80..55627938 100644 --- a/otelfiber/example/server.go +++ b/otelfiber/example/server.go @@ -7,9 +7,9 @@ import ( "go.opentelemetry.io/otel/sdk/resource" - "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v3" - "github.com/gofiber/contrib/otelfiber" + "github.com/gofiber/contrib/otelfiber/v3" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" @@ -17,7 +17,7 @@ import ( //"go.opentelemetry.io/otel/exporters/jaeger" "go.opentelemetry.io/otel/propagation" sdktrace "go.opentelemetry.io/otel/sdk/trace" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + semconv "go.opentelemetry.io/otel/semconv/v1.12.0" oteltrace "go.opentelemetry.io/otel/trace" ) @@ -34,17 +34,17 @@ func main() { app := fiber.New() // customise span name - //app.Use(otelfiber.Middleware(otelfiber.WithSpanNameFormatter(func(ctx *fiber.Ctx) string { + //app.Use(otelfiber.Middleware(otelfiber.WithSpanNameFormatter(func(ctx fiber.Ctx) string { // return fmt.Sprintf("%s - %s", ctx.Method(), ctx.Route().Path) //}))) app.Use(otelfiber.Middleware()) - app.Get("/error", func(ctx *fiber.Ctx) error { + app.Get("/error", func(ctx fiber.Ctx) error { return errors.New("abc") }) - app.Get("/users/:id", func(c *fiber.Ctx) error { + app.Get("/users/:id", func(c fiber.Ctx) error { id := c.Params("id") name := getUser(c.UserContext(), id) return c.JSON(fiber.Map{"id": id, name: name}) @@ -65,7 +65,7 @@ func initTracer() *sdktrace.TracerProvider { sdktrace.WithResource( resource.NewWithAttributes( semconv.SchemaURL, - semconv.ServiceNameKey.String("my-service"), + semconv.ServiceNameKey.String("my-service-fiber-v3"), )), ) otel.SetTracerProvider(tp) diff --git a/otelfiber/fiber.go b/otelfiber/fiber.go index 508528c0..3984aca9 100644 --- a/otelfiber/fiber.go +++ b/otelfiber/fiber.go @@ -5,8 +5,8 @@ import ( "net/http" "time" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/utils" + "github.com/gofiber/fiber/v3" + "github.com/gofiber/utils/v2" otelcontrib "go.opentelemetry.io/contrib" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -18,7 +18,7 @@ import ( const ( tracerKey = "gofiber-contrib-tracer-fiber" - instrumentationName = "github.com/gofiber/contrib/otelfiber" + instrumentationName = "github.com/gofiber/contrib/otelfiber/v3" MetricNameHttpServerDuration = "http.server.duration" MetricNameHttpServerRequestSize = "http.server.request.size" @@ -80,7 +80,7 @@ func Middleware(opts ...Option) fiber.Handler { cfg.SpanNameFormatter = defaultSpanNameFormatter } - return func(c *fiber.Ctx) error { + return func(c fiber.Ctx) error { // Don't execute middleware if Next returns true if cfg.Next != nil && cfg.Next(c) { return c.Next() @@ -176,6 +176,6 @@ func Middleware(opts ...Option) fiber.Handler { // defaultSpanNameFormatter is the default formatter for spans created with the fiber // integration. Returns the route pathRaw -func defaultSpanNameFormatter(ctx *fiber.Ctx) string { +func defaultSpanNameFormatter(ctx fiber.Ctx) string { return ctx.Route().Path } diff --git a/otelfiber/go.mod b/otelfiber/go.mod index ab748432..e31c37c7 100644 --- a/otelfiber/go.mod +++ b/otelfiber/go.mod @@ -1,34 +1,33 @@ -module github.com/gofiber/contrib/otelfiber/v2 +module github.com/gofiber/contrib/otelfiber/v3 -go 1.19 +go 1.21 require ( - github.com/gofiber/fiber/v2 v2.52.5 + github.com/gofiber/fiber/v3 v3.0.0-beta.3 + github.com/gofiber/utils/v2 v2.0.0-beta.6 github.com/stretchr/testify v1.9.0 - go.opentelemetry.io/contrib v1.20.0 - go.opentelemetry.io/contrib/propagators/b3 v1.20.0 - go.opentelemetry.io/otel v1.19.0 - go.opentelemetry.io/otel/metric v1.19.0 - go.opentelemetry.io/otel/sdk v1.19.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 - go.opentelemetry.io/otel/trace v1.19.0 + go.opentelemetry.io/contrib v1.28.0 + go.opentelemetry.io/contrib/propagators/b3 v1.28.0 + go.opentelemetry.io/otel v1.28.0 + go.opentelemetry.io/otel/metric v1.28.0 + go.opentelemetry.io/otel/sdk v1.28.0 + go.opentelemetry.io/otel/sdk/metric v1.28.0 + go.opentelemetry.io/otel/trace v1.28.0 ) require ( - github.com/andybalholm/brotli v1.0.5 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/google/uuid v1.5.0 // indirect - github.com/klauspost/compress v1.17.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rivo/uniseg v0.2.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.51.0 // indirect + github.com/valyala/fasthttp v1.55.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/sys v0.21.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/otelfiber/go.sum b/otelfiber/go.sum index 694cf74a..b10e22ab 100644 --- a/otelfiber/go.sum +++ b/otelfiber/go.sum @@ -1,56 +1,55 @@ -github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo= -github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= -github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/gofiber/fiber/v3 v3.0.0-beta.3 h1:7Q2I+HsIqnIEEDB+9oe7Gadpakh6ZLhXpTYz/L20vrg= +github.com/gofiber/fiber/v3 v3.0.0-beta.3/go.mod h1:kcMur0Dxqk91R7p4vxEpJfDWZ9u5IfvrtQc8Bvv/JmY= +github.com/gofiber/utils/v2 v2.0.0-beta.6 h1:ED62bOmpRXdgviPlfTmf0Q+AXzhaTUAFtdWjgx+XkYI= +github.com/gofiber/utils/v2 v2.0.0-beta.6/go.mod h1:3Kz8Px3jInKFvqxDzDeoSygwEOO+3uyubTmUa6PqY+0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= -github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= +github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8= +github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -go.opentelemetry.io/contrib v1.20.0 h1:oXUiIQLlkbi9uZB/bt5B1WRLsrTKqb7bPpAQ+6htn2w= -go.opentelemetry.io/contrib v1.20.0/go.mod h1:gIzjwWFoGazJmtCaDgViqOSJPde2mCWzv60o0bWPcZs= -go.opentelemetry.io/contrib/propagators/b3 v1.20.0 h1:Yty9Vs4F3D6/liF1o6FNt0PvN85h/BJJ6DQKJ3nrcM0= -go.opentelemetry.io/contrib/propagators/b3 v1.20.0/go.mod h1:On4VgbkqYL18kbJlWsa18+cMNe6rYpBnPi1ARI/BrsU= -go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= -go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= -go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= -go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= -go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= -go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= -go.opentelemetry.io/otel/sdk/metric v0.41.0 h1:c3sAt9/pQ5fSIUfl0gPtClV3HhE18DCVzByD33R/zsk= -go.opentelemetry.io/otel/sdk/metric v0.41.0/go.mod h1:PmOmSt+iOklKtIg5O4Vz9H/ttcRFSNTgii+E1KGyn1w= -go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= -go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= +go.opentelemetry.io/contrib v1.28.0 h1:voxvZwQacGw3GVdlEoqUNnNq/yGuubRqgjNHZl61XPI= +go.opentelemetry.io/contrib v1.28.0/go.mod h1:Tmhw9grdWtmXy6DxZNpIAudzYJqLeEM2P6QTZQSRwU8= +go.opentelemetry.io/contrib/propagators/b3 v1.28.0 h1:XR6CFQrQ/ttAYmTBX2loUEFGdk1h17pxYI8828dk/1Y= +go.opentelemetry.io/contrib/propagators/b3 v1.28.0/go.mod h1:DWRkzJONLquRz7OJPh2rRbZ7MugQj62rk7g6HRnEqh0= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= +go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= +go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/sdk/metric v1.28.0 h1:OkuaKgKrgAbYrrY0t92c+cC+2F6hsFNnCQArXCKlg08= +go.opentelemetry.io/otel/sdk/metric v1.28.0/go.mod h1:cWPjykihLAPvXKi4iZc1dpER3Jdq2Z0YLse3moQUCpg= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/otelfiber/otelfiber_test/fiber_test.go b/otelfiber/otelfiber_test/fiber_test.go index 32c87fb7..e9676e41 100644 --- a/otelfiber/otelfiber_test/fiber_test.go +++ b/otelfiber/otelfiber_test/fiber_test.go @@ -8,8 +8,8 @@ import ( "net/http/httptest" "testing" - "github.com/gofiber/contrib/otelfiber/v2" - "github.com/gofiber/fiber/v2" + "github.com/gofiber/contrib/otelfiber/v3" + "github.com/gofiber/fiber/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" otelcontrib "go.opentelemetry.io/contrib" @@ -24,11 +24,11 @@ import ( "go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/sdk/trace/tracetest" - semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + semconv "go.opentelemetry.io/otel/semconv/v1.12.0" oteltrace "go.opentelemetry.io/otel/trace" ) -const instrumentationName = "github.com/gofiber/contrib/otelfiber" +const instrumentationName = "github.com/gofiber/contrib/otelfiber/v3" func TestChildSpanFromGlobalTracer(t *testing.T) { sr := tracetest.NewSpanRecorder() @@ -37,7 +37,7 @@ func TestChildSpanFromGlobalTracer(t *testing.T) { app := fiber.New() app.Use(otelfiber.Middleware()) - app.Get("/user/:id", func(ctx *fiber.Ctx) error { + app.Get("/user/:id", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -54,7 +54,7 @@ func TestChildSpanFromCustomTracer(t *testing.T) { app := fiber.New() app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) - app.Get("/user/:id", func(ctx *fiber.Ctx) error { + app.Get("/user/:id", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -70,11 +70,11 @@ func TestSkipWithNext(t *testing.T) { otel.SetTracerProvider(provider) app := fiber.New() - app.Use(otelfiber.Middleware(otelfiber.WithNext(func(c *fiber.Ctx) bool { + app.Use(otelfiber.Middleware(otelfiber.WithNext(func(c fiber.Ctx) bool { return c.Path() == "/health" }))) - app.Get("/health", func(ctx *fiber.Ctx) error { + app.Get("/health", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -97,12 +97,12 @@ func TestTrace200(t *testing.T) { otelfiber.WithServerName(serverName), ), ) - app.Get("/user/:id", func(ctx *fiber.Ctx) error { + app.Get("/user/:id", func(ctx fiber.Ctx) error { id := ctx.Params("id") return ctx.SendString(id) }) - resp, _ := app.Test(httptest.NewRequest("GET", "/user/123", nil), 3000) + resp, _ := app.Test(httptest.NewRequest("GET", "/user/123", nil), 300000) // do and verify the request require.Equal(t, http.StatusOK, resp.StatusCode) @@ -132,7 +132,7 @@ func TestError(t *testing.T) { app := fiber.New() app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) // configure a handler that returns an error and 5xx status code - app.Get("/server_err", func(ctx *fiber.Ctx) error { + app.Get("/server_err", func(ctx fiber.Ctx) error { return errors.New("oh no") }) resp, _ := app.Test(httptest.NewRequest("GET", "/server_err", nil)) @@ -154,13 +154,13 @@ func TestError(t *testing.T) { func TestErrorOnlyHandledOnce(t *testing.T) { timesHandlingError := 0 app := fiber.New(fiber.Config{ - ErrorHandler: func(ctx *fiber.Ctx, err error) error { + ErrorHandler: func(ctx fiber.Ctx, err error) error { timesHandlingError++ return fiber.NewError(http.StatusInternalServerError, err.Error()) }, }) app.Use(otelfiber.Middleware()) - app.Get("/", func(ctx *fiber.Ctx) error { + app.Get("/", func(ctx fiber.Ctx) error { return errors.New("mock error") }) _, _ = app.Test(httptest.NewRequest(http.MethodGet, "/", nil)) @@ -172,7 +172,7 @@ func TestGetSpanNotInstrumented(t *testing.T) { var gotSpan oteltrace.Span app := fiber.New() - app.Get("/ping", func(ctx *fiber.Ctx) error { + app.Get("/ping", func(ctx fiber.Ctx) error { // Assert we don't have a span on the context. gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendString("ok") @@ -198,7 +198,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { app := fiber.New() app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) - app.Get("/user/:id", func(ctx *fiber.Ctx) error { + app.Get("/user/:id", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -227,7 +227,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) { app := fiber.New() app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider), otelfiber.WithPropagators(b3))) - app.Get("/user/:id", func(ctx *fiber.Ctx) error { + app.Get("/user/:id", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -292,7 +292,7 @@ func TestMetric(t *testing.T) { otelfiber.WithServerName(serverName), ), ) - app.Get(route, func(ctx *fiber.Ctx) error { + app.Get(route, func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusOK) }) @@ -413,7 +413,7 @@ func TestCustomAttributes(t *testing.T) { app.Use( otelfiber.Middleware( otelfiber.WithTracerProvider(provider), - otelfiber.WithCustomAttributes(func(ctx *fiber.Ctx) []attribute.KeyValue { + otelfiber.WithCustomAttributes(func(ctx fiber.Ctx) []attribute.KeyValue { return []attribute.KeyValue{ attribute.Key("http.query_params").String(ctx.Request().URI().QueryArgs().String()), } @@ -421,12 +421,12 @@ func TestCustomAttributes(t *testing.T) { ), ) - app.Get("/user/:id", func(ctx *fiber.Ctx) error { + app.Get("/user/:id", func(ctx fiber.Ctx) error { id := ctx.Params("id") return ctx.SendString(id) }) - resp, _ := app.Test(httptest.NewRequest("GET", "/user/123?foo=bar", nil), 3000) + resp, _ := app.Test(httptest.NewRequest("GET", "/user/123?foo=bar", nil), 300000) // do and verify the request require.Equal(t, http.StatusOK, resp.StatusCode) @@ -461,7 +461,7 @@ func TestCustomMetricAttributes(t *testing.T) { otelfiber.WithMeterProvider(provider), otelfiber.WithPort(port), otelfiber.WithServerName(serverName), - otelfiber.WithCustomMetricAttributes(func(ctx *fiber.Ctx) []attribute.KeyValue { + otelfiber.WithCustomMetricAttributes(func(ctx fiber.Ctx) []attribute.KeyValue { return []attribute.KeyValue{ attribute.Key("http.query_params").String(ctx.Request().URI().QueryArgs().String()), } @@ -469,7 +469,7 @@ func TestCustomMetricAttributes(t *testing.T) { ), ) - app.Get(route, func(ctx *fiber.Ctx) error { + app.Get(route, func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusOK) }) @@ -510,11 +510,11 @@ func TestOutboundTracingPropagation(t *testing.T) { otelfiber.WithTracerProvider(provider), otelfiber.WithPropagators(b3prop.New(b3prop.WithInjectEncoding(b3prop.B3MultipleHeader))), )) - app.Get("/foo", func(ctx *fiber.Ctx) error { + app.Get("/foo", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) - resp, _ := app.Test(httptest.NewRequest("GET", "/foo", nil), 3000) + resp, _ := app.Test(httptest.NewRequest("GET", "/foo", nil), 300000) assert.Equal(t, "1", resp.Header.Get("X-B3-Sampled")) assert.NotEmpty(t, resp.Header.Get("X-B3-SpanId")) @@ -534,7 +534,7 @@ func TestOutboundTracingPropagationWithInboundContext(t *testing.T) { otelfiber.WithTracerProvider(provider), otelfiber.WithPropagators(b3prop.New(b3prop.WithInjectEncoding(b3prop.B3MultipleHeader))), )) - app.Get("/foo", func(ctx *fiber.Ctx) error { + app.Get("/foo", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -544,7 +544,7 @@ func TestOutboundTracingPropagationWithInboundContext(t *testing.T) { req.Header.Set("X-B3-TraceId", traceId) req.Header.Set("X-B3-Sampled", "1") - resp, _ := app.Test(req, 3000) + resp, _ := app.Test(req, 300000) assert.NotEmpty(t, resp.Header.Get("X-B3-SpanId")) assert.Equal(t, traceId, resp.Header.Get("X-B3-TraceId")) @@ -568,7 +568,7 @@ func TestCollectClientIP(t *testing.T) { otelfiber.WithTracerProvider(provider), otelfiber.WithCollectClientIP(enabled), )) - app.Get("/foo", func(ctx *fiber.Ctx) error { + app.Get("/foo", func(ctx fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) diff --git a/otelfiber/semconv.go b/otelfiber/semconv.go index 2cf89544..411b8f97 100644 --- a/otelfiber/semconv.go +++ b/otelfiber/semconv.go @@ -4,17 +4,17 @@ import ( "encoding/base64" "strings" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/utils" + "github.com/gofiber/fiber/v3" + "github.com/gofiber/utils/v2" "go.opentelemetry.io/otel/attribute" semconv "go.opentelemetry.io/otel/semconv/v1.12.0" ) -func httpServerMetricAttributesFromRequest(c *fiber.Ctx, cfg config) []attribute.KeyValue { +func httpServerMetricAttributesFromRequest(c fiber.Ctx, cfg config) []attribute.KeyValue { attrs := []attribute.KeyValue{ httpFlavorAttribute(c), semconv.HTTPMethodKey.String(utils.CopyString(c.Method())), - semconv.HTTPSchemeKey.String(utils.CopyString(c.Protocol())), + semconv.HTTPSchemeKey.String(utils.CopyString(c.Scheme())), semconv.NetHostNameKey.String(utils.CopyString(c.Hostname())), } @@ -33,7 +33,7 @@ func httpServerMetricAttributesFromRequest(c *fiber.Ctx, cfg config) []attribute return attrs } -func httpServerTraceAttributesFromRequest(c *fiber.Ctx, cfg config) []attribute.KeyValue { +func httpServerTraceAttributesFromRequest(c fiber.Ctx, cfg config) []attribute.KeyValue { attrs := []attribute.KeyValue{ httpFlavorAttribute(c), // utils.CopyString: we need to copy the string as fasthttp strings are by default @@ -41,7 +41,7 @@ func httpServerTraceAttributesFromRequest(c *fiber.Ctx, cfg config) []attribute. // the handler returns. semconv.HTTPMethodKey.String(utils.CopyString(c.Method())), semconv.HTTPRequestContentLengthKey.Int(c.Request().Header.ContentLength()), - semconv.HTTPSchemeKey.String(utils.CopyString(c.Protocol())), + semconv.HTTPSchemeKey.String(utils.CopyString(c.Scheme())), semconv.HTTPTargetKey.String(string(utils.CopyBytes(c.Request().RequestURI()))), semconv.HTTPURLKey.String(utils.CopyString(c.OriginalURL())), semconv.HTTPUserAgentKey.String(string(utils.CopyBytes(c.Request().Header.UserAgent()))), @@ -74,7 +74,7 @@ func httpServerTraceAttributesFromRequest(c *fiber.Ctx, cfg config) []attribute. return attrs } -func httpFlavorAttribute(c *fiber.Ctx) attribute.KeyValue { +func httpFlavorAttribute(c fiber.Ctx) attribute.KeyValue { if c.Request().Header.IsHTTP11() { return semconv.HTTPFlavorHTTP11 }