diff --git a/go.mod b/go.mod index dc043e2a9..ba3fdfab2 100644 --- a/go.mod +++ b/go.mod @@ -76,7 +76,7 @@ require ( github.com/pkg/xattr v0.4.9 github.com/prometheus/client_golang v1.19.1 github.com/r3labs/sse/v2 v2.10.0 - github.com/riandyrn/otelchi v0.8.0 + github.com/riandyrn/otelchi v0.9.0 github.com/rogpeppe/go-internal v1.12.0 github.com/rs/cors v1.11.0 github.com/rs/zerolog v1.33.0 diff --git a/go.sum b/go.sum index a36d9aabe..247756aaf 100644 --- a/go.sum +++ b/go.sum @@ -1036,8 +1036,8 @@ github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKc github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/riandyrn/otelchi v0.8.0 h1:q60HKpwt1MmGjOWgM7m5gGyXYAY3DfTSdfBdBt6ICV4= -github.com/riandyrn/otelchi v0.8.0/go.mod h1:ErTae2TG7lrOtEPFsd5/hYLOHJpkk0NNyMaeTMWxl0U= +github.com/riandyrn/otelchi v0.9.0 h1:BuQxXR7/JF2yYOQl21Yyz5d52hns/96ecAaPUZiKQzc= +github.com/riandyrn/otelchi v0.9.0/go.mod h1:iX30kllzThsf8oEcEbl3GifPJZtN4cnCWUUc+UhE4yM= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8= github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= diff --git a/vendor/github.com/riandyrn/otelchi/CHANGELOG.md b/vendor/github.com/riandyrn/otelchi/CHANGELOG.md index 2d5aa4718..62595863b 100644 --- a/vendor/github.com/riandyrn/otelchi/CHANGELOG.md +++ b/vendor/github.com/riandyrn/otelchi/CHANGELOG.md @@ -8,6 +8,19 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +## [0.9.0] - 2024-07-06 + +### Changed + +- `WithFilter` option now support multiple filter functions, just like in [otelmux](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/v1.24.0/instrumentation/github.com/gorilla/mux/otelmux/config.go#L106-L110). ([#47]) +- Upgrade `go.opentelemetry.io/otel`, `go.opentelemetry.io/otel/sdk`, & `go.opentelemetry.io/otel/trace` to `v1.28.0`. ([#49]) +- Upgrade `github.com/go-chi/chi/v5` to `v5.1.0`. ([#49]) +- Set the go versions for testing in both `Makefile` & `compatibility-test.yml` to `1.21` & `1.22`. ([#49]) + +### Removed + +- Drop support for Go `<1.21`. ([#49]) + ## [0.8.0] - 2024-04-29 ### ⚠️ Notice ⚠️ @@ -161,6 +174,8 @@ It contains instrumentation for trace and depends on: - Example code for a basic usage. - Apache-2.0 license. +[#49]: https://github.com/riandyrn/otelchi/pull/49 +[#47]: https://github.com/riandyrn/otelchi/pull/47 [#43]: https://github.com/riandyrn/otelchi/pull/43 [#42]: https://github.com/riandyrn/otelchi/pull/42 [#41]: https://github.com/riandyrn/otelchi/pull/41 @@ -181,7 +196,8 @@ It contains instrumentation for trace and depends on: [#2]: https://github.com/riandyrn/otelchi/pull/2 [#1]: https://github.com/riandyrn/otelchi/pull/1 -[Unreleased]: https://github.com/riandyrn/otelchi/compare/v0.8.0...HEAD +[Unreleased]: https://github.com/riandyrn/otelchi/compare/v0.9.0...HEAD +[0.9.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.9.0 [0.8.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.8.0 [0.7.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.7.0 [0.6.0]: https://github.com/riandyrn/otelchi/releases/tag/v0.6.0 diff --git a/vendor/github.com/riandyrn/otelchi/CODEOWNERS b/vendor/github.com/riandyrn/otelchi/CODEOWNERS index d9e23c453..9445a6d02 100644 --- a/vendor/github.com/riandyrn/otelchi/CODEOWNERS +++ b/vendor/github.com/riandyrn/otelchi/CODEOWNERS @@ -1 +1 @@ -* @riandyrn @ilhamsyahids @mustafasegf @ProtozoaJr \ No newline at end of file +* @riandyrn @ilhamsyahids @ProtozoaJr \ No newline at end of file diff --git a/vendor/github.com/riandyrn/otelchi/Makefile b/vendor/github.com/riandyrn/otelchi/Makefile index ec261df89..02625b6d8 100644 --- a/vendor/github.com/riandyrn/otelchi/Makefile +++ b/vendor/github.com/riandyrn/otelchi/Makefile @@ -1,6 +1,6 @@ .PHONY: * -GO_VERSIONS="1.19 1.20 1.21" +GO_VERSIONS="1.21 1.22" # This is the command that will be used to run the tests go-test: diff --git a/vendor/github.com/riandyrn/otelchi/README.md b/vendor/github.com/riandyrn/otelchi/README.md index ba08bb7a5..89ab65076 100644 --- a/vendor/github.com/riandyrn/otelchi/README.md +++ b/vendor/github.com/riandyrn/otelchi/README.md @@ -1,14 +1,14 @@ # otelchi -[![ci](https://github.com/riandyrn/otelchi/actions/workflows/ci.yaml/badge.svg)](https://github.com/riandyrn/otelchi/actions/workflows/ci.yaml) +[![compatibility-test](https://github.com/riandyrn/otelchi/actions/workflows/compatibility-test.yaml/badge.svg)](https://github.com/riandyrn/otelchi/actions/workflows/compatibility-test.yaml) [![Go Report Card](https://goreportcard.com/badge/github.com/riandyrn/otelchi)](https://goreportcard.com/report/github.com/riandyrn/otelchi) [![Documentation](https://godoc.org/github.com/riandyrn/otelchi?status.svg)](https://pkg.go.dev/mod/github.com/riandyrn/otelchi) OpenTelemetry instrumentation for [go-chi/chi](https://github.com/go-chi/chi). -Essentialy this is adaptation from [otelmux](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation/github.com/gorilla/mux/otelmux) but instead using `gorilla/mux`, we use `go-chi/chi`. +Essentially this is an adaptation from [otelmux](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation/github.com/gorilla/mux/otelmux) but instead of using `gorilla/mux`, we use `go-chi/chi`. -Currently it could only instrument traces. +Currently, this library can only instrument traces. Contributions are welcomed! @@ -24,4 +24,4 @@ See [examples](./examples) for details. ## Why Port This? -I was planning to make this project as part of Open Telemetry Go instrumentation project. However based on [this comment](https://github.com/open-telemetry/opentelemetry-go-contrib/pull/986#issuecomment-941280855) they no longer accept new instrumentation. This is why I maintain this project here. \ No newline at end of file +I was planning to make this project as part of the Open Telemetry Go instrumentation project. However, based on [this comment](https://github.com/open-telemetry/opentelemetry-go-contrib/pull/986#issuecomment-941280855) they no longer accept new instrumentation. This is why I maintain this project here. diff --git a/vendor/github.com/riandyrn/otelchi/config.go b/vendor/github.com/riandyrn/otelchi/config.go index 3529268af..1763a28dd 100644 --- a/vendor/github.com/riandyrn/otelchi/config.go +++ b/vendor/github.com/riandyrn/otelchi/config.go @@ -16,7 +16,7 @@ type config struct { Propagators propagation.TextMapPropagator ChiRoutes chi.Routes RequestMethodInSpanName bool - Filter func(r *http.Request) bool + Filters []Filter TraceResponseHeaderKey string PublicEndpointFn func(r *http.Request) bool } @@ -32,6 +32,10 @@ func (o optionFunc) apply(c *config) { o(c) } +// 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 + // WithPropagators specifies propagators to use for extracting // information from the HTTP requests. If none are specified, global // ones will be used. @@ -76,12 +80,15 @@ func WithRequestMethodInSpanName(isActive bool) Option { }) } -// WithFilter is used for filtering request that should not be traced. -// This is useful for filtering health check request, etc. -// A Filter must return true if the request should be traced. -func WithFilter(filter func(r *http.Request) bool) Option { +// WithFilter adds a filter to the list of filters used by the handler. +// If any filter indicates to exclude a request then the request will not be +// traced. All filters must allow a request to be traced for a Span to be created. +// If no filters are provided then all requests are traced. +// Filters will be invoked for each processed request, it is advised to make them +// simple and fast. +func WithFilter(filter Filter) Option { return optionFunc(func(cfg *config) { - cfg.Filter = filter + cfg.Filters = append(cfg.Filters, filter) }) } diff --git a/vendor/github.com/riandyrn/otelchi/middleware.go b/vendor/github.com/riandyrn/otelchi/middleware.go index d6dfda031..4d9cdafbf 100644 --- a/vendor/github.com/riandyrn/otelchi/middleware.go +++ b/vendor/github.com/riandyrn/otelchi/middleware.go @@ -46,7 +46,7 @@ func Middleware(serverName string, opts ...Option) func(next http.Handler) http. handler: handler, chiRoutes: cfg.ChiRoutes, reqMethodInSpanName: cfg.RequestMethodInSpanName, - filter: cfg.Filter, + filters: cfg.Filters, traceResponseHeaderKey: cfg.TraceResponseHeaderKey, publicEndpointFn: cfg.PublicEndpointFn, } @@ -60,7 +60,7 @@ type traceware struct { handler http.Handler chiRoutes chi.Routes reqMethodInSpanName bool - filter func(r *http.Request) bool + filters []Filter traceResponseHeaderKey string publicEndpointFn func(r *http.Request) bool } @@ -111,10 +111,14 @@ func putRRW(rrw *recordingResponseWriter) { // ServeHTTP implements the http.Handler interface. It does the actual // tracing of the request. func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // skip if filter returns false - if tw.filter != nil && !tw.filter(r) { - tw.handler.ServeHTTP(w, r) - return + // go through all filters if any + for _, filter := range tw.filters { + // if there is a filter that returns false, we skip tracing + // and execute next handler + if !filter(r) { + tw.handler.ServeHTTP(w, r) + return + } } // extract tracing header using propagator diff --git a/vendor/github.com/riandyrn/otelchi/version.go b/vendor/github.com/riandyrn/otelchi/version.go index 8d6a5e2f0..c6761f24c 100644 --- a/vendor/github.com/riandyrn/otelchi/version.go +++ b/vendor/github.com/riandyrn/otelchi/version.go @@ -2,5 +2,5 @@ package otelchi // Version is the current release version of otelchi in use. func Version() string { - return "0.8.0" + return "0.9.0" } diff --git a/vendor/modules.txt b/vendor/modules.txt index b2fef3fdd..1adeec353 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1701,8 +1701,8 @@ github.com/r3labs/sse/v2 # github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 ## explicit github.com/rcrowley/go-metrics -# github.com/riandyrn/otelchi v0.8.0 -## explicit; go 1.19 +# github.com/riandyrn/otelchi v0.9.0 +## explicit; go 1.21 github.com/riandyrn/otelchi # github.com/rivo/uniseg v0.4.2 ## explicit; go 1.18