diff --git a/CHANGELOG.md b/CHANGELOG.md index 11745d8b35..a0da39da95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/tracing.md b/docs/tracing.md index e87a1fa0f3..0e2676f987 100644 --- a/docs/tracing.md +++ b/docs/tracing.md @@ -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). diff --git a/pkg/tracing/otlp/otlp.go b/pkg/tracing/otlp/otlp.go index 6843896de2..8de1cdcbd8 100644 --- a/pkg/tracing/otlp/otlp.go +++ b/pkg/tracing/otlp/otlp.go @@ -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. @@ -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) @@ -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