From 67d9e049512eddb98dd728b3a94804663f573408 Mon Sep 17 00:00:00 2001 From: "Pasha, Rehan" Date: Mon, 16 Oct 2023 06:28:29 -0400 Subject: [PATCH 1/8] change the Filter parameter from *http.Request to *gin.Context #3070 #4375 --- instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go | 2 +- instrumentation/github.com/gin-gonic/gin/otelgin/option.go | 5 +++-- .../github.com/gin-gonic/gin/otelgin/test/gintrace_test.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go index c114d085578..d137226b64f 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go @@ -55,7 +55,7 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc { } return func(c *gin.Context) { for _, f := range cfg.Filters { - if !f(c.Request) { + if !f(c) { // Serve the request to the next middleware // if a filter rejects the request. c.Next() diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/option.go b/instrumentation/github.com/gin-gonic/gin/otelgin/option.go index c13c3dad815..abcc76789d1 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/option.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/option.go @@ -19,6 +19,7 @@ package otelgin // import "go.opentelemetry.io/contrib/instrumentation/github.co import ( "net/http" + "github.com/gin-gonic/gin" "go.opentelemetry.io/otel/propagation" oteltrace "go.opentelemetry.io/otel/trace" ) @@ -30,9 +31,9 @@ type config struct { SpanNameFormatter SpanNameFormatter } -// Filter is a predicate used to determine whether a given http.request should +// Filter is a predicate used to determine whether a given gin.Context should // be traced. A Filter must return true if the request should be traced. -type Filter func(*http.Request) bool +type Filter func(*gin.Context) bool // SpanNameFormatter is used to set span name by http.request. type SpanNameFormatter func(r *http.Request) string diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go b/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go index 184a03713e2..897c88eedaf 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go @@ -235,7 +235,7 @@ func TestWithFilter(t *testing.T) { otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))) router := gin.New() - f := func(req *http.Request) bool { return req.URL.Path != "/healthcheck" } + f := func(req *gin.Context) bool { return c.Request.URL.Path != "/healthcheck" } router.Use(otelgin.Middleware("foobar", otelgin.WithFilter(f))) router.GET("/healthcheck", func(c *gin.Context) {}) @@ -251,7 +251,7 @@ func TestWithFilter(t *testing.T) { otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))) router := gin.New() - f := func(req *http.Request) bool { return req.URL.Path != "/healthcheck" } + f := func(req *gin.Context) bool { return c.Request.URL.Path != "/healthcheck" } router.Use(otelgin.Middleware("foobar", otelgin.WithFilter(f))) router.GET("/user/:id", func(c *gin.Context) {}) From 9f5655c444948ebc973791e7d855b818e980ddd3 Mon Sep 17 00:00:00 2001 From: "Pasha, Rehan" Date: Mon, 16 Oct 2023 06:33:33 -0400 Subject: [PATCH 2/8] adding changelog #3070 #4375 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1af4e337007..eba6c254e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Changed + +- Change the Filter parameter from *http.Request to *gin.Context in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` (#4444) + ### Added - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) From c348bec7513dfc1d1b4f06168140a72a1ccc90b1 Mon Sep 17 00:00:00 2001 From: rehanpfmr <111350825+rehanpfmr@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:50:03 +0530 Subject: [PATCH 3/8] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eba6c254e71..25da72e19f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed -- Change the Filter parameter from *http.Request to *gin.Context in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` (#4444) +- Change the `Filter` parameter from `*http.Request` to `*gin.Context` in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#4444) ### Added From 6172e43d730e56b3b4a932ec4e796931a952c102 Mon Sep 17 00:00:00 2001 From: rehanpfmr <111350825+rehanpfmr@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:25:38 +0530 Subject: [PATCH 4/8] Update CHANGELOG.md --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae1d0ca6ded..c39ca262980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] -### Changed - -- Change the `Filter` parameter from `*http.Request` to `*gin.Context` in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#4444) - ### Added - Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108) From a91fa5c5c3579a36382ed4fbcd32b497c250708c Mon Sep 17 00:00:00 2001 From: rehanpfmr <111350825+rehanpfmr@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:26:38 +0530 Subject: [PATCH 5/8] Update gintrace.go --- instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go index 41660ecb183..45c8f854fc7 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go @@ -55,7 +55,7 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc { } return func(c *gin.Context) { for _, f := range cfg.Filters { - if !f(c) { + if !f(c.Request) { // Serve the request to the next middleware // if a filter rejects the request. c.Next() From cd44dd7b2a95e90e41c543d2eb0d4b66926d7080 Mon Sep 17 00:00:00 2001 From: rehanpfmr <111350825+rehanpfmr@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:28:14 +0530 Subject: [PATCH 6/8] Update option.go --- instrumentation/github.com/gin-gonic/gin/otelgin/option.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/option.go b/instrumentation/github.com/gin-gonic/gin/otelgin/option.go index abcc76789d1..4a12decf89b 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/option.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/option.go @@ -31,9 +31,9 @@ type config struct { SpanNameFormatter SpanNameFormatter } -// Filter is a predicate used to determine whether a given gin.Context should +// Filter is a predicate used to determine whether a given http.request should // be traced. A Filter must return true if the request should be traced. -type Filter func(*gin.Context) bool +type Filter func(*http.request) bool // SpanNameFormatter is used to set span name by http.request. type SpanNameFormatter func(r *http.Request) string From f8ca2e1082c01aa45ef4d80af6f896f4466a926a Mon Sep 17 00:00:00 2001 From: rehanpfmr <111350825+rehanpfmr@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:29:16 +0530 Subject: [PATCH 7/8] Update option.go --- instrumentation/github.com/gin-gonic/gin/otelgin/option.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/option.go b/instrumentation/github.com/gin-gonic/gin/otelgin/option.go index 4a12decf89b..024b1b3dfcb 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/option.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/option.go @@ -33,7 +33,7 @@ type config struct { // Filter is a predicate used to determine whether a given http.request should // be traced. A Filter must return true if the request should be traced. -type Filter func(*http.request) bool +type Filter func(*http.Request) bool // SpanNameFormatter is used to set span name by http.request. type SpanNameFormatter func(r *http.Request) string From 872603d64b578f4787ecc022c18e8b9d04d34c6f Mon Sep 17 00:00:00 2001 From: rehanpfmr <111350825+rehanpfmr@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:30:58 +0530 Subject: [PATCH 8/8] Update gintrace_test.go --- .../github.com/gin-gonic/gin/otelgin/test/gintrace_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go b/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go index 897c88eedaf..184a03713e2 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/test/gintrace_test.go @@ -235,7 +235,7 @@ func TestWithFilter(t *testing.T) { otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))) router := gin.New() - f := func(req *gin.Context) bool { return c.Request.URL.Path != "/healthcheck" } + f := func(req *http.Request) bool { return req.URL.Path != "/healthcheck" } router.Use(otelgin.Middleware("foobar", otelgin.WithFilter(f))) router.GET("/healthcheck", func(c *gin.Context) {}) @@ -251,7 +251,7 @@ func TestWithFilter(t *testing.T) { otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))) router := gin.New() - f := func(req *gin.Context) bool { return c.Request.URL.Path != "/healthcheck" } + f := func(req *http.Request) bool { return req.URL.Path != "/healthcheck" } router.Use(otelgin.Middleware("foobar", otelgin.WithFilter(f))) router.GET("/user/:id", func(c *gin.Context) {})