diff --git a/instrumentation/github.com/labstack/echo/otelecho/config.go b/instrumentation/github.com/labstack/echo/otelecho/config.go index 9873c069728..7af5f39ad28 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/config.go +++ b/instrumentation/github.com/labstack/echo/otelecho/config.go @@ -5,6 +5,7 @@ package otelecho // import "go.opentelemetry.io/contrib/instrumentation/github.c import ( "net/http" + "strings" "github.com/labstack/echo/v4/middleware" @@ -14,7 +15,7 @@ import ( // defaultSpanNameFormatter is the default function used for formatting span names. var defaultSpanNameFormatter = func(path string, req *http.Request) string { - return req.Method + " " + path + return strings.ToUpper(req.Method) + " " + path } // SpanNameFormatter is a function that takes a path and an HTTP request and returns a span name. diff --git a/instrumentation/github.com/labstack/echo/otelecho/test/echo_test.go b/instrumentation/github.com/labstack/echo/otelecho/test/echo_test.go index 116f556708a..4b767e13f94 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/test/echo_test.go +++ b/instrumentation/github.com/labstack/echo/otelecho/test/echo_test.go @@ -217,7 +217,7 @@ func TestSpanNameFormatter(t *testing.T) { }, { name: "custom", - formatter: func(path string, req *http.Request) string { + formatter: func(path string, _ *http.Request) string { return "custom " + path }, expected: "custom /user/:id", @@ -244,9 +244,8 @@ func TestSpanNameFormatter(t *testing.T) { return c.NoContent(http.StatusOK) }) - r := httptest.NewRequest("GET", "/user/123", nil) + r := httptest.NewRequest(http.MethodGet, "/user/123", nil) w := httptest.NewRecorder() - router.ServeHTTP(w, r) spans := imsb.GetSpans() @@ -254,4 +253,26 @@ func TestSpanNameFormatter(t *testing.T) { assert.Equal(t, test.expected, spans[0].Name) }) } + + t.Run("test default span name formatter with lowercase method", func(t *testing.T) { + router := echo.New() + router.Use(otelecho.Middleware("foobar", + otelecho.WithTracerProvider(provider)), + ) + router.GET("/user/:id", func(c echo.Context) error { + return c.NoContent(http.StatusOK) + }) + + for _, method := range []string{"Get", "GET", "get"} { + r := httptest.NewRequest(method, "/user/123", nil) + w := httptest.NewRecorder() + router.ServeHTTP(w, r) + + spans := imsb.GetSpans() + assert.Len(t, spans, 1) + assert.Equal(t, "GET /user/:id", spans[0].Name) + + imsb.Reset() + } + }) }