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

Separated the sampler options into parent based and non-parent based #6711

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -22,6 +22,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#6530](https://github.com/thanos-io/thanos/pull/6530) / [#6690](https://github.com/thanos-io/thanos/pull/6690) Query: Add command line arguments for configuring tenants and forward tenant information to Store Gateway.
- [#6765](https://github.com/thanos-io/thanos/pull/6765) Index Cache: Add `enabled_items` to index cache config to selectively cache configured items. Available item types are `Postings`, `Series` and `ExpandedPostings`.
- [#6773](https://github.com/thanos-io/thanos/pull/6773) Index Cache: Add `ttl` to control the ttl to store items in remote index caches like memcached and redis.
- [#6711](https://github.com/thanos-io/thanos/pull/6711) Tracing: Add possibility to configure the parent and non-parent sampler for OTLP exporter.

### Changed

Expand Down
10 changes: 10 additions & 0 deletions docs/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ config:
sampler_param: ""
```

*Note:* The `sampler_type` in the configuration above can have one of the following values:
- `alwayssample`
- `neversample`
- `traceidratiobased`
- `parentbasedalwayssample`
- `parentbasedneversample`
- `parentbasedtraceidratiobased`

If the `sampler_type` is set to either `traceidratiobased` or `parentbasedtraceidratiobased`, then the `sampler_param` in the above configuration can be configured in the range `[0.0,1.0]`, when not provided the rate will be set to `1.0`.

### Jaeger

Client for https://github.com/jaegertracing/jaeger tracing. Options can be provided also via environment variables. For more details see the Jaeger [exporter specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#jaeger-exporter).
Expand Down
36 changes: 24 additions & 12 deletions pkg/tracing/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import (
)

const (
TracingClientGRPC string = "grpc"
TracingClientHTTP string = "http"
AlwaysSample string = "alwayssample"
NeverSample string = "neversample"
RatioBasedSample string = "traceidratiobased"
tracingClientGRPC string = "grpc"
tracingClientHTTP string = "http"
alwaysSample string = "alwayssample"
neverSample string = "neversample"
ratioBasedSample string = "traceidratiobased"
parentBasedAlwaysSample string = "parentbasedalwayssample"
parentBasedNeverSample string = "parentbasedneversample"
parentBasedRatioBasedSample string = "parentbasedtraceidratiobased"
)

// NewOTELTracer returns an OTLP exporter based tracer.
Expand All @@ -41,16 +44,15 @@ func NewTracerProvider(ctx context.Context, logger log.Logger, conf []byte) (*tr
var exporter *otlptrace.Exporter
var err error
switch strings.ToLower(config.ClientType) {
case TracingClientHTTP:
case tracingClientHTTP:
options := traceHTTPOptions(config)

client := otlptracehttp.NewClient(options...)
exporter, err = otlptrace.New(ctx, client)
if err != nil {
return nil, err
}

case TracingClientGRPC:
case tracingClientGRPC:
options := traceGRPCOptions(config)
client := otlptracegrpc.NewClient(options...)
exporter, err = otlptrace.New(ctx, client)
Expand Down Expand Up @@ -105,11 +107,21 @@ func newTraceProvider(ctx context.Context, processor tracesdk.SpanProcessor, log

func getSampler(config Config) (tracesdk.Sampler, error) {
switch strings.ToLower(config.SamplerType) {
case AlwaysSample:
return tracesdk.ParentBased(tracesdk.AlwaysSample()), nil
case NeverSample:
case alwaysSample:
return tracesdk.AlwaysSample(), nil
case neverSample:
return tracesdk.NeverSample(), nil
case ratioBasedSample:
arg, err := strconv.ParseFloat(config.SamplerParam, 64)
if err != nil {
return tracesdk.TraceIDRatioBased(1.0), err
}
return tracesdk.TraceIDRatioBased(arg), nil
case parentBasedNeverSample:
return tracesdk.ParentBased(tracesdk.NeverSample()), nil
case RatioBasedSample:
case parentBasedAlwaysSample:
return tracesdk.ParentBased(tracesdk.AlwaysSample()), nil
case parentBasedRatioBasedSample:
arg, err := strconv.ParseFloat(config.SamplerParam, 64)
if err != nil {
return tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0)), err
Expand Down
Loading