Skip to content

Commit c20a107

Browse files
committed
move instrumentation from request executor to client factory
1 parent 2db95f6 commit c20a107

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

http/client/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
// Check the [TransportOptions] struct for details..
4545
func InstrumentedHTTPClient(c *http.Client, t *TransportOptions, clientName string,
4646
getState state.GetterFn,
47-
) (*http.Client, error) {
47+
) *http.Client {
4848
// the default options is to have everything activated
4949
// TODO: we might want to return the provided client if no transport options are provided ?
5050
// TODO: we might want to return an error if no transport options are provided ?
@@ -77,5 +77,5 @@ func InstrumentedHTTPClient(c *http.Client, t *TransportOptions, clientName stri
7777
Jar: c.Jar,
7878
Timeout: c.Timeout,
7979
}
80-
return wc, nil
80+
return wc
8181
}

lura/backend.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,25 @@ func HTTPRequestExecutorFromConfig(clientFactory transport.HTTPClientFactory,
3838
cfg *config.Backend, opts *otelconfig.BackendOpts, skipPaths []string,
3939
getState otelstate.GetterFn,
4040
) transport.HTTPRequestExecutor {
41+
42+
cf := InstrumentedHTTPClientFactory(clientFactory, cfg, opts, skipPaths, getState)
43+
return transport.DefaultHTTPRequestExecutor(cf)
44+
}
45+
46+
func InstrumentedHTTPClientFactory(clientFactory transport.HTTPClientFactory,
47+
cfg *config.Backend, opts *otelconfig.BackendOpts, skipPaths []string,
48+
getState otelstate.GetterFn,
49+
) transport.HTTPClientFactory {
50+
4151
for _, sp := range skipPaths {
4252
if cfg.ParentEndpoint == sp {
43-
// TODO: check if there might be some othe executor that is
44-
// not the default one ?
45-
return transport.DefaultHTTPRequestExecutor(clientFactory)
53+
return clientFactory
4654
}
4755
}
4856

4957
if !opts.Enabled() {
5058
// no configuration for the backend, then .. no metrics nor tracing:
51-
return transport.DefaultHTTPRequestExecutor(clientFactory)
59+
return clientFactory
5260
}
5361

5462
if opts == nil {
@@ -106,11 +114,9 @@ func HTTPRequestExecutorFromConfig(clientFactory transport.HTTPClientFactory,
106114
},
107115
}
108116

109-
return func(ctx context.Context, req *http.Request) (*http.Response, error) {
110-
c, err := clienthttp.InstrumentedHTTPClient(clientFactory(ctx), &t, clientName, getState)
111-
if err != nil {
112-
return nil, err
113-
}
114-
return c.Do(req.WithContext(ctx))
117+
return func(ctx context.Context) *http.Client {
118+
// TODO: this can be optimized, because inside InstrumentedHTTPClient we
119+
// are creating a RoundTripper that could be "prebuilt" and reused
120+
return clienthttp.InstrumentedHTTPClient(clientFactory(ctx), &t, clientName, getState)
115121
}
116122
}

0 commit comments

Comments
 (0)