You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +02:00
allow otlp clients to use existing grpc connection (#2002)
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Adds `otlptracegrpc.WithGRPCConn` and `otlpmetricgrpc.WithGRPCConn` for reusing existing gRPC connection. (#2002)
|
||||||
|
|
||||||
## [1.0.1] - 2021-10-01
|
## [1.0.1] - 2021-10-01
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -220,6 +220,10 @@ func (c *Connection) setConnection(cc *grpc.ClientConn) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) {
|
func (c *Connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) {
|
||||||
|
if c.cfg.GRPCConn != nil {
|
||||||
|
return c.cfg.GRPCConn, nil
|
||||||
|
}
|
||||||
|
|
||||||
dialOpts := []grpc.DialOption{}
|
dialOpts := []grpc.DialOption{}
|
||||||
if c.cfg.ServiceConfig != "" {
|
if c.cfg.ServiceConfig != "" {
|
||||||
dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig))
|
dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig))
|
||||||
|
@ -75,6 +75,7 @@ type (
|
|||||||
ReconnectionPeriod time.Duration
|
ReconnectionPeriod time.Duration
|
||||||
ServiceConfig string
|
ServiceConfig string
|
||||||
DialOptions []grpc.DialOption
|
DialOptions []grpc.DialOption
|
||||||
|
GRPCConn *grpc.ClientConn
|
||||||
RetrySettings RetrySettings
|
RetrySettings RetrySettings
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -116,6 +116,14 @@ func WithDialOption(opts ...grpc.DialOption) Option {
|
|||||||
})}
|
})}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithGRPCConn allows reusing existing gRPC connection when it has already been
|
||||||
|
// established for other services. When set, other dial options will be ignored.
|
||||||
|
func WithGRPCConn(conn *grpc.ClientConn) Option {
|
||||||
|
return wrappedOption{otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||||
|
cfg.GRPCConn = conn
|
||||||
|
})}
|
||||||
|
}
|
||||||
|
|
||||||
// WithTimeout tells the client the max waiting time for the backend to process
|
// WithTimeout tells the client the max waiting time for the backend to process
|
||||||
// each metrics batch. If unset, the default will be 10 seconds.
|
// each metrics batch. If unset, the default will be 10 seconds.
|
||||||
func WithTimeout(duration time.Duration) Option {
|
func WithTimeout(duration time.Duration) Option {
|
||||||
|
@ -221,6 +221,10 @@ func (c *Connection) setConnection(cc *grpc.ClientConn) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) {
|
func (c *Connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) {
|
||||||
|
if c.cfg.GRPCConn != nil {
|
||||||
|
return c.cfg.GRPCConn, nil
|
||||||
|
}
|
||||||
|
|
||||||
dialOpts := []grpc.DialOption{}
|
dialOpts := []grpc.DialOption{}
|
||||||
if c.cfg.ServiceConfig != "" {
|
if c.cfg.ServiceConfig != "" {
|
||||||
dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig))
|
dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig))
|
||||||
|
@ -58,6 +58,7 @@ type (
|
|||||||
ReconnectionPeriod time.Duration
|
ReconnectionPeriod time.Duration
|
||||||
ServiceConfig string
|
ServiceConfig string
|
||||||
DialOptions []grpc.DialOption
|
DialOptions []grpc.DialOption
|
||||||
|
GRPCConn *grpc.ClientConn
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -116,6 +116,14 @@ func WithDialOption(opts ...grpc.DialOption) Option {
|
|||||||
})}
|
})}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithGRPCConn allows reusing existing gRPC connection when it has already been
|
||||||
|
// established for other services. When set, other dial options will be ignored.
|
||||||
|
func WithGRPCConn(conn *grpc.ClientConn) Option {
|
||||||
|
return wrappedOption{otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||||
|
cfg.GRPCConn = conn
|
||||||
|
})}
|
||||||
|
}
|
||||||
|
|
||||||
// WithTimeout tells the driver the max waiting time for the backend to process
|
// WithTimeout tells the driver the max waiting time for the backend to process
|
||||||
// each spans batch. If unset, the default will be 10 seconds.
|
// each spans batch. If unset, the default will be 10 seconds.
|
||||||
func WithTimeout(duration time.Duration) Option {
|
func WithTimeout(duration time.Duration) Option {
|
||||||
|
Reference in New Issue
Block a user