From 13833aeb61bd6a87d497d69407b837aa728f9547 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Tue, 20 Jun 2023 07:20:46 +0100 Subject: [PATCH 01/17] Use tracetest --- otelfiber/fiber.go | 20 ++++----- otelfiber/semconv.go | 4 +- otelfiber/{ => test}/fiber_test.go | 72 ++++++++++++++++-------------- 3 files changed, 50 insertions(+), 46 deletions(-) rename otelfiber/{ => test}/fiber_test.go (86%) diff --git a/otelfiber/fiber.go b/otelfiber/fiber.go index 76bd730d..6f486e2e 100644 --- a/otelfiber/fiber.go +++ b/otelfiber/fiber.go @@ -20,10 +20,10 @@ const ( tracerKey = "gofiber-contrib-tracer-fiber" instrumentationName = "github.com/gofiber/contrib/otelfiber" - metricNameHttpServerDuration = "http.server.duration" - metricNameHttpServerRequestSize = "http.server.request.size" - metricNameHttpServerResponseSize = "http.server.response.size" - metricNameHttpServerActiveRequests = "http.server.active_requests" + MetricNameHttpServerDuration = "http.server.duration" + MetricNameHttpServerRequestSize = "http.server.request.size" + MetricNameHttpServerResponseSize = "http.server.response.size" + MetricNameHttpServerActiveRequests = "http.server.active_requests" // Unit constants for deprecated metric units UnitDimensionless = "1" @@ -43,7 +43,7 @@ func Middleware(opts ...Option) fiber.Handler { } tracer := cfg.TracerProvider.Tracer( instrumentationName, - oteltrace.WithInstrumentationVersion(otelcontrib.SemVersion()), + oteltrace.WithInstrumentationVersion(otelcontrib.Version()), ) if cfg.MeterProvider == nil { @@ -51,22 +51,22 @@ func Middleware(opts ...Option) fiber.Handler { } meter := cfg.MeterProvider.Meter( instrumentationName, - metric.WithInstrumentationVersion(otelcontrib.SemVersion()), + metric.WithInstrumentationVersion(otelcontrib.Version()), ) - httpServerDuration, err := meter.Float64Histogram(metricNameHttpServerDuration, metric.WithUnit(UnitMilliseconds), metric.WithDescription("measures the duration inbound HTTP requests")) + httpServerDuration, err := meter.Float64Histogram(MetricNameHttpServerDuration, metric.WithUnit(UnitMilliseconds), metric.WithDescription("measures the duration inbound HTTP requests")) if err != nil { otel.Handle(err) } - httpServerRequestSize, err := meter.Int64Histogram(metricNameHttpServerRequestSize, metric.WithUnit(UnitBytes), metric.WithDescription("measures the size of HTTP request messages")) + httpServerRequestSize, err := meter.Int64Histogram(MetricNameHttpServerRequestSize, metric.WithUnit(UnitBytes), metric.WithDescription("measures the size of HTTP request messages")) if err != nil { otel.Handle(err) } - httpServerResponseSize, err := meter.Int64Histogram(metricNameHttpServerResponseSize, metric.WithUnit(UnitBytes), metric.WithDescription("measures the size of HTTP response messages")) + httpServerResponseSize, err := meter.Int64Histogram(MetricNameHttpServerResponseSize, metric.WithUnit(UnitBytes), metric.WithDescription("measures the size of HTTP response messages")) if err != nil { otel.Handle(err) } - httpServerActiveRequests, err := meter.Int64UpDownCounter(metricNameHttpServerActiveRequests, metric.WithUnit(UnitDimensionless), metric.WithDescription("measures the number of concurrent HTTP requests that are currently in-flight")) + httpServerActiveRequests, err := meter.Int64UpDownCounter(MetricNameHttpServerActiveRequests, metric.WithUnit(UnitDimensionless), metric.WithDescription("measures the number of concurrent HTTP requests that are currently in-flight")) if err != nil { otel.Handle(err) } diff --git a/otelfiber/semconv.go b/otelfiber/semconv.go index c0bc8402..ebf3a3d2 100644 --- a/otelfiber/semconv.go +++ b/otelfiber/semconv.go @@ -53,7 +53,7 @@ func httpServerTraceAttributesFromRequest(c *fiber.Ctx, cfg config) []attribute. attrs = append(attrs, semconv.HTTPServerNameKey.String(*cfg.ServerName)) } - if username, ok := hasBasicAuth(c.Get(fiber.HeaderAuthorization)); ok { + if username, ok := HasBasicAuth(c.Get(fiber.HeaderAuthorization)); ok { attrs = append(attrs, semconv.EnduserIDKey.String(utils.CopyString(username))) } clientIP := c.IP() @@ -72,7 +72,7 @@ func httpFlavorAttribute(c *fiber.Ctx) attribute.KeyValue { return semconv.HTTPFlavorHTTP10 } -func hasBasicAuth(auth string) (string, bool) { +func HasBasicAuth(auth string) (string, bool) { if auth == "" { return "", false } diff --git a/otelfiber/fiber_test.go b/otelfiber/test/fiber_test.go similarity index 86% rename from otelfiber/fiber_test.go rename to otelfiber/test/fiber_test.go index 62b6c822..41ff88e5 100644 --- a/otelfiber/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -1,4 +1,4 @@ -package otelfiber +package test import ( "context" @@ -8,6 +8,7 @@ import ( "net/http/httptest" "testing" + "github.com/gofiber/contrib/otelfiber" "github.com/gofiber/fiber/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -22,43 +23,46 @@ import ( "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" "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" oteltrace "go.opentelemetry.io/otel/trace" ) -func TestChildSpanFromGlobalTracer(t *testing.T) { - otel.SetTracerProvider(oteltest.NewTracerProvider()) +const instrumentationName = "github.com/gofiber/contrib/otelfiber" - var gotSpan oteltrace.Span +func TestChildSpanFromGlobalTracer(t *testing.T) { + sr := tracetest.NewSpanRecorder() + tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(tp) app := fiber.New() - app.Use(Middleware()) + app.Use(otelfiber.Middleware()) app.Get("/user/:id", func(ctx *fiber.Ctx) error { - gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) }) _, _ = app.Test(httptest.NewRequest("GET", "/user/123", nil)) - _, ok := gotSpan.(*oteltest.Span) - assert.True(t, ok) + spans := sr.Ended() + require.Len(t, spans, 1) } func TestChildSpanFromCustomTracer(t *testing.T) { - provider := oteltest.NewTracerProvider() - var gotSpan oteltrace.Span + sr := tracetest.NewSpanRecorder() + tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(tp) app := fiber.New() - app.Use(Middleware(WithTracerProvider(provider))) + app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(tp))) app.Get("/user/:id", func(ctx *fiber.Ctx) error { - gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) }) _, _ = app.Test(httptest.NewRequest("GET", "/user/123", nil)) - _, ok := gotSpan.(*oteltest.Span) - assert.True(t, ok) + spans := sr.Ended() + require.Len(t, spans, 1) } func TestTrace200(t *testing.T) { @@ -70,9 +74,9 @@ func TestTrace200(t *testing.T) { app := fiber.New() app.Use( - Middleware( - WithTracerProvider(provider), - WithServerName(serverName), + otelfiber.Middleware( + otelfiber.WithTracerProvider(provider), + otelfiber.WithServerName(serverName), ), ) app.Get("/user/:id", func(ctx *fiber.Ctx) error { @@ -109,7 +113,7 @@ func TestError(t *testing.T) { // setup app := fiber.New() - app.Use(Middleware(WithTracerProvider(provider))) + 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 { @@ -137,7 +141,7 @@ func TestErrorOnlyHandledOnce(t *testing.T) { return fiber.NewError(http.StatusInternalServerError, err.Error()) }, }) - app.Use(Middleware()) + app.Use(otelfiber.Middleware()) app.Get("/", func(ctx *fiber.Ctx) error { return errors.New("mock error") }) @@ -175,7 +179,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header)) app := fiber.New() - app.Use(Middleware(WithTracerProvider(provider))) + app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) app.Get("/user/:id", func(ctx *fiber.Ctx) error { gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) @@ -202,7 +206,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) { b3.Inject(ctx, propagation.HeaderCarrier(r.Header)) app := fiber.New() - app.Use(Middleware(WithTracerProvider(provider), WithPropagators(b3))) + app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider), otelfiber.WithPropagators(b3))) app.Get("/user/:id", func(ctx *fiber.Ctx) error { gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) @@ -244,7 +248,7 @@ func TestHasBasicAuth(t *testing.T) { for _, tC := range testCases { t.Run(tC.desc, func(t *testing.T) { - val, valid := hasBasicAuth(tC.auth) + val, valid := otelfiber.HasBasicAuth(tC.auth) assert.Equal(t, tC.user, val) assert.Equal(t, tC.valid, valid) @@ -262,10 +266,10 @@ func TestMetric(t *testing.T) { app := fiber.New() app.Use( - Middleware( - WithMeterProvider(provider), - WithPort(port), - WithServerName(serverName), + otelfiber.Middleware( + otelfiber.WithMeterProvider(provider), + otelfiber.WithPort(port), + otelfiber.WithServerName(serverName), ), ) app.Get(route, func(ctx *fiber.Ctx) error { @@ -299,12 +303,12 @@ func TestMetric(t *testing.T) { func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, route string, requestAttrs []attribute.KeyValue, responseAttrs []attribute.KeyValue) { assert.Equal(t, instrumentation.Scope{ Name: instrumentationName, - Version: otelcontrib.SemVersion(), + Version: otelcontrib.Version(), }, sm.Scope) // Duration value is not predictable. m := sm.Metrics[0] - assert.Equal(t, metricNameHttpServerDuration, m.Name) + assert.Equal(t, otelfiber.MetricNameHttpServerDuration, m.Name) require.IsType(t, m.Data, metricdata.Histogram[float64]{}) hist := m.Data.(metricdata.Histogram[float64]) assert.Equal(t, metricdata.CumulativeTemporality, hist.Temporality) @@ -316,27 +320,27 @@ func assertScopeMetrics(t *testing.T, sm metricdata.ScopeMetrics, route string, // Request size want := metricdata.Metrics{ - Name: metricNameHttpServerRequestSize, + Name: otelfiber.MetricNameHttpServerRequestSize, Description: "measures the size of HTTP request messages", - Unit: UnitBytes, + Unit: otelfiber.UnitBytes, Data: getHistogram(0, responseAttrs), } metricdatatest.AssertEqual(t, want, sm.Metrics[1], metricdatatest.IgnoreTimestamp()) // Response size want = metricdata.Metrics{ - Name: metricNameHttpServerResponseSize, + Name: otelfiber.MetricNameHttpServerResponseSize, Description: "measures the size of HTTP response messages", - Unit: UnitBytes, + Unit: otelfiber.UnitBytes, Data: getHistogram(2, responseAttrs), } metricdatatest.AssertEqual(t, want, sm.Metrics[2], metricdatatest.IgnoreTimestamp()) // Active requests want = metricdata.Metrics{ - Name: metricNameHttpServerActiveRequests, + Name: otelfiber.MetricNameHttpServerActiveRequests, Description: "measures the number of concurrent HTTP requests that are currently in-flight", - Unit: UnitDimensionless, + Unit: otelfiber.UnitDimensionless, Data: metricdata.Sum[int64]{ DataPoints: []metricdata.DataPoint[int64]{ {Attributes: attribute.NewSet(requestAttrs...), Value: 0}, From dce60af492731ea9b49eab0c82c4d4d56d390a53 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Tue, 20 Jun 2023 21:06:14 +0100 Subject: [PATCH 02/17] adapt TestTrace200 --- otelfiber/test/fiber_test.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index 41ff88e5..b76af83b 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -66,21 +66,19 @@ func TestChildSpanFromCustomTracer(t *testing.T) { } func TestTrace200(t *testing.T) { - sr := new(oteltest.SpanRecorder) - provider := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)) + sr := tracetest.NewSpanRecorder() + tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(tp) serverName := "foobar" - var gotSpan oteltrace.Span - app := fiber.New() app.Use( otelfiber.Middleware( - otelfiber.WithTracerProvider(provider), + otelfiber.WithTracerProvider(tp), otelfiber.WithServerName(serverName), ), ) app.Get("/user/:id", func(ctx *fiber.Ctx) error { - gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) id := ctx.Params("id") return ctx.SendString(id) }) @@ -90,21 +88,20 @@ func TestTrace200(t *testing.T) { // do and verify the request require.Equal(t, http.StatusOK, resp.StatusCode) - mspan, ok := gotSpan.(*oteltest.Span) - require.True(t, ok) - assert.Equal(t, attribute.StringValue(serverName), mspan.Attributes()[semconv.HTTPServerNameKey]) + spans := sr.Ended() + require.Len(t, spans, 1) // verify traces look good - spans := sr.Completed() - require.Len(t, spans, 1) span := spans[0] + attr := span.Attributes() + assert.Equal(t, "/user/:id", span.Name()) assert.Equal(t, oteltrace.SpanKindServer, span.SpanKind()) - assert.Equal(t, attribute.StringValue("foobar"), span.Attributes()["http.server_name"]) - assert.Equal(t, attribute.IntValue(http.StatusOK), span.Attributes()["http.status_code"]) - assert.Equal(t, attribute.StringValue("GET"), span.Attributes()["http.method"]) - assert.Equal(t, attribute.StringValue("/user/123"), span.Attributes()["http.target"]) - assert.Equal(t, attribute.StringValue("/user/:id"), span.Attributes()["http.route"]) + assert.Contains(t, attr, attribute.String("http.server_name", serverName)) + assert.Contains(t, attr, attribute.Int("http.status_code", http.StatusOK)) + assert.Contains(t, attr, attribute.String("http.method", "GET")) + assert.Contains(t, attr, attribute.String("http.target", "/user/123")) + assert.Contains(t, attr, attribute.String("http.route", "/user/:id")) } func TestError(t *testing.T) { From 4279d8f27be85a6c1d2bcd248d7e9278a2eefe2e Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Thu, 22 Jun 2023 14:01:17 +0100 Subject: [PATCH 03/17] remove 1.18.x from test --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8495ea9..14a2a967 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,6 @@ jobs: strategy: matrix: go-version: - - 1.18.x - 1.19.x - 1.20.x platform: From 9803b7dc4f3e047cc6e55b68b65bd49267676ad9 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Thu, 22 Jun 2023 14:04:32 +0100 Subject: [PATCH 04/17] Working on TestError --- otelfiber/test/fiber_test.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index b76af83b..fb19a05c 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -16,7 +16,7 @@ import ( b3prop "go.opentelemetry.io/contrib/propagators/b3" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" + //"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -33,8 +33,8 @@ const instrumentationName = "github.com/gofiber/contrib/otelfiber" func TestChildSpanFromGlobalTracer(t *testing.T) { sr := tracetest.NewSpanRecorder() - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) app := fiber.New() app.Use(otelfiber.Middleware()) @@ -50,11 +50,11 @@ func TestChildSpanFromGlobalTracer(t *testing.T) { func TestChildSpanFromCustomTracer(t *testing.T) { sr := tracetest.NewSpanRecorder() - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) app := fiber.New() - app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(tp))) + app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) app.Get("/user/:id", func(ctx *fiber.Ctx) error { return ctx.SendStatus(http.StatusNoContent) }) @@ -67,14 +67,14 @@ func TestChildSpanFromCustomTracer(t *testing.T) { func TestTrace200(t *testing.T) { sr := tracetest.NewSpanRecorder() - tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) - otel.SetTracerProvider(tp) + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) serverName := "foobar" app := fiber.New() app.Use( otelfiber.Middleware( - otelfiber.WithTracerProvider(tp), + otelfiber.WithTracerProvider(provider), otelfiber.WithServerName(serverName), ), ) @@ -105,8 +105,9 @@ func TestTrace200(t *testing.T) { } func TestError(t *testing.T) { - sr := new(oteltest.SpanRecorder) - provider := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)) + sr := tracetest.NewSpanRecorder() + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) // setup app := fiber.New() @@ -120,14 +121,16 @@ func TestError(t *testing.T) { assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) // verify the errors and status are correct - spans := sr.Completed() + spans := sr.Ended() require.Len(t, spans, 1) span := spans[0] + attr := span.Attributes() + assert.Equal(t, "/server_err", span.Name()) - assert.Equal(t, attribute.IntValue(http.StatusInternalServerError), span.Attributes()["http.status_code"]) - assert.Equal(t, attribute.StringValue("oh no"), span.Events()[0].Attributes[semconv.ExceptionMessageKey]) + assert.Contains(t, attr, attribute.Int("http.status_code", http.StatusInternalServerError)) + //assert.Equal(t, attribute.StringValue("oh no"), span.Events()[0].Attributes[semconv.ExceptionMessageKey]) // server errors set the status - assert.Equal(t, codes.Error, span.StatusCode()) + // assert.Equal(t, codes.Error, span.StatusCode()) } func TestErrorOnlyHandledOnce(t *testing.T) { From 38224d0c457476fbe09eed3d202611f3d814d074 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Thu, 22 Jun 2023 21:57:38 +0100 Subject: [PATCH 05/17] Deprecate support for 1.18 --- otelfiber/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otelfiber/go.mod b/otelfiber/go.mod index de56e8cf..55d5ab5b 100644 --- a/otelfiber/go.mod +++ b/otelfiber/go.mod @@ -1,6 +1,6 @@ module github.com/gofiber/contrib/otelfiber -go 1.18 +go 1.19 require ( github.com/gofiber/fiber/v2 v2.47.0 From 7a924b0ff56c073f7ba396192c80278f5b773511 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Thu, 22 Jun 2023 22:22:06 +0100 Subject: [PATCH 06/17] Adapted TestError to tracetest --- otelfiber/test/fiber_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index fb19a05c..5b536cf5 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -16,7 +16,7 @@ import ( b3prop "go.opentelemetry.io/contrib/propagators/b3" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" - //"go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/instrumentation" @@ -125,12 +125,12 @@ func TestError(t *testing.T) { require.Len(t, spans, 1) span := spans[0] attr := span.Attributes() - + assert.Equal(t, "/server_err", span.Name()) assert.Contains(t, attr, attribute.Int("http.status_code", http.StatusInternalServerError)) - //assert.Equal(t, attribute.StringValue("oh no"), span.Events()[0].Attributes[semconv.ExceptionMessageKey]) + assert.Equal(t, attribute.StringValue("oh no"), span.Events()[0].Attributes[1].Value) // server errors set the status - // assert.Equal(t, codes.Error, span.StatusCode()) + assert.Equal(t, codes.Error, span.Status().Code) } func TestErrorOnlyHandledOnce(t *testing.T) { From 6f8310bbfde4e39c1ddcb797b95c47514487427d Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Fri, 23 Jun 2023 07:58:29 +0100 Subject: [PATCH 07/17] Adapt TestPropagationWithGlobalPropagators --- otelfiber/test/fiber_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index 5b536cf5..a414140c 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -167,11 +167,11 @@ func TestGetSpanNotInstrumented(t *testing.T) { } func TestPropagationWithGlobalPropagators(t *testing.T) { - sr := new(oteltest.SpanRecorder) - provider := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)) + sr := tracetest.NewSpanRecorder() + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) otel.SetTextMapPropagator(propagation.TraceContext{}) defer otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator()) - var gotSpan oteltrace.Span r := httptest.NewRequest("GET", "/user/123", nil) @@ -181,16 +181,18 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { app := fiber.New() app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) app.Get("/user/:id", func(ctx *fiber.Ctx) error { - gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) }) _, _ = app.Test(r) - mspan, ok := gotSpan.(*oteltest.Span) - require.True(t, ok) - assert.Equal(t, pspan.SpanContext().TraceID(), mspan.SpanContext().TraceID()) - assert.Equal(t, pspan.SpanContext().SpanID(), mspan.ParentSpanID()) + spans := sr.Ended() + require.Len(t, spans, 1) + + // verify traces look good + span := spans[0] + assert.Equal(t, pspan.SpanContext().TraceID(), span.SpanContext().TraceID()) + assert.Equal(t, pspan.SpanContext().SpanID(), span.Parent().SpanID()) } func TestPropagationWithCustomPropagators(t *testing.T) { From 5fe5cfa8fa116b6c10e1e5eb290f63a09b1d6c4c Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Sat, 24 Jun 2023 08:23:42 +0100 Subject: [PATCH 08/17] Adapt TestPropagationWithCustomPropagators --- otelfiber/test/fiber_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index a414140c..11a5519d 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -17,7 +17,6 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/oteltest" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric" @@ -196,9 +195,9 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { } func TestPropagationWithCustomPropagators(t *testing.T) { - sr := new(oteltest.SpanRecorder) - provider := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)) - var gotSpan oteltrace.Span + sr := tracetest.NewSpanRecorder() + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) b3 := b3prop.New() @@ -210,16 +209,16 @@ 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 { - gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) }) _, _ = app.Test(r) - mspan, ok := gotSpan.(*oteltest.Span) - require.True(t, ok) + spans := sr.Ended() + require.Len(t, spans, 1) + mspan := spans[0] assert.Equal(t, pspan.SpanContext().TraceID(), mspan.SpanContext().TraceID()) - assert.Equal(t, pspan.SpanContext().SpanID(), mspan.ParentSpanID()) + assert.Equal(t, pspan.SpanContext().SpanID(), mspan.Parent().SpanID()) } func TestHasBasicAuth(t *testing.T) { From 3d48cb2aec74c3a40b6ee3106bf9eb0e555135a1 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Sat, 24 Jun 2023 08:25:11 +0100 Subject: [PATCH 09/17] tidy up mod --- otelfiber/go.mod | 1 - otelfiber/go.sum | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/otelfiber/go.mod b/otelfiber/go.mod index 55d5ab5b..f7da33a4 100644 --- a/otelfiber/go.mod +++ b/otelfiber/go.mod @@ -9,7 +9,6 @@ require ( go.opentelemetry.io/contrib/propagators/b3 v1.17.0 go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/metric v1.16.0 - go.opentelemetry.io/otel/oteltest v1.0.0-RC3 go.opentelemetry.io/otel/sdk v1.16.0 go.opentelemetry.io/otel/sdk/metric v0.39.0 go.opentelemetry.io/otel/trace v1.16.0 diff --git a/otelfiber/go.sum b/otelfiber/go.sum index 5b90ab3b..48ae8127 100644 --- a/otelfiber/go.sum +++ b/otelfiber/go.sum @@ -1,6 +1,5 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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= @@ -10,7 +9,6 @@ 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.47.0 h1:EN5lHVCc+Pyqh5OEsk8fzRiifgwpbrP0rulQ4iNf3fs= github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5lmcNksUoU= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -36,8 +34,6 @@ github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3 github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk= github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw= @@ -55,18 +51,14 @@ go.opentelemetry.io/contrib v1.17.0 h1:lJJdtuNsP++XHD7tXDYEFSpsqIc7DzShuXMR5Pwkm go.opentelemetry.io/contrib v1.17.0/go.mod h1:gIzjwWFoGazJmtCaDgViqOSJPde2mCWzv60o0bWPcZs= go.opentelemetry.io/contrib/propagators/b3 v1.17.0 h1:ImOVvHnku8jijXqkwCSyYKRDt2YrnGXD4BbhcpfbfJo= go.opentelemetry.io/contrib/propagators/b3 v1.17.0/go.mod h1:IkfUfMpKWmynvvE0264trz0sf32NRTZL4nuAN9AbWRc= -go.opentelemetry.io/otel v1.0.0-RC3/go.mod h1:Ka5j3ua8tZs4Rkq4Ex3hwgBgOchyPVq5S6P2lz//nKQ= go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= -go.opentelemetry.io/otel/oteltest v1.0.0-RC3 h1:MjaeegZTaX0Bv9uB9CrdVjOFM/8slRjReoWoV9xDCpY= -go.opentelemetry.io/otel/oteltest v1.0.0-RC3/go.mod h1:xpzajI9JBRr7gX63nO6kAmImmYIAtuQblZ36Z+LfCjE= go.opentelemetry.io/otel/sdk v1.16.0 h1:Z1Ok1YsijYL0CSJpHt4cS3wDDh7p572grzNrBMiMWgE= go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF9QD68aP6p4= go.opentelemetry.io/otel/sdk/metric v0.39.0 h1:Kun8i1eYf48kHH83RucG93ffz0zGV1sh46FAScOTuDI= go.opentelemetry.io/otel/sdk/metric v0.39.0/go.mod h1:piDIRgjcK7u0HCL5pCA4e74qpK/jk3NiUoAHATVAmiI= -go.opentelemetry.io/otel/trace v1.0.0-RC3/go.mod h1:VUt2TUYd8S2/ZRX09ZDFZQwn2RqfMB5MzO17jBojGxo= go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -112,10 +104,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 5a749cbce54d0bceaeccc19a216d7a1ab244e3a1 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Mon, 26 Jun 2023 09:14:27 +0100 Subject: [PATCH 10/17] add v2 and adapt new test --- otelfiber/example/go.sum | 9 --------- otelfiber/go.mod | 2 +- otelfiber/test/fiber_test.go | 13 ++++++------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/otelfiber/example/go.sum b/otelfiber/example/go.sum index f4256dd5..8dbefacd 100644 --- a/otelfiber/example/go.sum +++ b/otelfiber/example/go.sum @@ -11,8 +11,6 @@ github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.16.3 h1:XuJt9zzcnaz6a16/OU53ZjWp/v7/42WcR5t2a0PcNQY= -github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -27,8 +25,6 @@ github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw= github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0= 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.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= -github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4= @@ -42,8 +38,6 @@ github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0= github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw= 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.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c= -github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc= github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= @@ -52,17 +46,14 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/contrib v1.17.0 h1:lJJdtuNsP++XHD7tXDYEFSpsqIc7DzShuXMR5PwkmzA= go.opentelemetry.io/contrib v1.17.0/go.mod h1:gIzjwWFoGazJmtCaDgViqOSJPde2mCWzv60o0bWPcZs= -go.opentelemetry.io/contrib/propagators/b3 v1.17.0 h1:ImOVvHnku8jijXqkwCSyYKRDt2YrnGXD4BbhcpfbfJo= go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s= go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.16.0 h1:+XWJd3jf75RXJq29mxbuXhCXFDG3S3R4vBUeSI2P7tE= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.16.0/go.mod h1:hqgzBPTf4yONMFgdZvL/bK42R/iinTyVQtiWihs3SZc= go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo= go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4= -go.opentelemetry.io/otel/oteltest v1.0.0-RC3 h1:MjaeegZTaX0Bv9uB9CrdVjOFM/8slRjReoWoV9xDCpY= go.opentelemetry.io/otel/sdk v1.16.0 h1:Z1Ok1YsijYL0CSJpHt4cS3wDDh7p572grzNrBMiMWgE= go.opentelemetry.io/otel/sdk v1.16.0/go.mod h1:tMsIuKXuuIWPBAOrH+eHtvhTL+SntFtXF9QD68aP6p4= -go.opentelemetry.io/otel/sdk/metric v0.39.0 h1:Kun8i1eYf48kHH83RucG93ffz0zGV1sh46FAScOTuDI= go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs= go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/otelfiber/go.mod b/otelfiber/go.mod index f7da33a4..9498b4a5 100644 --- a/otelfiber/go.mod +++ b/otelfiber/go.mod @@ -1,4 +1,4 @@ -module github.com/gofiber/contrib/otelfiber +module github.com/gofiber/contrib/otelfiber/v2 go 1.19 diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index edaff680..319d42fd 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -8,7 +8,7 @@ import ( "net/http/httptest" "testing" - "github.com/gofiber/contrib/otelfiber" + "github.com/gofiber/contrib/otelfiber/v2" "github.com/gofiber/fiber/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -65,9 +65,9 @@ func TestChildSpanFromCustomTracer(t *testing.T) { } func TestSkipWithNext(t *testing.T) { - otel.SetTracerProvider(oteltest.NewTracerProvider()) - - var gotSpan oteltrace.Span + sr := tracetest.NewSpanRecorder() + provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) + otel.SetTracerProvider(provider) app := fiber.New() app.Use(Middleware(WithNext(func(c *fiber.Ctx) bool { @@ -75,14 +75,13 @@ func TestSkipWithNext(t *testing.T) { }))) app.Get("/health", func(ctx *fiber.Ctx) error { - gotSpan = oteltrace.SpanFromContext(ctx.UserContext()) return ctx.SendStatus(http.StatusNoContent) }) _, _ = app.Test(httptest.NewRequest("GET", "/health", nil)) - _, ok := gotSpan.(*oteltest.Span) - assert.False(t, ok) + spans := sr.Ended() + require.Len(t, spans, 0) } func TestTrace200(t *testing.T) { From bc5995742224ef3efc790fe8accb4557c0e5a7b3 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Tue, 27 Jun 2023 08:14:12 +0100 Subject: [PATCH 11/17] update README with v2 --- otelfiber/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otelfiber/README.md b/otelfiber/README.md index 01d42d84..29672868 100644 --- a/otelfiber/README.md +++ b/otelfiber/README.md @@ -15,7 +15,7 @@ Can be found on [OpenTelemetry Registry](https://opentelemetry.io/registry/instr This middleware supports Fiber v2. ``` -go get -u github.com/gofiber/contrib/otelfiber +go get -u github.com/gofiber/contrib/otelfiber/v2 ``` ### Signature From fe46bb23f89116b7d941c7f9a3f2e67af17b25c8 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Tue, 27 Jun 2023 08:24:54 +0100 Subject: [PATCH 12/17] fix test --- otelfiber/test/fiber_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index 319d42fd..25130dce 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -70,7 +70,7 @@ func TestSkipWithNext(t *testing.T) { otel.SetTracerProvider(provider) app := fiber.New() - app.Use(Middleware(WithNext(func(c *fiber.Ctx) bool { + app.Use(otelfiber.Middleware(otelfiber.WithNext(func(c *fiber.Ctx) bool { return c.Path() == "/health" }))) From 898b8a6c397413cbdf017005eda7fa5d2a66cfd6 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Mon, 3 Jul 2023 09:15:41 +0100 Subject: [PATCH 13/17] removed test for Go 1.18.x --- .github/workflows/test-otelfiber.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-otelfiber.yml b/.github/workflows/test-otelfiber.yml index 483ecc83..38b3c9b5 100644 --- a/.github/workflows/test-otelfiber.yml +++ b/.github/workflows/test-otelfiber.yml @@ -17,7 +17,6 @@ jobs: strategy: matrix: go-version: - - 1.18.x - 1.19.x - 1.20.x steps: From 175618082129aefcd7ad59865082c10613714905 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Mon, 3 Jul 2023 09:54:22 +0100 Subject: [PATCH 14/17] update comment --- otelfiber/test/fiber_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/test/fiber_test.go index 25130dce..bf675fc8 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/test/fiber_test.go @@ -131,8 +131,7 @@ func TestError(t *testing.T) { // setup app := fiber.New() app.Use(otelfiber.Middleware(otelfiber.WithTracerProvider(provider))) - // configure a handler that returns an error and 5xx status - // code + // configure a handler that returns an error and 5xx status code app.Get("/server_err", func(ctx *fiber.Ctx) error { return errors.New("oh no") }) From 9c8cd70fc3c5644816f386991c3cc9f2995f8fea Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Mon, 3 Jul 2023 09:59:37 +0100 Subject: [PATCH 15/17] deleted test.yml --- .github/workflows/test.yml | 49 -------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index b8495ea9..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,49 +0,0 @@ -on: - push: - branches: - - master - - main - pull_request: -name: Tests -jobs: - Tests: - name: Tests - strategy: - matrix: - go-version: - - 1.18.x - - 1.19.x - - 1.20.x - platform: - - ubuntu-latest - - windows-latest - runs-on: '${{ matrix.platform }}' - steps: - - name: Fetch Repository - uses: actions/checkout@v3 - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: '${{ matrix.go-version }}' - - name: Test PASETO Middleware - run: cd ./paseto && go test ./... -v -race - - name: Test Fiberzap Middleware - run: cd ./fiberzap && go test ./... -v -race - - name: Test otelfiber Middleware - run: cd ./otelfiber && go test ./... -v -race - - name: Test swagger Middleware - run: cd ./swagger && go test ./... -v -race - - name: Test casbin Middleware - run: cd ./casbin && go test ./... -v -race - - name: Test fibernewrelic Middleware - run: cd ./fibernewrelic && go test ./... -v -race - - name: Test opafiber Middleware - run: cd ./opafiber && go test ./... -v -race - - name: Test fiberi18n Middleware - run: cd ./fiberi18n && go test ./... -v -race - - name: Test fiberzerolog Middleware - run: cd ./fiberzerolog && go test ./... -v -race - - name: Test jwt Middleware - run: cd ./jwt && go test ./... -v -race - - name: Test websocket Middleware - run: cd ./websocket && go test ./... -v -race From 439c13a1de1be90fddc906deb7d02446a46a9ba0 Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Mon, 3 Jul 2023 10:12:15 +0100 Subject: [PATCH 16/17] update otelfiber in example code --- otelfiber/example/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otelfiber/example/go.mod b/otelfiber/example/go.mod index a6186a44..95e0f440 100644 --- a/otelfiber/example/go.mod +++ b/otelfiber/example/go.mod @@ -5,7 +5,7 @@ go 1.18 replace github.com/gofiber/contrib/otelfiber => ../ require ( - github.com/gofiber/contrib/otelfiber v1.0.8 + github.com/gofiber/contrib/otelfiber v1.0.9 github.com/gofiber/fiber/v2 v2.47.0 go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.16.0 From 8e36271833616cb7e216c7297297f91704b7399e Mon Sep 17 00:00:00 2001 From: Emanuele Fumagalli Date: Tue, 11 Jul 2023 04:19:54 +0100 Subject: [PATCH 17/17] renamed test package --- otelfiber/{test => otelfiber_test}/fiber_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename otelfiber/{test => otelfiber_test}/fiber_test.go (99%) diff --git a/otelfiber/test/fiber_test.go b/otelfiber/otelfiber_test/fiber_test.go similarity index 99% rename from otelfiber/test/fiber_test.go rename to otelfiber/otelfiber_test/fiber_test.go index bf675fc8..ce584ee6 100644 --- a/otelfiber/test/fiber_test.go +++ b/otelfiber/otelfiber_test/fiber_test.go @@ -1,4 +1,4 @@ -package test +package otelfiber_test import ( "context"