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

Support query params for traces url #5152

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `otel.scope.name` and `otel.scope.version` tags to spans exported by `go.opentelemetry.io/otel/exporters/zipkin`. (#5108)
- Add support for `AddLink` to `go.opentelemetry.io/otel/bridge/opencensus`. (#5116)
- Add `String` method to `Value` and `KeyValue` in `go.opentelemetry.io/otel/log`. (#5117)
- Add `Query` option in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5152)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Compression Compression
Timeout time.Duration
URLPath string
Query map[string][]string

// gRPC configurations
GRPCCredentials credentials.TransportCredentials
Expand Down Expand Up @@ -346,3 +347,10 @@
return cfg
})
}

func WithQuery(query map[string][]string) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Query = query
return cfg
})

Check warning on line 355 in exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go#L351-L355

Added lines #L351 - L355 were not covered by tests
}
5 changes: 5 additions & 0 deletions exporters/otlp/otlptrace/otlptracegrpc/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,8 @@
func WithRetry(settings RetryConfig) Option {
return wrappedOption{otlpconfig.WithRetry(retry.Config(settings))}
}

// WithQuery will send the provided query values with each gRPC request.
func WithQuery(query map[string][]string) Option {
return wrappedOption{otlpconfig.WithQuery(query)}

Check warning on line 206 in exporters/otlp/otlptrace/otlptracegrpc/options.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlptrace/otlptracegrpc/options.go#L205-L206

Added lines #L205 - L206 were not covered by tests
}
11 changes: 10 additions & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
}

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 @@ -346,3 +346,12 @@
}(ctx, cancel)
return ctx, cancel
}

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

Check warning on line 353 in exporters/otlp/otlptrace/otlptracehttp/client.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlptrace/otlptracehttp/client.go#L353

Added line #L353 was not covered by tests
}

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

// gRPC configurations
GRPCCredentials credentials.TransportCredentials
Expand Down Expand Up @@ -346,3 +347,10 @@ func WithProxy(pf HTTPTransportProxyFunc) GenericOption {
return cfg
})
}

func WithQuery(query map[string][]string) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Query = query
return cfg
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,17 @@ func TestConfigs(t *testing.T) {
assert.Nil(t, c.Traces.Proxy)
},
},

// Query tests
{
name: "Test With Query",
opts: []GenericOption{
WithQuery(map[string][]string{"queryKey": {"queryVal"}}),
},
asserts: func(t *testing.T, c *Config, grpcOption bool) {
assert.Equal(t, map[string][]string{"queryKey": {"queryVal"}}, c.Traces.Query)
},
},
}

for _, tt := range tests {
Expand Down
8 changes: 8 additions & 0 deletions internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type (
Compression Compression
Timeout time.Duration
URLPath string
Query map[string][]string

// gRPC configurations
GRPCCredentials credentials.TransportCredentials
Expand Down Expand Up @@ -346,3 +347,10 @@ func WithProxy(pf HTTPTransportProxyFunc) GenericOption {
return cfg
})
}

func WithQuery(query map[string][]string) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Query = query
return cfg
})
}
Loading