Skip to content

redisotel: Missing server.address from sentinel traces #3301

Open
@AndrewWinterman

Description

@AndrewWinterman

We are using sentinel for high availability.

I'm in process of writing a library to support switchover from legacy deployments which do not use sentinel, and I noticed the server.address is missing from the sentinel spans:

Image

Initialization of the tracer looks as follows:

	failoverOptions := &redis.FailoverOptions{
		SentinelAddrs:    []string{cfg.SentinelAddr},
		ClientName:       app.Info().PodID,
		DB:               cfg.DBNumber,
		Password:         string(cfg.Password),
		SentinelPassword: string(cfg.Password),

		// Base number of socket connections.
		// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
		// If there is not enough connections in the pool, new connections will be allocated in excess of PoolSize,
		// you can limit it through MaxActiveConns
		PoolSize: cfg.PoolSize,
		// Minimum number of idle connections which is useful when establishing
		// new connection is slow.
		// Default is 0. the idle connections are not closed by default.
		MinIdleConns: cfg.MinIdleConns,
		// Maximum number of idle connections.
		// Default is 0. the idle connections are not closed by default.
		MaxIdleConns: cfg.MaxIdleConns,
		// Maximum number of connections allocated by the pool at a given time.
		// When zero, there is no limit on the number of connections in the pool.
		MaxActiveConns: cfg.MaxActiveConns,

		// there are additional idle
		ReplicaOnly:           role == RedisReplicaRoleReader,
		MasterName:            cfg.LeaderName,
		ContextTimeoutEnabled: true,

		// <<Stencil::Block(failoverOptions)>>

		// <</Stencil::Block>>
	}

	redis.SetLogger(&redisLogger{})

	var client redis.UniversalClient

	switch role {
	case RedisReplicaRoleReader:
		failoverOptions.RouteByLatency = cfg.RouteReadsByLatency
		client = redis.NewFailoverClusterClient(failoverOptions)
	case RedisReplicaRoleWriter:
		client = redis.NewFailoverClient(failoverOptions)
	default:
		return nil, fmt.Errorf("unknown RedisReplicaRole: %v", role)
	}

	ping := client.Ping(ctx)
	if ping.Err() != nil {
		return nil, errors.Wrapf(ping.Err(), "failed to contact Redis Sentinel at %q", cfg.SentinelAddr)
	}

	if err := redisotel.InstrumentTracing(client); err != nil {
		return nil, errors.Wrap(err, "failed to instrument Redis tracing")
	}
	if err := redisotel.InstrumentMetrics(client); err != nil {
		return nil, errors.Wrap(err, "failed to instrument Redis tracing")
	}
	return client, nil

Related:

Cause is because of this line here:

https://github.com/redis/go-redis/blob/master/sentinel.go#L90

It uses "FailoverClient" instead of any real address.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions