1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-09 13:37:12 +02:00

remove WithTrace* options from otlptrace exporters (#1997)

* remove WithTrace* options from otlptrace exporters
* remove old WithTraces methods usage
This commit is contained in:
Gustavo Silva Paiva 2021-06-11 19:27:38 -03:00 committed by GitHub
parent b33edaa552
commit 377f7ce402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 157 deletions

View File

@ -82,12 +82,12 @@ func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption {
}
if v, ok := e.getEnvValue("TRACES_ENDPOINT"); ok {
if isInsecureEndpoint(v) {
opts = append(opts, WithInsecureTraces())
opts = append(opts, WithInsecure())
} else {
opts = append(opts, WithSecureTraces())
opts = append(opts, WithSecure())
}
opts = append(opts, WithTracesEndpoint(trimSchema(v)))
opts = append(opts, WithEndpoint(trimSchema(v)))
}
// Certificate File
@ -100,7 +100,7 @@ func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption {
}
if path, ok := e.getEnvValue("TRACES_CERTIFICATE"); ok {
if tls, err := e.readTLSConfig(path); err == nil {
opts = append(opts, WithTracesTLSClientConfig(tls))
opts = append(opts, WithTLSClientConfig(tls))
} else {
otel.Handle(fmt.Errorf("failed to configure otlp traces exporter certificate '%s': %w", path, err))
}
@ -111,7 +111,7 @@ func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption {
opts = append(opts, WithHeaders(stringToHeader(h)))
}
if h, ok := e.getEnvValue("TRACES_HEADERS"); ok {
opts = append(opts, WithTracesHeaders(stringToHeader(h)))
opts = append(opts, WithHeaders(stringToHeader(h)))
}
// Compression
@ -119,7 +119,7 @@ func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption {
opts = append(opts, WithCompression(stringToCompression(c)))
}
if c, ok := e.getEnvValue("TRACES_COMPRESSION"); ok {
opts = append(opts, WithTracesCompression(stringToCompression(c)))
opts = append(opts, WithCompression(stringToCompression(c)))
}
// Timeout
if t, ok := e.getEnvValue("TIMEOUT"); ok {
@ -129,7 +129,7 @@ func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption {
}
if t, ok := e.getEnvValue("TRACES_TIMEOUT"); ok {
if d, err := strconv.Atoi(t); err == nil {
opts = append(opts, WithTracesTimeout(time.Duration(d)*time.Millisecond))
opts = append(opts, WithTimeout(time.Duration(d)*time.Millisecond))
}
}

View File

@ -207,25 +207,13 @@ func WithEndpoint(endpoint string) GenericOption {
})
}
func WithTracesEndpoint(endpoint string) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Endpoint = endpoint
})
}
func WithCompression(compression Compression) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Compression = compression
})
}
func WithTracesCompression(compression Compression) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Compression = compression
})
}
func WithTracesURLPath(urlPath string) GenericOption {
func WithURLPath(urlPath string) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.URLPath = urlPath
})
@ -245,14 +233,6 @@ func WithTLSClientConfig(tlsCfg *tls.Config) GenericOption {
})
}
func WithTracesTLSClientConfig(tlsCfg *tls.Config) GenericOption {
return newSplitOption(func(cfg *Config) {
cfg.Traces.TLSCfg = tlsCfg.Clone()
}, func(cfg *Config) {
cfg.Traces.GRPCCredentials = credentials.NewTLS(tlsCfg)
})
}
func WithInsecure() GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Insecure = true
@ -265,42 +245,18 @@ func WithSecure() GenericOption {
})
}
func WithInsecureTraces() GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Insecure = true
})
}
func WithSecureTraces() GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Insecure = false
})
}
func WithHeaders(headers map[string]string) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Headers = headers
})
}
func WithTracesHeaders(headers map[string]string) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Headers = headers
})
}
func WithTimeout(duration time.Duration) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Timeout = duration
})
}
func WithTracesTimeout(duration time.Duration) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.Traces.Timeout = duration
})
}
func WithMaxAttempts(maxAttempts int) GenericOption {
return newGenericOption(func(cfg *Config) {
cfg.MaxAttempts = maxAttempts

View File

@ -15,7 +15,6 @@
package otlpconfig_test
import (
"crypto/tls"
"errors"
"testing"
"time"
@ -94,16 +93,6 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, "someendpoint", c.Traces.Endpoint)
},
},
{
name: "Test With Signal Specific Endpoint",
opts: []otlpconfig.GenericOption{
otlpconfig.WithEndpoint("overrode_by_signal_specific"),
otlpconfig.WithTracesEndpoint("traces_endpoint"),
},
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
assert.Equal(t, "traces_endpoint", c.Traces.Endpoint)
},
},
{
name: "Test Environment Endpoint",
env: map[string]string{
@ -126,7 +115,7 @@ func TestConfigs(t *testing.T) {
{
name: "Test Mixed Environment and With Endpoint",
opts: []otlpconfig.GenericOption{
otlpconfig.WithTracesEndpoint("traces_endpoint"),
otlpconfig.WithEndpoint("traces_endpoint"),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_ENDPOINT": "env_endpoint",
@ -214,21 +203,6 @@ func TestConfigs(t *testing.T) {
}
},
},
{
name: "Test With Signal Specific Certificate",
opts: []otlpconfig.GenericOption{
otlpconfig.WithTLSClientConfig(&tls.Config{}),
otlpconfig.WithTracesTLSClientConfig(tlsCert),
},
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
if grpcOption {
assert.NotNil(t, c.Traces.GRPCCredentials)
} else {
assert.Equal(t, tlsCert.RootCAs.Subjects(), c.Traces.TLSCfg.RootCAs.Subjects())
}
},
},
{
name: "Test Environment Certificate",
env: map[string]string{
@ -291,16 +265,6 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, map[string]string{"h1": "v1"}, c.Traces.Headers)
},
},
{
name: "Test With Signal Specific Headers",
opts: []otlpconfig.GenericOption{
otlpconfig.WithHeaders(map[string]string{"overrode": "by_signal_specific"}),
otlpconfig.WithTracesHeaders(map[string]string{"t1": "tv1"}),
},
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
assert.Equal(t, map[string]string{"t1": "tv1"}, c.Traces.Headers)
},
},
{
name: "Test Environment Headers",
env: map[string]string{"OTEL_EXPORTER_OTLP_HEADERS": "h1=v1,h2=v2"},
@ -337,16 +301,6 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, otlpconfig.GzipCompression, c.Traces.Compression)
},
},
{
name: "Test With Signal Specific Compression",
opts: []otlpconfig.GenericOption{
otlpconfig.WithCompression(otlpconfig.NoCompression), // overrode by signal specific configs
otlpconfig.WithTracesCompression(otlpconfig.GzipCompression),
},
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
assert.Equal(t, otlpconfig.GzipCompression, c.Traces.Compression)
},
},
{
name: "Test Environment Compression",
env: map[string]string{
@ -368,7 +322,7 @@ func TestConfigs(t *testing.T) {
{
name: "Test Mixed Environment and With Compression",
opts: []otlpconfig.GenericOption{
otlpconfig.WithTracesCompression(otlpconfig.NoCompression),
otlpconfig.WithCompression(otlpconfig.NoCompression),
},
env: map[string]string{
"OTEL_EXPORTER_OTLP_TRACES_COMPRESSION": "gzip",
@ -388,16 +342,6 @@ func TestConfigs(t *testing.T) {
assert.Equal(t, 5*time.Second, c.Traces.Timeout)
},
},
{
name: "Test With Signal Specific Timeout",
opts: []otlpconfig.GenericOption{
otlpconfig.WithTimeout(time.Duration(5 * time.Second)),
otlpconfig.WithTracesTimeout(time.Duration(13 * time.Second)),
},
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
assert.Equal(t, 13*time.Second, c.Traces.Timeout)
},
},
{
name: "Test Environment Timeout",
env: map[string]string{
@ -424,7 +368,7 @@ func TestConfigs(t *testing.T) {
"OTEL_EXPORTER_OTLP_TRACES_TIMEOUT": "27000",
},
opts: []otlpconfig.GenericOption{
otlpconfig.WithTracesTimeout(5 * time.Second),
otlpconfig.WithTimeout(5 * time.Second),
},
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
assert.Equal(t, c.Traces.Timeout, 5*time.Second)

View File

@ -49,13 +49,6 @@ func WithInsecure() Option {
return wrappedOption{otlpconfig.WithInsecure()}
}
// WithTracesInsecure disables client transport security for the traces exporter's gRPC connection
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
// does. Note, by default, client security is required unless WithInsecure is used.
func WithTracesInsecure() Option {
return wrappedOption{otlpconfig.WithInsecureTraces()}
}
// WithEndpoint allows one to set the endpoint that the exporter will
// connect to the collector on. If unset, it will instead try to use
// connect to DefaultCollectorHost:DefaultCollectorPort.
@ -63,13 +56,6 @@ func WithEndpoint(endpoint string) Option {
return wrappedOption{otlpconfig.WithEndpoint(endpoint)}
}
// WithTracesEndpoint allows one to set the traces endpoint that the exporter will
// connect to the collector on. If unset, it will instead try to use
// connect to DefaultCollectorHost:DefaultCollectorPort.
func WithTracesEndpoint(endpoint string) Option {
return wrappedOption{otlpconfig.WithTracesEndpoint(endpoint)}
}
// WithReconnectionPeriod allows one to set the delay between next connection attempt
// after failing to connect with the collector.
func WithReconnectionPeriod(rp time.Duration) Option {
@ -97,25 +83,11 @@ func WithCompressor(compressor string) Option {
return wrappedOption{otlpconfig.WithCompression(compressorToCompression(compressor))}
}
// WithTracesCompression will set the compressor for the gRPC client to use when sending traces requests.
// It is the responsibility of the caller to ensure that the compressor set has been registered
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
// compressors auto-register on import, such as gzip, which can be registered by calling
// `import _ "google.golang.org/grpc/encoding/gzip"`.
func WithTracesCompression(compressor string) Option {
return wrappedOption{otlpconfig.WithTracesCompression(compressorToCompression(compressor))}
}
// WithHeaders will send the provided headers with gRPC requests.
func WithHeaders(headers map[string]string) Option {
return wrappedOption{otlpconfig.WithHeaders(headers)}
}
// WithTracesHeaders will send the provided headers with gRPC traces requests.
func WithTracesHeaders(headers map[string]string) Option {
return wrappedOption{otlpconfig.WithTracesHeaders(headers)}
}
// WithTLSCredentials allows the connection to use TLS credentials
// when talking to the server. It takes in grpc.TransportCredentials instead
// of say a Certificate file or a tls.Certificate, because the retrieving of
@ -127,17 +99,6 @@ func WithTLSCredentials(creds credentials.TransportCredentials) Option {
})}
}
// WithTracesTLSCredentials allows the connection to use TLS credentials
// when talking to the traces server. It takes in grpc.TransportCredentials instead
// of say a Certificate file or a tls.Certificate, because the retrieving of
// these credentials can be done in many ways e.g. plain file, in code tls.Config
// or by certificate rotation, so it is up to the caller to decide what to use.
func WithTracesTLSCredentials(creds credentials.TransportCredentials) Option {
return wrappedOption{otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
cfg.Traces.GRPCCredentials = creds
})}
}
// WithServiceConfig defines the default gRPC service config used.
func WithServiceConfig(serviceConfig string) Option {
return wrappedOption{otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
@ -160,12 +121,6 @@ func WithTimeout(duration time.Duration) Option {
return wrappedOption{otlpconfig.WithTimeout(duration)}
}
// WithTracesTimeout tells the driver the max waiting time for the backend to process
// each spans batch. If unset, the default will be 10 seconds.
func WithTracesTimeout(duration time.Duration) Option {
return wrappedOption{otlpconfig.WithTracesTimeout(duration)}
}
// WithRetry configures the retry policy for transient errors that may occurs when
// exporting traces. An exponential back-off algorithm is used to
// ensure endpoints are not overwhelmed with retries. If unset, the default

View File

@ -81,7 +81,7 @@ func WithCompression(compression Compression) Option {
// WithURLPath allows one to override the default URL path used
// for sending traces. If unset, default ("/v1/traces") will be used.
func WithURLPath(urlPath string) Option {
return wrappedOption{otlpconfig.WithTracesURLPath(urlPath)}
return wrappedOption{otlpconfig.WithURLPath(urlPath)}
}
// WithMaxAttempts allows one to override how many times the driver