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

remove WithTrace* options from otlptrace exporters #1997

Merged
merged 5 commits into from Jun 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions exporters/otlp/otlptrace/internal/otlpconfig/envconfig.go
Expand Up @@ -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
Expand All @@ -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))
}
Expand All @@ -111,15 +111,15 @@ 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
if c, ok := e.getEnvValue("COMPRESSION"); ok {
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 {
Expand All @@ -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))
}
}

Expand Down
46 changes: 1 addition & 45 deletions exporters/otlp/otlptrace/internal/otlpconfig/options.go
Expand Up @@ -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
})
Expand All @@ -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
Expand All @@ -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
Expand Down
62 changes: 3 additions & 59 deletions exporters/otlp/otlptrace/internal/otlpconfig/options_test.go
Expand Up @@ -15,7 +15,6 @@
package otlpconfig_test

import (
"crypto/tls"
"errors"
"testing"
"time"
Expand Down Expand Up @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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{
Expand All @@ -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",
Expand All @@ -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{
Expand All @@ -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)
Expand Down
45 changes: 0 additions & 45 deletions exporters/otlp/otlptrace/otlptracegrpc/options.go
Expand Up @@ -49,27 +49,13 @@ 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.
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 {
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracehttp/options.go
Expand Up @@ -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
Expand Down