Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNTM-100] Add WithQuery #1

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}
}
Loading