From 6ea8b409df5fb4709b97cbd59b0dac72bfa298ca Mon Sep 17 00:00:00 2001 From: EROMOSELE AKHIGBE Date: Sat, 30 Mar 2024 00:54:40 +0100 Subject: [PATCH 1/4] updated .chloggen folder --- ...confighttp-add-context-to-public-func.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/confighttp-add-context-to-public-func.yaml diff --git a/.chloggen/confighttp-add-context-to-public-func.yaml b/.chloggen/confighttp-add-context-to-public-func.yaml new file mode 100644 index 00000000000..15961a0eb6d --- /dev/null +++ b/.chloggen/confighttp-add-context-to-public-func.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: deprecation + +# 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: Deprecate `ToClient`,`ToListener`and `ToServer` use `ToClientContext`,`ToListenerContext` and `ToServerContext`instead. + +# One or more tracking issues or pull requests related to the change +issues: [9807] + +# (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: [api] \ No newline at end of file From aa17c7c90419c7cdb7f3d1c25d9c6825a8d429a7 Mon Sep 17 00:00:00 2001 From: EROMOSELE AKHIGBE Date: Sat, 30 Mar 2024 00:55:07 +0100 Subject: [PATCH 2/4] Updated func to add context --- config/confighttp/compression_test.go | 3 +- config/confighttp/confighttp.go | 27 ++++++++--- config/confighttp/confighttp_test.go | 67 +++++++++++++++------------ exporter/otlphttpexporter/otlp.go | 2 +- receiver/otlpreceiver/otlp.go | 4 +- 5 files changed, 64 insertions(+), 39 deletions(-) diff --git a/config/confighttp/compression_test.go b/config/confighttp/compression_test.go index 63d9ba02ab9..ea56d07ff66 100644 --- a/config/confighttp/compression_test.go +++ b/config/confighttp/compression_test.go @@ -7,6 +7,7 @@ import ( "bytes" "compress/gzip" "compress/zlib" + "context" "fmt" "io" "net/http" @@ -99,7 +100,7 @@ func TestHTTPClientCompression(t *testing.T) { Endpoint: srv.URL, Compression: tt.encoding, } - client, err := clientSettings.ToClient(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) + client, err := clientSettings.ToClientContext(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) require.NoError(t, err) res, err := client.Do(req) if tt.shouldError { diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 80482513f56..f2c44889e22 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -115,8 +115,13 @@ func NewDefaultClientConfig() ClientConfig { } } -// ToClient creates an HTTP client. -func (hcs *ClientConfig) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) { +// Deprecated: [v0.98.0] Use ToClientContext instead. +func (hcs *ClientConfig) ToClient(_ context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) { + return hcs.ToClientContext(context.Background(), host, settings) +} + +// ToClientContext creates an HTTP client. +func (hcs *ClientConfig) ToClientContext(_ context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) { tlsCfg, err := hcs.TLSSetting.LoadTLSConfigContext(context.Background()) if err != nil { return nil, err @@ -277,8 +282,13 @@ type ServerConfig struct { ResponseHeaders map[string]configopaque.String `mapstructure:"response_headers"` } -// ToListener creates a net.Listener. -func (hss *ServerConfig) ToListener() (net.Listener, error) { +// Deprecated: [v0.98.0] Use ToListenerContext instead. +func (hss *ServerConfig) ToListener(_ context.Context) (net.Listener, error) { + return hss.ToListenerContext(context.Background()) +} + +// ToListenerContext creates a net.Listener. +func (hss *ServerConfig) ToListenerContext(_ context.Context) (net.Listener, error) { listener, err := net.Listen("tcp", hss.Endpoint) if err != nil { return nil, err @@ -327,8 +337,13 @@ func WithDecoder(key string, dec func(body io.ReadCloser) (io.ReadCloser, error) } } -// ToServer creates an http.Server from settings object. -func (hss *ServerConfig) ToServer(host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { +// Deprecated: [v0.98.0] Use ToServerContext instead. +func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { + return hss.ToServerContext(context.Background(), host, settings, handler, opts...) +} + +// ToServerContext creates an http.Server from settings object. +func (hss *ServerConfig) ToServerContext(_ context.Context, host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { internal.WarnOnUnspecifiedHost(settings.Logger, hss.Endpoint) serverOpts := &toServerOptions{} diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index c49a6c80d8a..375fb4e7840 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -169,7 +169,7 @@ func TestAllHTTPClientSettings(t *testing.T) { t.Run(test.name, func(t *testing.T) { tt := componenttest.NewNopTelemetrySettings() tt.TracerProvider = nil - client, err := test.settings.ToClient(host, tt) + client, err := test.settings.ToClientContext(context.Background(), host, tt) if test.shouldError { assert.Error(t, err) return @@ -222,7 +222,7 @@ func TestPartialHTTPClientSettings(t *testing.T) { t.Run(test.name, func(t *testing.T) { tt := componenttest.NewNopTelemetrySettings() tt.TracerProvider = nil - client, err := test.settings.ToClient(host, tt) + client, err := test.settings.ToClientContext(context.Background(), host, tt) assert.NoError(t, err) transport := client.Transport.(*http.Transport) assert.EqualValues(t, 1024, transport.ReadBufferSize) @@ -272,7 +272,7 @@ func TestProxyURL(t *testing.T) { tt := componenttest.NewNopTelemetrySettings() tt.TracerProvider = nil - client, err := s.ToClient(componenttest.NewNopHost(), tt) + client, err := s.ToClientContext(context.Background(), componenttest.NewNopHost(), tt) if tC.err { require.Error(t, err) @@ -342,7 +342,7 @@ func TestHTTPClientSettingsError(t *testing.T) { } for _, test := range tests { t.Run(test.err, func(t *testing.T) { - _, err := test.settings.ToClient(host, componenttest.NewNopTelemetrySettings()) + _, err := test.settings.ToClientContext(context.Background(), host, componenttest.NewNopTelemetrySettings()) assert.Regexp(t, test.err, err) }) } @@ -451,7 +451,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { // Omit TracerProvider and MeterProvider in TelemetrySettings as otelhttp.Transport cannot be introspected - client, err := test.settings.ToClient(test.host, component.TelemetrySettings{Logger: zap.NewNop(), MetricsLevel: configtelemetry.LevelNone}) + client, err := test.settings.ToClientContext(context.Background(), test.host, component.TelemetrySettings{Logger: zap.NewNop(), MetricsLevel: configtelemetry.LevelNone}) if test.shouldErr { assert.Error(t, err) return @@ -523,7 +523,7 @@ func TestHTTPServerSettingsError(t *testing.T) { } for _, test := range tests { t.Run(test.err, func(t *testing.T) { - _, err := test.settings.ToListener() + _, err := test.settings.ToListener(context.Background()) assert.Regexp(t, test.err, err) }) } @@ -554,7 +554,8 @@ func TestHTTPServerWarning(t *testing.T) { logger, observed := observer.New(zap.DebugLevel) set.Logger = zap.New(logger) - _, err := test.settings.ToServer( + _, err := test.settings.ToServerContext( + context.Background(), componenttest.NewNopHost(), set, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -697,10 +698,11 @@ func TestHttpReception(t *testing.T) { Endpoint: "localhost:0", TLSSetting: tt.tlsServerCreds, } - ln, err := hss.ToListener() + ln, err := hss.ToListenerContext(context.Background()) require.NoError(t, err) - s, err := hss.ToServer( + s, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -731,7 +733,7 @@ func TestHttpReception(t *testing.T) { return rt, nil } } - client, errClient := hcs.ToClient(componenttest.NewNopHost(), component.TelemetrySettings{}) + client, errClient := hcs.ToClientContext(context.Background(), componenttest.NewNopHost(), component.TelemetrySettings{}) require.NoError(t, errClient) resp, errResp := client.Get(hcs.Endpoint) @@ -810,10 +812,11 @@ func TestHttpCors(t *testing.T) { CORS: tt.CORSConfig, } - ln, err := hss.ToListener() + ln, err := hss.ToListenerContext(context.Background()) require.NoError(t, err) - s, err := hss.ToServer( + s, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -853,7 +856,8 @@ func TestHttpCorsInvalidSettings(t *testing.T) { } // This effectively does not enable CORS but should also not cause an error - s, err := hss.ToServer( + s, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) @@ -883,7 +887,7 @@ func TestHttpCorsWithSettings(t *testing.T) { }, } - srv, err := hss.ToServer(host, componenttest.NewNopTelemetrySettings(), nil) + srv, err := hss.ToServerContext(context.Background(), host, componenttest.NewNopTelemetrySettings(), nil) require.NoError(t, err) require.NotNil(t, srv) @@ -926,10 +930,11 @@ func TestHttpServerHeaders(t *testing.T) { ResponseHeaders: tt.headers, } - ln, err := hss.ToListener() + ln, err := hss.ToListenerContext(context.Background()) require.NoError(t, err) - s, err := hss.ToServer( + s, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -1012,7 +1017,8 @@ func ExampleServerConfig() { settings := ServerConfig{ Endpoint: "localhost:443", } - s, err := settings.ToServer( + s, err := settings.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) @@ -1020,7 +1026,7 @@ func ExampleServerConfig() { panic(err) } - l, err := settings.ToListener() + l, err := settings.ToListenerContext(context.Background()) if err != nil { panic(err) } @@ -1059,7 +1065,7 @@ func TestHttpClientHeaders(t *testing.T) { Timeout: 0, Headers: tt.headers, } - client, _ := setting.ToClient(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) + client, _ := setting.ToClientContext(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) req, err := http.NewRequest(http.MethodGet, setting.Endpoint, nil) assert.NoError(t, err) _, err = client.Do(req) @@ -1095,7 +1101,7 @@ func TestHttpClientHostHeader(t *testing.T) { Timeout: 0, Headers: tt.headers, } - client, _ := setting.ToClient(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) + client, _ := setting.ToClientContext(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) req, err := http.NewRequest(http.MethodGet, setting.Endpoint, nil) assert.NoError(t, err) _, err = client.Do(req) @@ -1190,7 +1196,7 @@ func TestServerAuth(t *testing.T) { handlerCalled = true }) - srv, err := hss.ToServer(host, componenttest.NewNopTelemetrySettings(), handler) + srv, err := hss.ToServerContext(context.Background(), host, componenttest.NewNopTelemetrySettings(), handler) require.NoError(t, err) // test @@ -1208,7 +1214,7 @@ func TestInvalidServerAuth(t *testing.T) { }, } - srv, err := hss.ToServer(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.NewServeMux()) + srv, err := hss.ToServerContext(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.NewServeMux()) require.Error(t, err) require.Nil(t, srv) } @@ -1231,7 +1237,7 @@ func TestFailedServerAuth(t *testing.T) { }, } - srv, err := hss.ToServer(host, componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) + srv, err := hss.ToServerContext(context.Background(), host, componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) require.NoError(t, err) // test @@ -1254,7 +1260,8 @@ func TestServerWithErrorHandler(t *testing.T) { http.Error(w, "invalid request", http.StatusInternalServerError) } - srv, err := hss.ToServer( + srv, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}), @@ -1282,7 +1289,8 @@ func TestServerWithDecoder(t *testing.T) { return body, nil } - srv, err := hss.ToServer( + srv, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}), @@ -1358,7 +1366,8 @@ func BenchmarkHttpRequest(b *testing.B) { TLSSetting: tlsServerCreds, } - s, err := hss.ToServer( + s, err := hss.ToServerContext( + context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -1366,7 +1375,7 @@ func BenchmarkHttpRequest(b *testing.B) { require.NoError(b, errWrite) })) require.NoError(b, err) - ln, err := hss.ToListener() + ln, err := hss.ToListenerContext(context.Background()) require.NoError(b, err) go func() { @@ -1390,12 +1399,12 @@ func BenchmarkHttpRequest(b *testing.B) { b.Run(bb.name, func(b *testing.B) { var c *http.Client if !bb.clientPerThread { - c, err = hcs.ToClient(componenttest.NewNopHost(), component.TelemetrySettings{}) + c, err = hcs.ToClientContext(context.Background(), componenttest.NewNopHost(), component.TelemetrySettings{}) require.NoError(b, err) } b.RunParallel(func(pb *testing.PB) { if c == nil { - c, err = hcs.ToClient(componenttest.NewNopHost(), component.TelemetrySettings{}) + c, err = hcs.ToClientContext(context.Background(), componenttest.NewNopHost(), component.TelemetrySettings{}) require.NoError(b, err) } for pb.Next() { diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 8a8d428121b..20c2ff905bc 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -78,7 +78,7 @@ func newExporter(cfg component.Config, set exporter.CreateSettings) (*baseExport // start actually creates the HTTP client. The client construction is deferred till this point as this // is the only place we get hold of Extensions which are required to construct auth round tripper. func (e *baseExporter) start(_ context.Context, host component.Host) error { - client, err := e.config.ClientConfig.ToClient(host, e.settings) + client, err := e.config.ClientConfig.ToClientContext(context.Background(), host, e.settings) if err != nil { return err } diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 91936bfb6a5..06725de5a96 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -145,13 +145,13 @@ func (r *otlpReceiver) startHTTPServer(host component.Host) error { } var err error - if r.serverHTTP, err = r.cfg.HTTP.ToServer(host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil { + if r.serverHTTP, err = r.cfg.HTTP.ToServerContext(context.Background(), host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil { return err } r.settings.Logger.Info("Starting HTTP server", zap.String("endpoint", r.cfg.HTTP.ServerConfig.Endpoint)) var hln net.Listener - if hln, err = r.cfg.HTTP.ServerConfig.ToListener(); err != nil { + if hln, err = r.cfg.HTTP.ServerConfig.ToListenerContext(context.Background()); err != nil { return err } From 096b7e61d5c130a221363762d2377937cb00b7ff Mon Sep 17 00:00:00 2001 From: EROMOSELE AKHIGBE Date: Sat, 30 Mar 2024 03:08:50 +0100 Subject: [PATCH 3/4] updated funcs --- config/confighttp/confighttp.go | 6 +++--- config/confighttp/confighttp_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index f2c44889e22..919f94b3feb 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -116,7 +116,7 @@ func NewDefaultClientConfig() ClientConfig { } // Deprecated: [v0.98.0] Use ToClientContext instead. -func (hcs *ClientConfig) ToClient(_ context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) { +func (hcs *ClientConfig) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) { return hcs.ToClientContext(context.Background(), host, settings) } @@ -283,7 +283,7 @@ type ServerConfig struct { } // Deprecated: [v0.98.0] Use ToListenerContext instead. -func (hss *ServerConfig) ToListener(_ context.Context) (net.Listener, error) { +func (hss *ServerConfig) ToListener() (net.Listener, error) { return hss.ToListenerContext(context.Background()) } @@ -338,7 +338,7 @@ func WithDecoder(key string, dec func(body io.ReadCloser) (io.ReadCloser, error) } // Deprecated: [v0.98.0] Use ToServerContext instead. -func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { +func (hss *ServerConfig) ToServer(host component.Host, settings component.TelemetrySettings, handler http.Handler, opts ...ToServerOption) (*http.Server, error) { return hss.ToServerContext(context.Background(), host, settings, handler, opts...) } diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 375fb4e7840..3c96c58583d 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -523,7 +523,7 @@ func TestHTTPServerSettingsError(t *testing.T) { } for _, test := range tests { t.Run(test.err, func(t *testing.T) { - _, err := test.settings.ToListener(context.Background()) + _, err := test.settings.ToListenerContext(context.Background()) assert.Regexp(t, test.err, err) }) } From fa1e3951b004ce24c0fb91ce02c61e3e93572a7b Mon Sep 17 00:00:00 2001 From: EROMOSELE AKHIGBE Date: Thu, 4 Apr 2024 02:08:01 +0100 Subject: [PATCH 4/4] Added ctx to the funcs --- config/confighttp/confighttp.go | 8 ++++---- exporter/otlphttpexporter/otlp.go | 4 ++-- receiver/otlpreceiver/otlp.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 919f94b3feb..985c4f9be7a 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -121,8 +121,8 @@ func (hcs *ClientConfig) ToClient(host component.Host, settings component.Teleme } // ToClientContext creates an HTTP client. -func (hcs *ClientConfig) ToClientContext(_ context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) { - tlsCfg, err := hcs.TLSSetting.LoadTLSConfigContext(context.Background()) +func (hcs *ClientConfig) ToClientContext(ctx context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) { + tlsCfg, err := hcs.TLSSetting.LoadTLSConfigContext(ctx) if err != nil { return nil, err } @@ -288,7 +288,7 @@ func (hss *ServerConfig) ToListener() (net.Listener, error) { } // ToListenerContext creates a net.Listener. -func (hss *ServerConfig) ToListenerContext(_ context.Context) (net.Listener, error) { +func (hss *ServerConfig) ToListenerContext(ctx context.Context) (net.Listener, error) { listener, err := net.Listen("tcp", hss.Endpoint) if err != nil { return nil, err @@ -296,7 +296,7 @@ func (hss *ServerConfig) ToListenerContext(_ context.Context) (net.Listener, err if hss.TLSSetting != nil { var tlsCfg *tls.Config - tlsCfg, err = hss.TLSSetting.LoadTLSConfigContext(context.Background()) + tlsCfg, err = hss.TLSSetting.LoadTLSConfigContext(ctx) if err != nil { return nil, err } diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 20c2ff905bc..f8e746bb570 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -77,8 +77,8 @@ func newExporter(cfg component.Config, set exporter.CreateSettings) (*baseExport // start actually creates the HTTP client. The client construction is deferred till this point as this // is the only place we get hold of Extensions which are required to construct auth round tripper. -func (e *baseExporter) start(_ context.Context, host component.Host) error { - client, err := e.config.ClientConfig.ToClientContext(context.Background(), host, e.settings) +func (e *baseExporter) start(ctx context.Context, host component.Host) error { + client, err := e.config.ClientConfig.ToClientContext(ctx, host, e.settings) if err != nil { return err } diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 4702b2307e0..7a10bc90a96 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -116,7 +116,7 @@ func (r *otlpReceiver) startGRPCServer(host component.Host) error { return nil } -func (r *otlpReceiver) startHTTPServer(host component.Host) error { +func (r *otlpReceiver) startHTTPServer(ctx context.Context, host component.Host) error { // If HTTP is not enabled, nothing to start. if r.cfg.HTTP == nil { return nil @@ -145,13 +145,13 @@ func (r *otlpReceiver) startHTTPServer(host component.Host) error { } var err error - if r.serverHTTP, err = r.cfg.HTTP.ToServerContext(context.Background(), host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil { + if r.serverHTTP, err = r.cfg.HTTP.ToServerContext(ctx, host, r.settings.TelemetrySettings, httpMux, confighttp.WithErrorHandler(errorHandler)); err != nil { return err } r.settings.Logger.Info("Starting HTTP server", zap.String("endpoint", r.cfg.HTTP.ServerConfig.Endpoint)) var hln net.Listener - if hln, err = r.cfg.HTTP.ServerConfig.ToListenerContext(context.Background()); err != nil { + if hln, err = r.cfg.HTTP.ServerConfig.ToListenerContext(ctx); err != nil { return err } @@ -172,7 +172,7 @@ func (r *otlpReceiver) Start(ctx context.Context, host component.Host) error { if err := r.startGRPCServer(host); err != nil { return err } - if err := r.startHTTPServer(host); err != nil { + if err := r.startHTTPServer(ctx, host); err != nil { // It's possible that a valid GRPC server configuration was specified, // but an invalid HTTP configuration. If that's the case, the successfully // started GRPC server must be shutdown to ensure no goroutines are leaked.