From c3e93d2cad1e93bf10076f00d93d629b5d76221f Mon Sep 17 00:00:00 2001 From: NeerajNagure <101815703+NeerajNagure@users.noreply.github.com> Date: Fri, 5 Apr 2024 06:50:28 +0530 Subject: [PATCH] Tracing: added missing sampler types (#7231) * added missing sampler types Signed-off-by: Neeraj Nagure * added changelog entry Signed-off-by: Neeraj Nagure * fixed changelog entry Signed-off-by: Neeraj Nagure * Fixed changelog entry conflict Signed-off-by: Neeraj Nagure --------- Signed-off-by: Neeraj Nagure --- CHANGELOG.md | 1 + pkg/tracing/otlp/otlp.go | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f756068d4..445a422f86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Added +- [#7231](https://github.com/thanos-io/thanos/pull/7231) Tracing: added missing sampler types - [#7194](https://github.com/thanos-io/thanos/pull/7194) Downsample: retry objstore related errors - [#7105](https://github.com/thanos-io/thanos/pull/7105) Rule: add flag `--query.enable-x-functions` to allow usage of extended promql functions (xrate, xincrease, xdelta) in loaded rules - [#6867](https://github.com/thanos-io/thanos/pull/6867) Query UI: Tenant input box added to the Query UI, in order to be able to specify which tenant the query should use. diff --git a/pkg/tracing/otlp/otlp.go b/pkg/tracing/otlp/otlp.go index 6843896de2..bf29d3622b 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" + TraceIDRatioBasedSample string = "traceidratiobased" + ParentBasedAlwaysSample string = "parentbasedalwayssample" + ParentBasedNeverSample string = "parentbasedneversample" + ParentBasedTraceIDRatioBasedSample string = "parentbasedtraceidratiobased" ) // NewOTELTracer returns an OTLP exporter based tracer. @@ -106,10 +109,20 @@ 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 + return tracesdk.AlwaysSample(), nil case NeverSample: + return tracesdk.NeverSample(), nil + case TraceIDRatioBasedSample: + arg, err := strconv.ParseFloat(config.SamplerParam, 64) + if err != nil { + return tracesdk.TraceIDRatioBased(1.0), err + } + return tracesdk.TraceIDRatioBased(arg), nil + case ParentBasedAlwaysSample: + return tracesdk.ParentBased(tracesdk.AlwaysSample()), nil + case ParentBasedNeverSample: return tracesdk.ParentBased(tracesdk.NeverSample()), nil - case RatioBasedSample: + case ParentBasedTraceIDRatioBasedSample: arg, err := strconv.ParseFloat(config.SamplerParam, 64) if err != nil { return tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0)), err