Skip to content

Commit

Permalink
migrate ExperimentalTracerOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Omer Aplatony <[email protected]>
  • Loading branch information
omerap12 committed Jan 10, 2025
1 parent d502e91 commit 8954c09
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
9 changes: 7 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ type ServerConfig struct {

EnableGRPCGateway bool

// ExperimentalEnableDistributedTracing enables distributed tracing using OpenTelemetry protocol.
ExperimentalEnableDistributedTracing bool
// ExperimentalTracerOptions are options for OpenTelemetry gRPC interceptor.
// Deprecated in v3.6 and will be decommissioned in v3.7.
// TODO: remove in v3.7
ExperimentalTracerOptions []otelgrpc.Option

TracerOptions []otelgrpc.Option

WatchProgressNotifyInterval time.Duration

// UnsafeNoFsync disables all uses of fsync.
Expand Down Expand Up @@ -211,6 +213,9 @@ type ServerConfig struct {

// ServerFeatureGate is a server level feature gate
ServerFeatureGate featuregate.FeatureGate

// EnableDistributedTracing enables distributed tracing using OpenTelemetry protocol.
EnableDistributedTracing bool `json:"enable-distributed-tracing"`
}

// VerifyBootstrap sanity-checks the initial config for bootstrap case
Expand Down
16 changes: 8 additions & 8 deletions server/embed/config_tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ type tracingExporter struct {
func newTracingExporter(ctx context.Context, cfg *Config) (*tracingExporter, error) {
exporter, err := otlptracegrpc.New(ctx,
otlptracegrpc.WithInsecure(),
otlptracegrpc.WithEndpoint(cfg.ExperimentalDistributedTracingAddress),
otlptracegrpc.WithEndpoint(cfg.DistributedTracingAddress),

Check warning on line 52 in server/embed/config_tracing.go

View check run for this annotation

Codecov / codecov/patch

server/embed/config_tracing.go#L52

Added line #L52 was not covered by tests
)
if err != nil {
return nil, err
}

res, err := resource.New(ctx,
resource.WithAttributes(
semconv.ServiceNameKey.String(cfg.ExperimentalDistributedTracingServiceName),
semconv.ServiceNameKey.String(cfg.DistributedTracingServiceName),

Check warning on line 60 in server/embed/config_tracing.go

View check run for this annotation

Codecov / codecov/patch

server/embed/config_tracing.go#L60

Added line #L60 was not covered by tests
),
)
if err != nil {
return nil, err
}

if resWithIDKey := determineResourceWithIDKey(cfg.ExperimentalDistributedTracingServiceInstanceID); resWithIDKey != nil {
if resWithIDKey := determineResourceWithIDKey(cfg.DistributedTracingServiceInstanceID); resWithIDKey != nil {

Check warning on line 67 in server/embed/config_tracing.go

View check run for this annotation

Codecov / codecov/patch

server/embed/config_tracing.go#L67

Added line #L67 was not covered by tests
// Merge resources into a new
// resource in case of duplicates.
res, err = resource.Merge(res, resWithIDKey)
Expand All @@ -77,7 +77,7 @@ func newTracingExporter(ctx context.Context, cfg *Config) (*tracingExporter, err
tracesdk.WithBatcher(exporter),
tracesdk.WithResource(res),
tracesdk.WithSampler(
tracesdk.ParentBased(determineSampler(cfg.ExperimentalDistributedTracingSamplingRatePerMillion)),
tracesdk.ParentBased(determineSampler(cfg.DistributedTracingSamplingRatePerMillion)),

Check warning on line 80 in server/embed/config_tracing.go

View check run for this annotation

Codecov / codecov/patch

server/embed/config_tracing.go#L80

Added line #L80 was not covered by tests
),
)

Expand All @@ -95,10 +95,10 @@ func newTracingExporter(ctx context.Context, cfg *Config) (*tracingExporter, err

cfg.logger.Debug(
"distributed tracing enabled",
zap.String("address", cfg.ExperimentalDistributedTracingAddress),
zap.String("service-name", cfg.ExperimentalDistributedTracingServiceName),
zap.String("service-instance-id", cfg.ExperimentalDistributedTracingServiceInstanceID),
zap.Int("sampling-rate", cfg.ExperimentalDistributedTracingSamplingRatePerMillion),
zap.String("address", cfg.DistributedTracingAddress),
zap.String("service-name", cfg.DistributedTracingServiceName),
zap.String("service-instance-id", cfg.DistributedTracingServiceInstanceID),
zap.Int("sampling-rate", cfg.DistributedTracingSamplingRatePerMillion),

Check warning on line 101 in server/embed/config_tracing.go

View check run for this annotation

Codecov / codecov/patch

server/embed/config_tracing.go#L98-L101

Added lines #L98 - L101 were not covered by tests
)

return &tracingExporter{
Expand Down
6 changes: 3 additions & 3 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
Logger: cfg.logger,
ForceNewCluster: cfg.ForceNewCluster,
EnableGRPCGateway: cfg.EnableGRPCGateway,
ExperimentalEnableDistributedTracing: cfg.ExperimentalEnableDistributedTracing,
EnableDistributedTracing: cfg.EnableDistributedTracing,
UnsafeNoFsync: cfg.UnsafeNoFsync,
EnableLeaseCheckpoint: cfg.ExperimentalEnableLeaseCheckpoint,
LeaseCheckpointPersist: cfg.ExperimentalEnableLeaseCheckpointPersist,
Expand All @@ -228,7 +228,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
ServerFeatureGate: cfg.ServerFeatureGate,
}

if srvcfg.ExperimentalEnableDistributedTracing {
if srvcfg.EnableDistributedTracing {
tctx := context.Background()
tracingExporter, terr := newTracingExporter(tctx, cfg)
if terr != nil {
Expand All @@ -237,7 +237,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
e.tracingExporterShutdown = func() {
tracingExporter.Close(tctx)
}
srvcfg.ExperimentalTracerOptions = tracingExporter.opts
srvcfg.TracerOptions = tracingExporter.opts

e.cfg.logger.Info(
"distributed tracing setup enabled",
Expand Down
6 changes: 3 additions & 3 deletions server/etcdserver/api/v3rpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, interceptor grpc.UnarySer
grpc_prometheus.StreamServerInterceptor,
}

if s.Cfg.ExperimentalEnableDistributedTracing {
chainUnaryInterceptors = append(chainUnaryInterceptors, otelgrpc.UnaryServerInterceptor(s.Cfg.ExperimentalTracerOptions...))
chainStreamInterceptors = append(chainStreamInterceptors, otelgrpc.StreamServerInterceptor(s.Cfg.ExperimentalTracerOptions...))
if s.Cfg.EnableDistributedTracing {
chainUnaryInterceptors = append(chainUnaryInterceptors, otelgrpc.UnaryServerInterceptor(s.Cfg.TracerOptions...))
chainStreamInterceptors = append(chainStreamInterceptors, otelgrpc.StreamServerInterceptor(s.Cfg.TracerOptions...))

Check warning on line 58 in server/etcdserver/api/v3rpc/grpc.go

View check run for this annotation

Codecov / codecov/patch

server/etcdserver/api/v3rpc/grpc.go#L57-L58

Added lines #L57 - L58 were not covered by tests
}

opts = append(opts, grpc.ChainUnaryInterceptor(chainUnaryInterceptors...))
Expand Down

0 comments on commit 8954c09

Please sign in to comment.