From cff8392708ba56ac2f005bafcce158fc31ee1cef Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Fri, 20 Sep 2024 20:03:31 +0530 Subject: [PATCH 01/14] chore: add an option to add span prefix, changelog, tests --- .chloggen/add-new-server-option.yaml | 25 ++++++++ config/confighttp/confighttp.go | 17 +++-- config/confighttp/confighttp_test.go | 92 ++++++++++++++++++++++++++++ receiver/otlpreceiver/otlp.go | 2 +- 4 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 .chloggen/add-new-server-option.yaml diff --git a/.chloggen/add-new-server-option.yaml b/.chloggen/add-new-server-option.yaml new file mode 100644 index 00000000000..189201f9366 --- /dev/null +++ b/.chloggen/add-new-server-option.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: confighttp + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add an option to add prefix for span name for receivers + +# One or more tracking issues or pull requests related to the change +issues: [] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 4c38d3015a7..a68a026be66 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -13,6 +13,7 @@ import ( "net/http" "net/http/cookiejar" "net/url" + "strings" "time" "github.com/rs/cors" @@ -377,6 +378,7 @@ func (hss *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) { type toServerOptions struct { errHandler func(w http.ResponseWriter, r *http.Request, errorMsg string, statusCode int) decoders map[string]func(body io.ReadCloser) (io.ReadCloser, error) + spanPrefix string } // ToServerOption is an option to change the behavior of the HTTP server @@ -410,6 +412,14 @@ func WithDecoder(key string, dec func(body io.ReadCloser) (io.ReadCloser, error) }) } +// WithSpanPrefix creates a span prefixed with the specified name. +// Ideally, this prefix should be the component's ID. +func WithSpanPrefix(spanPrefix string) ToServerOption { + return toServerOptionFunc(func(opts *toServerOptions) { + opts.spanPrefix = spanPrefix + }) +} + // ToServer creates an http.Server from settings object. func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { internal.WarnOnUnspecifiedHost(settings.Logger, hss.Endpoint) @@ -462,15 +472,14 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin otelOpts := []otelhttp.Option{ otelhttp.WithTracerProvider(settings.TracerProvider), otelhttp.WithPropagators(otel.GetTextMapPropagator()), - otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string { - return r.URL.Path + otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string { + return strings.TrimPrefix(fmt.Sprintf("%s:%s", operation, r.URL.Path), ":") }), otelhttp.WithMeterProvider(settings.LeveledMeterProvider(configtelemetry.LevelDetailed)), } // Enable OpenTelemetry observability plugin. - // TODO: Consider to use component ID string as prefix for all the operations. - handler = otelhttp.NewHandler(handler, "", otelOpts...) + handler = otelhttp.NewHandler(handler, serverOpts.spanPrefix, otelOpts...) // wrap the current handler in an interceptor that will add client.Info to the request's context handler = &clientInfoHandler{ diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index aaaef2bb501..a50796a4ff7 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -21,6 +21,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/metric" + "go.opentelemetry.io/otel/trace" + "go.opentelemetry.io/otel/trace/embedded" + "go.opentelemetry.io/otel/trace/noop" "go.uber.org/zap" "go.uber.org/zap/zaptest/observer" @@ -1543,3 +1546,92 @@ func TestDefaultHTTPServerSettings(t *testing.T) { assert.Equal(t, time.Duration(0), httpServerSettings.ReadTimeout) assert.Equal(t, 1*time.Minute, httpServerSettings.ReadHeaderTimeout) } + +// TracerProvider is an OpenTelemetry No-Op TracerProvider. +type TracerProvider struct { + embedded.TracerProvider + ch chan string +} + +// NewTracerProvider returns a TracerProvider that does not record any telemetry. +func NewTracerProvider(ch chan string) TracerProvider { + return TracerProvider{ch: ch} +} + +// Tracer returns an OpenTelemetry Tracer that does not record any telemetry. +func (t TracerProvider) Tracer(string, ...trace.TracerOption) trace.Tracer { + return Tracer{ch: t.ch} +} + +// Tracer is an OpenTelemetry No-Op Tracer. +type Tracer struct { + embedded.Tracer + ch chan string +} + +type Span struct { + noop.Span + name string +} + +func (t Tracer) Start(ctx context.Context, name string, _ ...trace.SpanStartOption) (context.Context, trace.Span) { + t.ch <- name + return context.TODO(), Span{name: name} +} + +func TestOperationPrefix(t *testing.T) { + tests := []struct { + name string + prefix string + expectedSpanName string + }{ + { + name: "componentID prefix", + prefix: "otlphttpreceiver", + expectedSpanName: "otlphttpreceiver:/", + }, + { + name: "empty prefix", + prefix: "", + expectedSpanName: "/", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + nameChan := make(chan string, 1) + set := componenttest.NewNopTelemetrySettings() + set.TracerProvider = TracerProvider{ch: nameChan} + logger, _ := observer.New(zap.DebugLevel) + set.Logger = zap.New(logger) + setting := &ServerConfig{ + Endpoint: "localhost:0", + } + + ln, err := setting.ToListener(context.Background()) + require.NoError(t, err) + s, err := setting.ToServer( + context.Background(), + componenttest.NewNopHost(), + set, + http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + }), + WithSpanPrefix(tt.prefix), + ) + require.NoError(t, err) + go func() { + _ = s.Serve(ln) + }() + url := fmt.Sprintf("http://%s", ln.Addr().String()) + status, err := http.Get(url) + require.NoError(t, err) + require.Equal(t, status.StatusCode, http.StatusOK) + require.NoError(t, s.Close()) + + spanName := <-nameChan + require.Equal(t, tt.expectedSpanName, spanName) + require.False(t, strings.HasPrefix(spanName, ":")) + }) + } + +} diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 82218ef88db..1254f3a4a1f 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -162,7 +162,7 @@ func (r *otlpReceiver) startHTTPServer(ctx context.Context, host component.Host) } var err error - if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil { + if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler), confighttp.WithSpanPrefix(r.settings.ID.String())); err != nil { return err } From ce61bb54ac0b72dc8bc1d125af6be54d5cb8a665 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Fri, 20 Sep 2024 20:04:40 +0530 Subject: [PATCH 02/14] changelog --- .chloggen/add-new-server-option.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/add-new-server-option.yaml b/.chloggen/add-new-server-option.yaml index 189201f9366..f1b9c640674 100644 --- a/.chloggen/add-new-server-option.yaml +++ b/.chloggen/add-new-server-option.yaml @@ -10,7 +10,7 @@ component: confighttp note: Add an option to add prefix for span name for receivers # One or more tracking issues or pull requests related to the change -issues: [] +issues: [9382] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. From c871eaf09a2c0faa274a5bbeab3bc4c14322990b Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Fri, 20 Sep 2024 20:10:11 +0530 Subject: [PATCH 03/14] reword changelog --- .chloggen/add-new-server-option.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/add-new-server-option.yaml b/.chloggen/add-new-server-option.yaml index f1b9c640674..7b1e066a8e4 100644 --- a/.chloggen/add-new-server-option.yaml +++ b/.chloggen/add-new-server-option.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: confighttp # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Add an option to add prefix for span name for receivers +note: Add an option to add prefix for span name for components # One or more tracking issues or pull requests related to the change issues: [9382] From 06d33613d2a8263b22a9c212d1885ee8e4b4ccc6 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Thu, 26 Sep 2024 23:59:36 +0530 Subject: [PATCH 04/14] go.mod --- config/confighttp/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/confighttp/go.mod b/config/confighttp/go.mod index 8cfbc955d97..40ac61fae23 100644 --- a/config/confighttp/go.mod +++ b/config/confighttp/go.mod @@ -21,6 +21,7 @@ require ( go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 go.opentelemetry.io/otel v1.30.0 go.opentelemetry.io/otel/metric v1.30.0 + go.opentelemetry.io/otel/trace v1.30.0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 golang.org/x/net v0.29.0 @@ -40,7 +41,6 @@ require ( go.opentelemetry.io/collector/pdata v1.15.0 // indirect go.opentelemetry.io/otel/sdk v1.30.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect - go.opentelemetry.io/otel/trace v1.30.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.18.0 // indirect From f2641b81f8f396bc621305a3b4c46c048a6dc76c Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Fri, 27 Sep 2024 00:02:01 +0530 Subject: [PATCH 05/14] fix tests --- config/confighttp/confighttp_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index a50796a4ff7..955e44cd081 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -1576,7 +1576,7 @@ type Span struct { func (t Tracer) Start(ctx context.Context, name string, _ ...trace.SpanStartOption) (context.Context, trace.Span) { t.ch <- name - return context.TODO(), Span{name: name} + return ctx, Span{name: name} } func TestOperationPrefix(t *testing.T) { @@ -1622,10 +1622,10 @@ func TestOperationPrefix(t *testing.T) { go func() { _ = s.Serve(ln) }() - url := fmt.Sprintf("http://%s", ln.Addr().String()) - status, err := http.Get(url) + uri := fmt.Sprintf("http://%s", ln.Addr().String()) + status, err := http.Get(uri) require.NoError(t, err) - require.Equal(t, status.StatusCode, http.StatusOK) + require.Equal(t, http.StatusOK, status.StatusCode) require.NoError(t, s.Close()) spanName := <-nameChan From e4b5fb7892833acaf32a234eff106386c51acf75 Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:58:01 +0530 Subject: [PATCH 06/14] Update config/confighttp/confighttp.go Co-authored-by: Andrzej Stencel --- config/confighttp/confighttp.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index a68a026be66..4d37339a306 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -473,7 +473,10 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin otelhttp.WithTracerProvider(settings.TracerProvider), otelhttp.WithPropagators(otel.GetTextMapPropagator()), otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string { - return strings.TrimPrefix(fmt.Sprintf("%s:%s", operation, r.URL.Path), ":") + if len(operation) > 0 { + return fmt.Sprintf("%s:%s", operation, r.URL.Path) + } + return r.URL.Path }), otelhttp.WithMeterProvider(settings.LeveledMeterProvider(configtelemetry.LevelDetailed)), } From 9171bb70ec2e80c46ec5ab6f32c108209fb24611 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Fri, 27 Sep 2024 16:06:20 +0530 Subject: [PATCH 07/14] fix: imports --- config/confighttp/confighttp.go | 1 - 1 file changed, 1 deletion(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 4d37339a306..402011511e3 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -13,7 +13,6 @@ import ( "net/http" "net/http/cookiejar" "net/url" - "strings" "time" "github.com/rs/cors" From dffbad7c5ce1101a09c7bc5d6f4632bc53a8e176 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Sat, 28 Sep 2024 01:32:54 +0530 Subject: [PATCH 08/14] fix: lint --- config/confighttp/confighttp_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 486719bb375..054ec14d5be 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -1613,8 +1613,7 @@ func TestOperationPrefix(t *testing.T) { go func() { _ = s.Serve(ln) }() - uri := fmt.Sprintf("http://%s", ln.Addr().String()) - status, err := http.Get(uri) + status, err := http.Get(fmt.Sprintf("http://%s", ln.Addr().String())) require.NoError(t, err) require.Equal(t, http.StatusOK, status.StatusCode) require.NoError(t, s.Close()) From e6ab7d537a5782836cce4917ebc1d39ccfdbd050 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Sat, 12 Oct 2024 03:17:04 +0530 Subject: [PATCH 09/14] chore: make it more generic --- config/confighttp/confighttp.go | 34 +++++++++++++++++----------- config/confighttp/confighttp_test.go | 2 +- receiver/otlpreceiver/otlp.go | 5 +++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 402011511e3..48578c36935 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -372,12 +372,14 @@ func (hss *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) { return listener, nil } +type spanFormatterFunc func(string, *http.Request) string + // toServerOptions has options that change the behavior of the HTTP server // returned by ServerConfig.ToServer(). type toServerOptions struct { errHandler func(w http.ResponseWriter, r *http.Request, errorMsg string, statusCode int) decoders map[string]func(body io.ReadCloser) (io.ReadCloser, error) - spanPrefix string + formater func(string, *http.Request) string } // ToServerOption is an option to change the behavior of the HTTP server @@ -411,11 +413,11 @@ func WithDecoder(key string, dec func(body io.ReadCloser) (io.ReadCloser, error) }) } -// WithSpanPrefix creates a span prefixed with the specified name. -// Ideally, this prefix should be the component's ID. -func WithSpanPrefix(spanPrefix string) ToServerOption { +// WithSpanFormatter specifies which formater to use for span. +// Ideally, this prefix in span name should be the component's ID. +func WithSpanFormatter(formater spanFormatterFunc) ToServerOption { return toServerOptionFunc(func(opts *toServerOptions) { - opts.spanPrefix = spanPrefix + opts.formater = formater }) } @@ -423,7 +425,9 @@ func WithSpanPrefix(spanPrefix string) ToServerOption { func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { internal.WarnOnUnspecifiedHost(settings.Logger, hss.Endpoint) - serverOpts := &toServerOptions{} + serverOpts := &toServerOptions{ + formater: PrefixFormatter(""), // use empty-prefix formater by default + } for _, o := range opts { o.apply(serverOpts) } @@ -471,17 +475,12 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin otelOpts := []otelhttp.Option{ otelhttp.WithTracerProvider(settings.TracerProvider), otelhttp.WithPropagators(otel.GetTextMapPropagator()), - otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string { - if len(operation) > 0 { - return fmt.Sprintf("%s:%s", operation, r.URL.Path) - } - return r.URL.Path - }), + otelhttp.WithSpanNameFormatter(serverOpts.formater), otelhttp.WithMeterProvider(settings.LeveledMeterProvider(configtelemetry.LevelDetailed)), } // Enable OpenTelemetry observability plugin. - handler = otelhttp.NewHandler(handler, serverOpts.spanPrefix, otelOpts...) + handler = otelhttp.NewHandler(handler, "", otelOpts...) // wrap the current handler in an interceptor that will add client.Info to the request's context handler = &clientInfoHandler{ @@ -564,3 +563,12 @@ func maxRequestBodySizeInterceptor(next http.Handler, maxRecvSize int64) http.Ha next.ServeHTTP(w, r) }) } + +func PrefixFormatter(prefix string) spanFormatterFunc { + return func(s string, r *http.Request) string { + if len(prefix) > 0 { + return fmt.Sprintf("%s:%s", prefix, r.URL.Path) + } + return r.URL.Path + } +} diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 054ec14d5be..cb154651f18 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -1607,7 +1607,7 @@ func TestOperationPrefix(t *testing.T) { http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) }), - WithSpanPrefix(tt.prefix), + WithSpanFormatter(PrefixFormatter(tt.prefix)), ) require.NoError(t, err) go func() { diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 7bcb01fa208..b289f287f4f 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -162,7 +162,10 @@ func (r *otlpReceiver) startHTTPServer(ctx context.Context, host component.Host) } var err error - if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler), confighttp.WithSpanPrefix(r.settings.ID.String())); err != nil { + if r.serverHTTP, err = r.cfg.HTTP.ToServer(ctx, host, r.settings.TelemetrySettings, httpMux, + confighttp.WithErrorHandler(errorHandler), + confighttp.WithSpanFormatter(confighttp.PrefixFormatter(r.settings.ID.String())), + ); err != nil { return err } From 4fe1105e903654366da3e5c3be5be7c0f5885376 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 15 Oct 2024 19:45:59 +0530 Subject: [PATCH 10/14] go.mod --- config/confighttp/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/confighttp/go.mod b/config/confighttp/go.mod index c90e12b9958..72371da8abb 100644 --- a/config/confighttp/go.mod +++ b/config/confighttp/go.mod @@ -20,6 +20,7 @@ require ( go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 go.opentelemetry.io/otel v1.31.0 go.opentelemetry.io/otel/metric v1.31.0 + go.opentelemetry.io/otel/trace v1.31.0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 golang.org/x/net v0.30.0 @@ -38,7 +39,6 @@ require ( go.opentelemetry.io/collector/pdata v1.17.0 // indirect go.opentelemetry.io/otel/sdk v1.31.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect - go.opentelemetry.io/otel/trace v1.31.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 // indirect From 43d9d0d9a2b57c5cc31c23874ad4cc642b263420 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 22 Oct 2024 02:04:38 +0530 Subject: [PATCH 11/14] chore: lint --- config/confighttp/confighttp.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 53a2e5763c9..8dd6c2b8319 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -372,8 +372,6 @@ func (hss *ServerConfig) ToListener(ctx context.Context) (net.Listener, error) { return listener, nil } -type spanFormatterFunc func(string, *http.Request) string - // toServerOptions has options that change the behavior of the HTTP server // returned by ServerConfig.ToServer(). type toServerOptions struct { @@ -415,7 +413,7 @@ func WithDecoder(key string, dec func(body io.ReadCloser) (io.ReadCloser, error) // WithSpanFormatter specifies which formater to use for span. // Ideally, this prefix in span name should be the component's ID. -func WithSpanFormatter(formater spanFormatterFunc) ToServerOption { +func WithSpanFormatter(formater func(string, *http.Request) string) ToServerOption { return toServerOptionFunc(func(opts *toServerOptions) { opts.formater = formater }) @@ -564,8 +562,8 @@ func maxRequestBodySizeInterceptor(next http.Handler, maxRecvSize int64) http.Ha }) } -func PrefixFormatter(prefix string) spanFormatterFunc { - return func(s string, r *http.Request) string { +func PrefixFormatter(prefix string) func(string, *http.Request) string { + return func(_ string, r *http.Request) string { if len(prefix) > 0 { return fmt.Sprintf("%s:%s", prefix, r.URL.Path) } From e2d4dcab01fd07f97f6748555f724af665e4a9f7 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Wed, 20 Nov 2024 18:53:40 +0530 Subject: [PATCH 12/14] fix syntax --- config/confighttp/confighttp.go | 1 + 1 file changed, 1 insertion(+) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 74ef426c3a3..961c9300c14 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -571,6 +571,7 @@ func PrefixFormatter(prefix string) func(string, *http.Request) string { } return r.URL.Path } +} func getLeveledMeterProvider(settings component.TelemetrySettings) metric.MeterProvider { if configtelemetry.LevelDetailed <= settings.MetricsLevel { From d1e307878dbaadb637f91ad6b0bec67e5b56b78e Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Wed, 20 Nov 2024 18:58:11 +0530 Subject: [PATCH 13/14] go tidy --- config/confighttp/confighttp_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 5c1973e5b36..369c4df4683 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/embedded" "go.opentelemetry.io/otel/trace/noop" From 2deac0e5bd3a5d8670652e804f1a0e3daef92c24 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Wed, 20 Nov 2024 19:15:16 +0530 Subject: [PATCH 14/14] lint --- config/confighttp/confighttp_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 369c4df4683..54a2ce46b3a 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -1609,7 +1609,7 @@ func TestOperationPrefix(t *testing.T) { go func() { _ = s.Serve(ln) }() - status, err := http.Get(fmt.Sprintf("http://%s", ln.Addr().String())) + status, err := http.Get("http://" + ln.Addr().String()) require.NoError(t, err) require.Equal(t, http.StatusOK, status.StatusCode) require.NoError(t, s.Close()) @@ -1619,5 +1619,4 @@ func TestOperationPrefix(t *testing.T) { require.False(t, strings.HasPrefix(spanName, ":")) }) } - }