@@ -38,17 +38,25 @@ func HTTPRequestExecutorFromConfig(clientFactory transport.HTTPClientFactory,
38
38
cfg * config.Backend , opts * otelconfig.BackendOpts , skipPaths []string ,
39
39
getState otelstate.GetterFn ,
40
40
) 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
+
41
51
for _ , sp := range skipPaths {
42
52
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
46
54
}
47
55
}
48
56
49
57
if ! opts .Enabled () {
50
58
// no configuration for the backend, then .. no metrics nor tracing:
51
- return transport . DefaultHTTPRequestExecutor ( clientFactory )
59
+ return clientFactory
52
60
}
53
61
54
62
if opts == nil {
@@ -106,11 +114,9 @@ func HTTPRequestExecutorFromConfig(clientFactory transport.HTTPClientFactory,
106
114
},
107
115
}
108
116
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 )
115
121
}
116
122
}
0 commit comments