Skip to content

Commit

Permalink
[RNTM-100] Add WithQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
lior-govrin committed Apr 3, 2024
1 parent 60666c5 commit b666c1a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (d *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.Resourc
}

func (d *client) newRequest(body []byte) (request, error) {
u := url.URL{Scheme: d.getScheme(), Host: d.cfg.Endpoint, Path: d.cfg.URLPath}
u := url.URL{Scheme: d.getScheme(), Host: d.cfg.Endpoint, Path: d.cfg.URLPath, RawQuery: d.getRawQuery()}
r, err := http.NewRequest(http.MethodPost, u.String(), nil)
if err != nil {
return request{Request: r}, err
Expand Down Expand Up @@ -339,3 +339,12 @@ func (d *client) contextWithStop(ctx context.Context) (context.Context, context.
}(ctx, cancel)
return ctx, cancel
}

func (d *client) getRawQuery() string {
values := url.Values{}
for k, v := range d.cfg.Query {
values[k] = v
}

return values.Encode()
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type (
Compression Compression
Timeout time.Duration
URLPath string
Query map[string][]string

// gRPC configurations
GRPCCredentials credentials.TransportCredentials
Expand Down Expand Up @@ -326,3 +327,10 @@ func WithTimeout(duration time.Duration) GenericOption {
return cfg
})
}

func WithQuery(query map[string][]string) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Query = query
return cfg
})
}
5 changes: 5 additions & 0 deletions exporters/otlp/otlptrace/otlptracehttp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ func WithTimeout(duration time.Duration) Option {
func WithRetry(rc RetryConfig) Option {
return wrappedOption{otlpconfig.WithRetry(retry.Config(rc))}
}

// WithQuery allows one to tell the driver to send query values with the payloads.
func WithQuery(query map[string][]string) Option {
return wrappedOption{otlpconfig.WithQuery(query)}
}

0 comments on commit b666c1a

Please sign in to comment.