File tree 3 files changed +43
-0
lines changed
exporters/otlp/otlpmetric/otlpmetrichttp
3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,16 @@ func newClient(cfg oconf.Config) (*client, error) {
80
80
if cfg .Metrics .Insecure {
81
81
u .Scheme = "http"
82
82
}
83
+
84
+ // Add query parameters to the URL
85
+ if len (cfg .Metrics .QueryParams ) > 0 {
86
+ query := u .Query ()
87
+ for key , value := range cfg .Metrics .QueryParams {
88
+ query .Set (key , value )
89
+ }
90
+ u .RawQuery = query .Encode ()
91
+ }
92
+
83
93
// Body is set when this is cloned during upload.
84
94
req , err := http .NewRequest (http .MethodPost , u .String (), http .NoBody )
85
95
if err != nil {
Original file line number Diff line number Diff line change @@ -222,3 +222,12 @@ func WithAggregationSelector(selector metric.AggregationSelector) Option {
222
222
func WithProxy (pf HTTPTransportProxyFunc ) Option {
223
223
return wrappedOption {oconf .WithProxy (oconf .HTTPTransportProxyFunc (pf ))}
224
224
}
225
+
226
+ // WithQueryParams sets the query parameters to be included in the endpoint URL.
227
+ //
228
+ // If query parameters are provided in the endpoint URL, they will be merged
229
+ // with the parameters set using this function. Parameters set using this
230
+ // function will take precedence in case of conflicts.
231
+ func WithQueryParams (params map [string ]string ) Option {
232
+ return wrappedOption {oconf .WithQueryParams (params )}
233
+ }
Original file line number Diff line number Diff line change 56
56
Compression Compression
57
57
Timeout time.Duration
58
58
URLPath string
59
+ QueryParams map [string ]string // New variable to store query params
59
60
60
61
// gRPC configurations
61
62
GRPCCredentials credentials.TransportCredentials
@@ -290,6 +291,17 @@ func WithEndpointURL(v string) GenericOption {
290
291
cfg .Metrics .URLPath = u .Path
291
292
cfg .Metrics .Insecure = u .Scheme != "https"
292
293
294
+ // Extract and store query parameters
295
+ if u .RawQuery != "" {
296
+ queryParams := make (map [string ]string )
297
+ for key , values := range u .Query () {
298
+ if len (values ) > 0 {
299
+ queryParams [key ] = values [0 ]
300
+ }
301
+ }
302
+ cfg .Metrics .QueryParams = queryParams // New variable to store query params
303
+ }
304
+
293
305
return cfg
294
306
})
295
307
}
@@ -373,3 +385,15 @@ func WithProxy(pf HTTPTransportProxyFunc) GenericOption {
373
385
return cfg
374
386
})
375
387
}
388
+
389
+ func WithQueryParams (params map [string ]string ) HTTPOption {
390
+ return NewHTTPOption (func (cfg Config ) Config {
391
+ if cfg .Metrics .QueryParams == nil {
392
+ cfg .Metrics .QueryParams = make (map [string ]string )
393
+ }
394
+ for key , value := range params {
395
+ cfg .Metrics .QueryParams [key ] = value
396
+ }
397
+ return cfg
398
+ })
399
+ }
You can’t perform that action at this time.
0 commit comments