Skip to content

Commit 0cac051

Browse files
committed
[CHORE] moved TestHTTPRouteAttribute to test subfolder - instrumentation/github.com/labstack/echo/otelecho/test
1 parent b7c1918 commit 0cac051

File tree

4 files changed

+34
-44
lines changed

4 files changed

+34
-44
lines changed

instrumentation/github.com/labstack/echo/otelecho/echo_test.go

-36
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
b3prop "go.opentelemetry.io/contrib/propagators/b3"
1818
"go.opentelemetry.io/otel"
1919
"go.opentelemetry.io/otel/propagation"
20-
sdktrace "go.opentelemetry.io/otel/sdk/trace"
21-
"go.opentelemetry.io/otel/sdk/trace/tracetest"
2220
"go.opentelemetry.io/otel/trace"
2321
"go.opentelemetry.io/otel/trace/noop"
2422
)
@@ -119,37 +117,3 @@ func TestSkipper(t *testing.T) {
119117
router.ServeHTTP(w, r)
120118
assert.Equal(t, http.StatusOK, w.Result().StatusCode, "should call the 'ping' handler") //nolint:bodyclose // False positive for httptest.ResponseRecorder: https://github.com/timakin/bodyclose/issues/59.
121119
}
122-
123-
func TestHTTPRouteAttribute(t *testing.T) {
124-
// Set up an in-memory span recorder
125-
sr := tracetest.NewSpanRecorder()
126-
tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))
127-
128-
// Create Echo instance with middleware
129-
e := echo.New()
130-
e.Use(Middleware("test-service", WithTracerProvider(tp)))
131-
e.GET("/users/:id", func(c echo.Context) error {
132-
return c.String(http.StatusOK, "ok")
133-
})
134-
135-
// Simulate a request
136-
r := httptest.NewRequest("GET", "/users/123", nil)
137-
w := httptest.NewRecorder()
138-
e.ServeHTTP(w, r)
139-
140-
// Check response
141-
assert.Equal(t, http.StatusOK, w.Result().StatusCode)
142-
143-
// Verify span attributes
144-
spans := sr.Ended()
145-
assert.Len(t, spans, 1, "expected one span")
146-
147-
found := false
148-
for _, attr := range spans[0].Attributes() {
149-
if attr.Key == "http.route" && attr.Value.AsString() == "/users/:id" {
150-
found = true
151-
break
152-
}
153-
}
154-
assert.True(t, found, "http.route attribute not found or incorrect, got %v", spans[0].Attributes())
155-
}

instrumentation/github.com/labstack/echo/otelecho/go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ require (
1010
go.opentelemetry.io/contrib/propagators/b3 v1.35.0
1111
go.opentelemetry.io/otel v1.35.0
1212
go.opentelemetry.io/otel/metric v1.35.0
13-
go.opentelemetry.io/otel/sdk v1.35.0
1413
go.opentelemetry.io/otel/trace v1.35.0
1514
)
1615

1716
require (
1817
github.com/davecgh/go-spew v1.1.1 // indirect
1918
github.com/go-logr/logr v1.4.2 // indirect
2019
github.com/go-logr/stdr v1.2.2 // indirect
21-
github.com/google/uuid v1.6.0 // indirect
2220
github.com/labstack/gommon v0.4.2 // indirect
2321
github.com/mattn/go-colorable v0.1.14 // indirect
2422
github.com/mattn/go-isatty v0.0.20 // indirect

instrumentation/github.com/labstack/echo/otelecho/go.sum

-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
77
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
88
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
99
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
10-
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
11-
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1210
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1311
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1412
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -37,12 +35,8 @@ go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
3735
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
3836
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
3937
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
40-
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
41-
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
4238
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
4339
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
44-
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
45-
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
4640
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
4741
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
4842
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=

instrumentation/github.com/labstack/echo/otelecho/test/echo_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,37 @@ func TestSpanNameFormatter(t *testing.T) {
256256
})
257257
}
258258
}
259+
260+
func TestHTTPRouteAttribute(t *testing.T) {
261+
// Set up an in-memory span recorder
262+
sr := tracetest.NewSpanRecorder()
263+
tp := trace.NewTracerProvider(trace.WithSpanProcessor(sr))
264+
265+
// Create Echo instance with middleware
266+
e := echo.New()
267+
e.Use(otelecho.Middleware("test-service", otelecho.WithTracerProvider(tp)))
268+
e.GET("/users/:id", func(c echo.Context) error {
269+
return c.String(http.StatusOK, "ok")
270+
})
271+
272+
// Simulate a request
273+
r := httptest.NewRequest("GET", "/users/123", nil)
274+
w := httptest.NewRecorder()
275+
e.ServeHTTP(w, r)
276+
277+
// Check response
278+
assert.Equal(t, http.StatusOK, w.Result().StatusCode)
279+
280+
// Verify span attributes
281+
spans := sr.Ended()
282+
assert.Len(t, spans, 1, "expected one span")
283+
284+
found := false
285+
for _, attr := range spans[0].Attributes() {
286+
if attr.Key == "http.route" && attr.Value.AsString() == "/users/:id" {
287+
found = true
288+
break
289+
}
290+
}
291+
assert.True(t, found, "http.route attribute not found or incorrect, got %v", spans[0].Attributes())
292+
}

0 commit comments

Comments
 (0)