diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ed9ee86e4..afe7825f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Added +- [#6185](https://github.com/thanos-io/thanos/pull/6185) Tracing: tracing in OTLP support configuring service_name. + ### Fixed - [#6172](https://github.com/thanos-io/thanos/pull/6172) query-frontend: return JSON formatted errors for invalid PromQL expression in the split by interval middleware. diff --git a/docs/tracing.md b/docs/tracing.md index 430570d72f..b0405945cd 100644 --- a/docs/tracing.md +++ b/docs/tracing.md @@ -78,6 +78,7 @@ Thanos supports exporting traces in the OpenTelemetry Protocol (OTLP). Both gRPC type: OTLP config: client_type: "" + service_name: "" reconnection_period: 0s compression: "" insecure: false diff --git a/pkg/tracing/otlp/config_yaml.go b/pkg/tracing/otlp/config_yaml.go index ed471612f0..caa9ceb5ba 100644 --- a/pkg/tracing/otlp/config_yaml.go +++ b/pkg/tracing/otlp/config_yaml.go @@ -21,6 +21,7 @@ type retryConfig struct { type Config struct { ClientType string `yaml:"client_type"` + ServiceName string `yaml:"service_name"` ReconnectionPeriod time.Duration `yaml:"reconnection_period"` Compression string `yaml:"compression"` Insecure bool `yaml:"insecure"` diff --git a/pkg/tracing/otlp/otlp.go b/pkg/tracing/otlp/otlp.go index 58c27f2bdd..7f0890a790 100644 --- a/pkg/tracing/otlp/otlp.go +++ b/pkg/tracing/otlp/otlp.go @@ -17,6 +17,7 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/sdk/resource" tracesdk "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.7.0" _ "google.golang.org/grpc/encoding/gzip" "gopkg.in/yaml.v2" ) @@ -58,13 +59,16 @@ func NewTracerProvider(ctx context.Context, logger log.Logger, conf []byte) (*tr } processor := tracesdk.NewBatchSpanProcessor(exporter) - tp := newTraceProvider(ctx, processor, logger) + tp := newTraceProvider(ctx, processor, logger, config.ServiceName) return tp, nil } -func newTraceProvider(ctx context.Context, processor tracesdk.SpanProcessor, logger log.Logger) *tracesdk.TracerProvider { - resource, err := resource.New(ctx) +func newTraceProvider(ctx context.Context, processor tracesdk.SpanProcessor, logger log.Logger, serviceName string) *tracesdk.TracerProvider { + resource, err := resource.New( + ctx, + resource.WithAttributes(semconv.ServiceNameKey.String(serviceName)), + ) if err != nil { level.Warn(logger).Log("msg", "jaeger: detecting resources for tracing provider failed", "err", err) } diff --git a/pkg/tracing/otlp/otlp_test.go b/pkg/tracing/otlp/otlp_test.go index 46108876da..979942d85b 100644 --- a/pkg/tracing/otlp/otlp_test.go +++ b/pkg/tracing/otlp/otlp_test.go @@ -23,7 +23,8 @@ func TestContextTracing_ClientEnablesTracing(t *testing.T) { tracerOtel := newTraceProvider( context.Background(), tracesdk.NewSimpleSpanProcessor(exp), - log.NewNopLogger()) + log.NewNopLogger(), + "thanos") tracer, _ := migration.Bridge(tracerOtel, log.NewNopLogger()) clientRoot, _ := tracing.StartSpan(tracing.ContextWithTracer(context.Background(), tracer), "a")