From 21809eb66f87d9c4159e9e922cd8c8ba6a61f8ee Mon Sep 17 00:00:00 2001 From: martinyonatann Date: Mon, 20 Jan 2025 19:32:14 +0700 Subject: [PATCH 1/5] setup and implementation of a body wrapper in otelmux --- CHANGELOG.md | 21 ++-- .../gorilla/mux/otelmux/example/go.mod | 1 - .../gorilla/mux/otelmux/example/go.sum | 2 - .../github.com/gorilla/mux/otelmux/go.mod | 1 - .../github.com/gorilla/mux/otelmux/go.sum | 2 - .../github.com/gorilla/mux/otelmux/mux.go | 71 +++-------- .../mux/otelmux/request/body_wrapper.go | 75 +++++++++++ .../mux/otelmux/request/body_wrapper_test.go | 74 +++++++++++ .../otelmux/request/resp_writer_wrapper.go | 119 ++++++++++++++++++ .../request/resp_writer_wrapper_test.go | 63 ++++++++++ .../gorilla/mux/otelmux/test/go.mod | 1 - .../gorilla/mux/otelmux/test/go.sum | 2 - 12 files changed, 362 insertions(+), 70 deletions(-) create mode 100644 instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go create mode 100644 instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper_test.go create mode 100644 instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go create mode 100644 instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d24b3e7c350..6a2fb26ee3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added +- Setup & Implementation of a body wrapper in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` #(6650) + +### Added + - Generate server metrics with semantic conventions `v1.26.0` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http/dup`. (#6411) - Generate client metrics with semantic conventions `v1.26.0` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http/dup`. (#6607) @@ -67,7 +71,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Use `baggagecopy.NewLogProcessor` when configuring a Log Provider. - `NewLogProcessor` accepts a `Filter` function type that selects which baggage members are added to the log record. -### Changed +### Changed - Transform raw (`slog.KindAny`) attribute values to matching `log.Value` types. For example, `[]string{"foo", "bar"}` attribute value is now transformed to `log.SliceValue(log.StringValue("foo"), log.StringValue("bar"))` instead of `log.String("[foo bar"])`. (#6254) @@ -311,7 +315,7 @@ The next release will require at least [Go 1.21]. ### Changed -- The fallback options in `go.opentelemetry.io/contrib/exporters/autoexport` now accept factory functions. (#4891) +- The fallback options in `go.opentelemetry.io/contrib/exporters/autoexport` now accept factory functions. (#4891) - `WithFallbackMetricReader(metric.Reader) MetricOption` is replaced with `func WithFallbackMetricReader(func(context.Context) (metric.Reader, error)) MetricOption`. - `WithFallbackSpanExporter(trace.SpanExporter) SpanOption` is replaced with `WithFallbackSpanExporter(func(context.Context) (trace.SpanExporter, error)) SpanOption`. - The `http.server.request_content_length` metric in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is changed to `http.server.request.size`.(#4707) @@ -589,7 +593,7 @@ The next release will require at least [Go 1.19]. ### Changed - Change `runtime.uptime` instrument in `go.opentelemetry.io/contrib/instrumentation/runtime` from `Int64ObservableUpDownCounter` to `Int64ObservableCounter`, - since the value is monotonic. (#3347) + since the value is monotonic. (#3347) - `samplers/jaegerremote`: change to use protobuf parser instead of encoding/json to accept enums as strings. (#3183) ### Fixed @@ -863,7 +867,7 @@ Update dependency on the `go.opentelemetry.io/otel` project to `v1.1.0`. ## [1.0.0/0.25.0] - 2021-10-06 - Resource detectors and propagators (with the exception of `go. - opentelemetry.io/contrib/propagators/opencensus`) are now stable and +opentelemetry.io/contrib/propagators/opencensus`) are now stable and released at v1.0.0. - Update dependency on the `go.opentelemetry.io/otel` project to `v1.0.1`. - Update dependency on `go.opentelemetry.io/otel/metric` to `v0.24.0`. @@ -927,7 +931,7 @@ Update dependency on the `go.opentelemetry.io/otel` project to `v1.1.0`. ### Changed - The `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` instrumentation now accepts a `WithCommandAttributeDisabled`, - so the caller can specify whether to opt-out of tracing the mongo command. (#712) + so the caller can specify whether to opt-out of tracing the mongo command. (#712) - Upgrade to v0.20.0 of `go.opentelemetry.io/otel`. (#758) - The B3 and Jaeger propagators now store their debug or deferred state in the context.Context instead of the SpanContext. (#758) @@ -1022,7 +1026,7 @@ Update dependency on the `go.opentelemetry.io/otel` project to `v1.1.0`. ## Changed - The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` package instrumentation no longer accepts a `Tracer` as an argument to the interceptor function. - Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373) + Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373) - The `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` instrumentation now accepts a `TracerProvider` rather than a `Tracer`. (#374) - Remove `go.opentelemetry.io/otel/sdk` dependency from instrumentation. (#381) - Use `httpsnoop` in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` to ensure `http.ResponseWriter` additional interfaces are preserved. (#388) @@ -1049,7 +1053,7 @@ Update dependency on the `go.opentelemetry.io/otel` project to `v1.1.0`. - Update instrumentation guidelines about uniform provider options. Also, update style guide. (#303) - Make config struct of instrumentation unexported. (#303) - Instrumentations have been updated to adhere to the [configuration style guide's](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config) - updated recommendation to use `newConfig()` instead of `configure()`. (#336) + updated recommendation to use `newConfig()` instead of `configure()`. (#336) - A new instrumentation naming scheme is implemented to avoid package name conflicts for instrumented packages while still remaining discoverable. (#359) - `google.golang.org/grpc` -> `google.golang.org/grpc/otelgrpc` - `go.mongodb.org/mongo-driver` -> `go.mongodb.org/mongo-driver/mongo/otelmongo` @@ -1159,7 +1163,7 @@ This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-tel ### Fixed - Update README to include information about external instrumentation. - To start, this includes native instrumentation found in the `go-redis/redis` package. (#117) + To start, this includes native instrumentation found in the `go-redis/redis` package. (#117) - Bump github.com/golangci/golangci-lint from 1.27.0 to 1.28.2 in /tools. (#122, #123, #125) - Bump go.mongodb.org/mongo-driver from 1.3.4 to 1.3.5 in /instrumentation/go.mongodb.org/mongo-driver. (#124) @@ -1287,5 +1291,4 @@ First official tagged release of `contrib` repository. [Go 1.20]: https://go.dev/doc/go1.20 [Go 1.19]: https://go.dev/doc/go1.19 [Go 1.18]: https://go.dev/doc/go1.18 - [GO-2024-2687]: https://pkg.go.dev/vuln/GO-2024-2687 diff --git a/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod b/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod index adc81dfb759..9ecdd0860d6 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod +++ b/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod @@ -14,7 +14,6 @@ require ( ) require ( - github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum b/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum index e160ea2ce32..27970d787e1 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum +++ b/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum @@ -1,7 +1,5 @@ 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= -github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/instrumentation/github.com/gorilla/mux/otelmux/go.mod b/instrumentation/github.com/gorilla/mux/otelmux/go.mod index bd30f1a7de0..f4f1893e03b 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/go.mod +++ b/instrumentation/github.com/gorilla/mux/otelmux/go.mod @@ -3,7 +3,6 @@ module go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmu go 1.22.0 require ( - github.com/felixge/httpsnoop v1.0.4 github.com/gorilla/mux v1.8.1 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/otel v1.34.0 diff --git a/instrumentation/github.com/gorilla/mux/otelmux/go.sum b/instrumentation/github.com/gorilla/mux/otelmux/go.sum index 15010c081b9..9ab8f6e66f2 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/go.sum +++ b/instrumentation/github.com/gorilla/mux/otelmux/go.sum @@ -1,7 +1,5 @@ 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= -github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/instrumentation/github.com/gorilla/mux/otelmux/mux.go b/instrumentation/github.com/gorilla/mux/otelmux/mux.go index c7b2355eca8..9086a73ca6a 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/mux.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/mux.go @@ -6,12 +6,11 @@ package otelmux // import "go.opentelemetry.io/contrib/instrumentation/github.co import ( "fmt" "net/http" - "sync" - "github.com/felixge/httpsnoop" "github.com/gorilla/mux" "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil" + "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/request" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" semconv "go.opentelemetry.io/otel/semconv/v1.20.0" @@ -70,49 +69,6 @@ type traceware struct { filters []Filter } -type recordingResponseWriter struct { - writer http.ResponseWriter - written bool - status int -} - -var rrwPool = &sync.Pool{ - New: func() interface{} { - return &recordingResponseWriter{} - }, -} - -func getRRW(writer http.ResponseWriter) *recordingResponseWriter { - rrw := rrwPool.Get().(*recordingResponseWriter) - rrw.written = false - rrw.status = http.StatusOK - rrw.writer = httpsnoop.Wrap(writer, httpsnoop.Hooks{ - Write: func(next httpsnoop.WriteFunc) httpsnoop.WriteFunc { - return func(b []byte) (int, error) { - if !rrw.written { - rrw.written = true - } - return next(b) - } - }, - WriteHeader: func(next httpsnoop.WriteHeaderFunc) httpsnoop.WriteHeaderFunc { - return func(statusCode int) { - if !rrw.written { - rrw.written = true - rrw.status = statusCode - } - next(statusCode) - } - }, - }) - return rrw -} - -func putRRW(rrw *recordingResponseWriter) { - rrw.writer = nil - rrwPool.Put(rrw) -} - // defaultSpanNameFunc just reuses the route name as the span name. func defaultSpanNameFunc(routeName string, _ *http.Request) string { return routeName } @@ -163,12 +119,23 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) { spanName := tw.spanNameFormatter(routeStr, r) ctx, span := tw.tracer.Start(ctx, spanName, opts...) defer span.End() - r2 := r.WithContext(ctx) - rrw := getRRW(w) - defer putRRW(rrw) - tw.handler.ServeHTTP(rrw.writer, r2) - if rrw.status > 0 { - span.SetAttributes(semconv.HTTPStatusCode(rrw.status)) + + var readRecordFunc, writeRecordFunc func(int64) + + // if request body is nil or NoBody, we don't want to mutate the body as it + // will affect the identity of it in an unforeseeable way because we assert + // ReadCloser fulfills a certain interface and it is indeed nil or NoBody. + bw := request.NewBodyWrapper(r.Body, readRecordFunc) + if r.Body != nil && r.Body != http.NoBody { + r.Body = bw + } + + rrw := request.NewRespWriterWrapper(w, writeRecordFunc) + + tw.handler.ServeHTTP(w, r.WithContext(ctx)) + statusCode := rrw.StatusCode() + if statusCode > 0 { + span.SetAttributes(semconv.HTTPStatusCode(statusCode)) } - span.SetStatus(semconvutil.HTTPServerStatus(rrw.status)) + span.SetStatus(semconvutil.HTTPServerStatus(statusCode)) } diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go b/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go new file mode 100644 index 00000000000..5842afcdb3f --- /dev/null +++ b/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go @@ -0,0 +1,75 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package request // import "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/request" + +import ( + "io" + "sync" +) + +var _ io.ReadCloser = &BodyWrapper{} + +// BodyWrapper wraps a http.Request.Body (an io.ReadCloser) to track the number +// of bytes read and the last error. +type BodyWrapper struct { + io.ReadCloser + OnRead func(n int64) // must not be nil + + mu sync.Mutex + read int64 + err error +} + +// NewBodyWrapper creates a new BodyWrapper. +// +// The onRead attribute is a callback that will be called every time the data +// is read, with the number of bytes being read. +func NewBodyWrapper(body io.ReadCloser, onRead func(int64)) *BodyWrapper { + return &BodyWrapper{ + ReadCloser: body, + OnRead: onRead, + } +} + +// Read reads the data from the io.ReadCloser, and stores the number of bytes +// read and the error. +func (w *BodyWrapper) Read(b []byte) (int, error) { + n, err := w.ReadCloser.Read(b) + n1 := int64(n) + + w.updateReadData(n1, err) + w.OnRead(n1) + return n, err +} + +func (w *BodyWrapper) updateReadData(n int64, err error) { + w.mu.Lock() + defer w.mu.Unlock() + + w.read += n + if err != nil { + w.err = err + } +} + +// Closes closes the io.ReadCloser. +func (w *BodyWrapper) Close() error { + return w.ReadCloser.Close() +} + +// BytesRead returns the number of bytes read up to this point. +func (w *BodyWrapper) BytesRead() int64 { + w.mu.Lock() + defer w.mu.Unlock() + + return w.read +} + +// Error returns the last error. +func (w *BodyWrapper) Error() error { + w.mu.Lock() + defer w.mu.Unlock() + + return w.err +} diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper_test.go b/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper_test.go new file mode 100644 index 00000000000..794e54fb9c8 --- /dev/null +++ b/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper_test.go @@ -0,0 +1,74 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package request + +import ( + "errors" + "io" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var errFirstCall = errors.New("first call") + +func TestBodyWrapper(t *testing.T) { + bw := NewBodyWrapper(io.NopCloser(strings.NewReader("hello world")), func(int64) {}) + + data, err := io.ReadAll(bw) + require.NoError(t, err) + assert.Equal(t, "hello world", string(data)) + + assert.Equal(t, int64(11), bw.BytesRead()) + assert.Equal(t, io.EOF, bw.Error()) +} + +type multipleErrorsReader struct { + calls int +} + +type errorWrapper struct{} + +func (errorWrapper) Error() string { + return "subsequent calls" +} + +func (mer *multipleErrorsReader) Read([]byte) (int, error) { + mer.calls = mer.calls + 1 + if mer.calls == 1 { + return 0, errFirstCall + } + + return 0, errorWrapper{} +} + +func TestBodyWrapperWithErrors(t *testing.T) { + bw := NewBodyWrapper(io.NopCloser(&multipleErrorsReader{}), func(int64) {}) + + data, err := io.ReadAll(bw) + require.Equal(t, errFirstCall, err) + assert.Equal(t, "", string(data)) + require.Equal(t, errFirstCall, bw.Error()) + + data, err = io.ReadAll(bw) + require.Equal(t, errorWrapper{}, err) + assert.Equal(t, "", string(data)) + require.Equal(t, errorWrapper{}, bw.Error()) +} + +func TestConcurrentBodyWrapper(t *testing.T) { + bw := NewBodyWrapper(io.NopCloser(strings.NewReader("hello world")), func(int64) {}) + + go func() { + _, _ = io.ReadAll(bw) + }() + + assert.NotNil(t, bw.BytesRead()) + assert.Eventually(t, func() bool { + return errors.Is(bw.Error(), io.EOF) + }, time.Second, 10*time.Millisecond) +} diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go b/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go new file mode 100644 index 00000000000..7b552c76d7e --- /dev/null +++ b/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go @@ -0,0 +1,119 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package request // import "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/request" + +import ( + "net/http" + "sync" +) + +var _ http.ResponseWriter = &RespWriterWrapper{} + +// RespWriterWrapper wraps a http.ResponseWriter in order to track the number of +// bytes written, the last error, and to catch the first written statusCode. +// TODO: The wrapped http.ResponseWriter doesn't implement any of the optional +// types (http.Hijacker, http.Pusher, http.CloseNotifier, etc) +// that may be useful when using it in real life situations. +type RespWriterWrapper struct { + http.ResponseWriter + OnWrite func(n int64) // must not be nil + + mu sync.RWMutex + written int64 + statusCode int + err error + wroteHeader bool +} + +// NewRespWriterWrapper creates a new RespWriterWrapper. +// +// The onWrite attribute is a callback that will be called every time the data +// is written, with the number of bytes that were written. +func NewRespWriterWrapper(w http.ResponseWriter, onWrite func(int64)) *RespWriterWrapper { + return &RespWriterWrapper{ + ResponseWriter: w, + OnWrite: onWrite, + statusCode: http.StatusOK, // default status code in case the Handler doesn't write anything + } +} + +// Write writes the bytes array into the [ResponseWriter], and tracks the +// number of bytes written and last error. +func (w *RespWriterWrapper) Write(p []byte) (int, error) { + w.mu.Lock() + defer w.mu.Unlock() + + if !w.wroteHeader { + w.writeHeader(http.StatusOK) + } + + n, err := w.ResponseWriter.Write(p) + n1 := int64(n) + w.OnWrite(n1) + w.written += n1 + w.err = err + return n, err +} + +// WriteHeader persists initial statusCode for span attribution. +// All calls to WriteHeader will be propagated to the underlying ResponseWriter +// and will persist the statusCode from the first call. +// Blocking consecutive calls to WriteHeader alters expected behavior and will +// remove warning logs from net/http where developers will notice incorrect handler implementations. +func (w *RespWriterWrapper) WriteHeader(statusCode int) { + w.mu.Lock() + defer w.mu.Unlock() + + w.writeHeader(statusCode) +} + +// writeHeader persists the status code for span attribution, and propagates +// the call to the underlying ResponseWriter. +// It does not acquire a lock, and therefore assumes that is being handled by a +// parent method. +func (w *RespWriterWrapper) writeHeader(statusCode int) { + if !w.wroteHeader { + w.wroteHeader = true + w.statusCode = statusCode + } + w.ResponseWriter.WriteHeader(statusCode) +} + +// Flush implements [http.Flusher]. +func (w *RespWriterWrapper) Flush() { + w.mu.Lock() + defer w.mu.Unlock() + + if !w.wroteHeader { + w.writeHeader(http.StatusOK) + } + + if f, ok := w.ResponseWriter.(http.Flusher); ok { + f.Flush() + } +} + +// BytesWritten returns the number of bytes written. +func (w *RespWriterWrapper) BytesWritten() int64 { + w.mu.RLock() + defer w.mu.RUnlock() + + return w.written +} + +// BytesWritten returns the HTTP status code that was sent. +func (w *RespWriterWrapper) StatusCode() int { + w.mu.RLock() + defer w.mu.RUnlock() + + return w.statusCode +} + +// Error returns the last error. +func (w *RespWriterWrapper) Error() error { + w.mu.RLock() + defer w.mu.RUnlock() + + return w.err +} diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper_test.go b/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper_test.go new file mode 100644 index 00000000000..21229b4dc69 --- /dev/null +++ b/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper_test.go @@ -0,0 +1,63 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package request + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRespWriterWriteHeader(t *testing.T) { + rw := NewRespWriterWrapper(&httptest.ResponseRecorder{}, func(int64) {}) + + rw.WriteHeader(http.StatusTeapot) + assert.Equal(t, http.StatusTeapot, rw.statusCode) + assert.True(t, rw.wroteHeader) + + rw.WriteHeader(http.StatusGone) + assert.Equal(t, http.StatusTeapot, rw.statusCode) +} + +func TestRespWriterFlush(t *testing.T) { + rw := NewRespWriterWrapper(&httptest.ResponseRecorder{}, func(int64) {}) + + rw.Flush() + assert.Equal(t, http.StatusOK, rw.statusCode) + assert.True(t, rw.wroteHeader) +} + +type nonFlushableResponseWriter struct{} + +func (_ nonFlushableResponseWriter) Header() http.Header { + return http.Header{} +} + +func (_ nonFlushableResponseWriter) Write([]byte) (int, error) { + return 0, nil +} + +func (_ nonFlushableResponseWriter) WriteHeader(int) {} + +func TestRespWriterFlushNoFlusher(t *testing.T) { + rw := NewRespWriterWrapper(nonFlushableResponseWriter{}, func(int64) {}) + + rw.Flush() + assert.Equal(t, http.StatusOK, rw.statusCode) + assert.True(t, rw.wroteHeader) +} + +func TestConcurrentRespWriterWrapper(t *testing.T) { + rw := NewRespWriterWrapper(&httptest.ResponseRecorder{}, func(int64) {}) + + go func() { + _, _ = rw.Write([]byte("hello world")) + }() + + assert.NotNil(t, rw.BytesWritten()) + assert.NotNil(t, rw.StatusCode()) + assert.NoError(t, rw.Error()) +} diff --git a/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod b/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod index b7ba984be47..5fd5944523a 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod +++ b/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod @@ -13,7 +13,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum b/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum index 8d9ce78bc23..bdba61d924d 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum +++ b/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum @@ -1,7 +1,5 @@ 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= -github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= From 141bb08c31ff6c1efc8b8099d792d816389622b0 Mon Sep 17 00:00:00 2001 From: martinyonatann Date: Mon, 20 Jan 2025 20:51:09 +0700 Subject: [PATCH 2/5] skip changelog --- CHANGELOG.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a2fb26ee3c..d24b3e7c350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added -- Setup & Implementation of a body wrapper in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` #(6650) - -### Added - - Generate server metrics with semantic conventions `v1.26.0` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http/dup`. (#6411) - Generate client metrics with semantic conventions `v1.26.0` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` when `OTEL_SEMCONV_STABILITY_OPT_IN` is set to `http/dup`. (#6607) @@ -71,7 +67,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Use `baggagecopy.NewLogProcessor` when configuring a Log Provider. - `NewLogProcessor` accepts a `Filter` function type that selects which baggage members are added to the log record. -### Changed +### Changed - Transform raw (`slog.KindAny`) attribute values to matching `log.Value` types. For example, `[]string{"foo", "bar"}` attribute value is now transformed to `log.SliceValue(log.StringValue("foo"), log.StringValue("bar"))` instead of `log.String("[foo bar"])`. (#6254) @@ -315,7 +311,7 @@ The next release will require at least [Go 1.21]. ### Changed -- The fallback options in `go.opentelemetry.io/contrib/exporters/autoexport` now accept factory functions. (#4891) +- The fallback options in `go.opentelemetry.io/contrib/exporters/autoexport` now accept factory functions. (#4891) - `WithFallbackMetricReader(metric.Reader) MetricOption` is replaced with `func WithFallbackMetricReader(func(context.Context) (metric.Reader, error)) MetricOption`. - `WithFallbackSpanExporter(trace.SpanExporter) SpanOption` is replaced with `WithFallbackSpanExporter(func(context.Context) (trace.SpanExporter, error)) SpanOption`. - The `http.server.request_content_length` metric in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is changed to `http.server.request.size`.(#4707) @@ -593,7 +589,7 @@ The next release will require at least [Go 1.19]. ### Changed - Change `runtime.uptime` instrument in `go.opentelemetry.io/contrib/instrumentation/runtime` from `Int64ObservableUpDownCounter` to `Int64ObservableCounter`, - since the value is monotonic. (#3347) + since the value is monotonic. (#3347) - `samplers/jaegerremote`: change to use protobuf parser instead of encoding/json to accept enums as strings. (#3183) ### Fixed @@ -867,7 +863,7 @@ Update dependency on the `go.opentelemetry.io/otel` project to `v1.1.0`. ## [1.0.0/0.25.0] - 2021-10-06 - Resource detectors and propagators (with the exception of `go. -opentelemetry.io/contrib/propagators/opencensus`) are now stable and + opentelemetry.io/contrib/propagators/opencensus`) are now stable and released at v1.0.0. - Update dependency on the `go.opentelemetry.io/otel` project to `v1.0.1`. - Update dependency on `go.opentelemetry.io/otel/metric` to `v0.24.0`. @@ -931,7 +927,7 @@ opentelemetry.io/contrib/propagators/opencensus`) are now stable and ### Changed - The `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` instrumentation now accepts a `WithCommandAttributeDisabled`, - so the caller can specify whether to opt-out of tracing the mongo command. (#712) + so the caller can specify whether to opt-out of tracing the mongo command. (#712) - Upgrade to v0.20.0 of `go.opentelemetry.io/otel`. (#758) - The B3 and Jaeger propagators now store their debug or deferred state in the context.Context instead of the SpanContext. (#758) @@ -1026,7 +1022,7 @@ opentelemetry.io/contrib/propagators/opencensus`) are now stable and ## Changed - The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` package instrumentation no longer accepts a `Tracer` as an argument to the interceptor function. - Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373) + Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373) - The `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` instrumentation now accepts a `TracerProvider` rather than a `Tracer`. (#374) - Remove `go.opentelemetry.io/otel/sdk` dependency from instrumentation. (#381) - Use `httpsnoop` in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` to ensure `http.ResponseWriter` additional interfaces are preserved. (#388) @@ -1053,7 +1049,7 @@ opentelemetry.io/contrib/propagators/opencensus`) are now stable and - Update instrumentation guidelines about uniform provider options. Also, update style guide. (#303) - Make config struct of instrumentation unexported. (#303) - Instrumentations have been updated to adhere to the [configuration style guide's](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config) - updated recommendation to use `newConfig()` instead of `configure()`. (#336) + updated recommendation to use `newConfig()` instead of `configure()`. (#336) - A new instrumentation naming scheme is implemented to avoid package name conflicts for instrumented packages while still remaining discoverable. (#359) - `google.golang.org/grpc` -> `google.golang.org/grpc/otelgrpc` - `go.mongodb.org/mongo-driver` -> `go.mongodb.org/mongo-driver/mongo/otelmongo` @@ -1163,7 +1159,7 @@ This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-tel ### Fixed - Update README to include information about external instrumentation. - To start, this includes native instrumentation found in the `go-redis/redis` package. (#117) + To start, this includes native instrumentation found in the `go-redis/redis` package. (#117) - Bump github.com/golangci/golangci-lint from 1.27.0 to 1.28.2 in /tools. (#122, #123, #125) - Bump go.mongodb.org/mongo-driver from 1.3.4 to 1.3.5 in /instrumentation/go.mongodb.org/mongo-driver. (#124) @@ -1291,4 +1287,5 @@ First official tagged release of `contrib` repository. [Go 1.20]: https://go.dev/doc/go1.20 [Go 1.19]: https://go.dev/doc/go1.19 [Go 1.18]: https://go.dev/doc/go1.18 + [GO-2024-2687]: https://pkg.go.dev/vuln/GO-2024-2687 From 0c1f634e5a246c3f4e170a065d338dd3d52ec998 Mon Sep 17 00:00:00 2001 From: martinyonatann Date: Mon, 20 Jan 2025 21:22:00 +0700 Subject: [PATCH 3/5] fix: tests --- .../gorilla/mux/otelmux/example/go.mod | 1 + .../gorilla/mux/otelmux/example/go.sum | 2 ++ .../github.com/gorilla/mux/otelmux/go.mod | 1 + .../github.com/gorilla/mux/otelmux/go.sum | 2 ++ .../github.com/gorilla/mux/otelmux/mux.go | 27 ++++++++++++++++--- .../gorilla/mux/otelmux/test/go.mod | 1 + .../gorilla/mux/otelmux/test/go.sum | 2 ++ 7 files changed, 32 insertions(+), 4 deletions(-) diff --git a/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod b/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod index 9ecdd0860d6..adc81dfb759 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod +++ b/instrumentation/github.com/gorilla/mux/otelmux/example/go.mod @@ -14,6 +14,7 @@ require ( ) require ( + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum b/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum index 27970d787e1..e160ea2ce32 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum +++ b/instrumentation/github.com/gorilla/mux/otelmux/example/go.sum @@ -1,5 +1,7 @@ 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/instrumentation/github.com/gorilla/mux/otelmux/go.mod b/instrumentation/github.com/gorilla/mux/otelmux/go.mod index f4f1893e03b..bd30f1a7de0 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/go.mod +++ b/instrumentation/github.com/gorilla/mux/otelmux/go.mod @@ -3,6 +3,7 @@ module go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmu go 1.22.0 require ( + github.com/felixge/httpsnoop v1.0.4 github.com/gorilla/mux v1.8.1 github.com/stretchr/testify v1.10.0 go.opentelemetry.io/otel v1.34.0 diff --git a/instrumentation/github.com/gorilla/mux/otelmux/go.sum b/instrumentation/github.com/gorilla/mux/otelmux/go.sum index 9ab8f6e66f2..15010c081b9 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/go.sum +++ b/instrumentation/github.com/gorilla/mux/otelmux/go.sum @@ -1,5 +1,7 @@ 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/instrumentation/github.com/gorilla/mux/otelmux/mux.go b/instrumentation/github.com/gorilla/mux/otelmux/mux.go index 9086a73ca6a..ca0dc7b484f 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/mux.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/mux.go @@ -7,6 +7,7 @@ import ( "fmt" "net/http" + "github.com/felixge/httpsnoop" "github.com/gorilla/mux" "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil" @@ -120,8 +121,7 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx, span := tw.tracer.Start(ctx, spanName, opts...) defer span.End() - var readRecordFunc, writeRecordFunc func(int64) - + readRecordFunc := func(int64) {} // if request body is nil or NoBody, we don't want to mutate the body as it // will affect the identity of it in an unforeseeable way because we assert // ReadCloser fulfills a certain interface and it is indeed nil or NoBody. @@ -130,10 +130,29 @@ func (tw traceware) ServeHTTP(w http.ResponseWriter, r *http.Request) { r.Body = bw } - rrw := request.NewRespWriterWrapper(w, writeRecordFunc) + writeRecordFunc := func(int64) {} + rww := request.NewRespWriterWrapper(w, writeRecordFunc) + + // Wrap w to use our ResponseWriter methods while also exposing + // other interfaces that w may implement (http.CloseNotifier, + // http.Flusher, http.Hijacker, http.Pusher, io.ReaderFrom). + w = httpsnoop.Wrap(w, httpsnoop.Hooks{ + Header: func(httpsnoop.HeaderFunc) httpsnoop.HeaderFunc { + return rww.Header + }, + Write: func(httpsnoop.WriteFunc) httpsnoop.WriteFunc { + return rww.Write + }, + WriteHeader: func(httpsnoop.WriteHeaderFunc) httpsnoop.WriteHeaderFunc { + return rww.WriteHeader + }, + Flush: func(httpsnoop.FlushFunc) httpsnoop.FlushFunc { + return rww.Flush + }, + }) tw.handler.ServeHTTP(w, r.WithContext(ctx)) - statusCode := rrw.StatusCode() + statusCode := rww.StatusCode() if statusCode > 0 { span.SetAttributes(semconv.HTTPStatusCode(statusCode)) } diff --git a/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod b/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod index 5fd5944523a..b7ba984be47 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod +++ b/instrumentation/github.com/gorilla/mux/otelmux/test/go.mod @@ -13,6 +13,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum b/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum index bdba61d924d..8d9ce78bc23 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum +++ b/instrumentation/github.com/gorilla/mux/otelmux/test/go.sum @@ -1,5 +1,7 @@ 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/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= From 62d7f9ebf375f3d39cf92df71192e0eed6bb5762 Mon Sep 17 00:00:00 2001 From: martinyonatann Date: Tue, 21 Jan 2025 02:54:17 +0700 Subject: [PATCH 4/5] move wrapper into internal --- .../gorilla/mux/otelmux/{ => internal}/request/body_wrapper.go | 2 +- .../mux/otelmux/{ => internal}/request/body_wrapper_test.go | 0 .../mux/otelmux/{ => internal}/request/resp_writer_wrapper.go | 2 +- .../otelmux/{ => internal}/request/resp_writer_wrapper_test.go | 0 instrumentation/github.com/gorilla/mux/otelmux/mux.go | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename instrumentation/github.com/gorilla/mux/otelmux/{ => internal}/request/body_wrapper.go (96%) rename instrumentation/github.com/gorilla/mux/otelmux/{ => internal}/request/body_wrapper_test.go (100%) rename instrumentation/github.com/gorilla/mux/otelmux/{ => internal}/request/resp_writer_wrapper.go (98%) rename instrumentation/github.com/gorilla/mux/otelmux/{ => internal}/request/resp_writer_wrapper_test.go (100%) diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper.go similarity index 96% rename from instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go rename to instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper.go index 5842afcdb3f..afea8c35f3d 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package request // import "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/request" +package request // import "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/request" import ( "io" diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper_test.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper_test.go similarity index 100% rename from instrumentation/github.com/gorilla/mux/otelmux/request/body_wrapper_test.go rename to instrumentation/github.com/gorilla/mux/otelmux/internal/request/body_wrapper_test.go diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper.go similarity index 98% rename from instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go rename to instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper.go index 7b552c76d7e..537465b05b1 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package request // import "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/request" +package request // import "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/request" import ( "net/http" diff --git a/instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper_test.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper_test.go similarity index 100% rename from instrumentation/github.com/gorilla/mux/otelmux/request/resp_writer_wrapper_test.go rename to instrumentation/github.com/gorilla/mux/otelmux/internal/request/resp_writer_wrapper_test.go diff --git a/instrumentation/github.com/gorilla/mux/otelmux/mux.go b/instrumentation/github.com/gorilla/mux/otelmux/mux.go index ca0dc7b484f..8d3830c7f65 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/mux.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/mux.go @@ -11,7 +11,7 @@ import ( "github.com/gorilla/mux" "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil" - "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/request" + "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/request" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" semconv "go.opentelemetry.io/otel/semconv/v1.20.0" From ac6d68aef6517d143d70a8473eb6238c2aac9a40 Mon Sep 17 00:00:00 2001 From: martinyonatann Date: Tue, 21 Jan 2025 16:53:57 +0700 Subject: [PATCH 5/5] fix lint --- instrumentation/github.com/gorilla/mux/otelmux/mux.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/github.com/gorilla/mux/otelmux/mux.go b/instrumentation/github.com/gorilla/mux/otelmux/mux.go index 8d3830c7f65..73087e2f377 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/mux.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/mux.go @@ -10,8 +10,9 @@ import ( "github.com/felixge/httpsnoop" "github.com/gorilla/mux" - "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil" "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/request" + "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux/internal/semconvutil" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" semconv "go.opentelemetry.io/otel/semconv/v1.20.0"