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

[tracing] tracing in OTLP support configuring service_name #6185

Merged
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/tracing/otlp/config_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
10 changes: 7 additions & 3 deletions pkg/tracing/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/tracing/otlp/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down