// Code generated by gotmpl. DO NOT MODIFY.
// source: internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package otlpconfig provides configuration for the otlptrace exporters.
package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig" import ( ) const ( // DefaultTracesPath is a default URL path for endpoint that // receives spans. DefaultTracesPath string = "/v1/traces" // DefaultTimeout is a default max waiting time for the backend to process // each span batch. DefaultTimeout time.Duration = 10 * time.Second ) type ( // HTTPTransportProxyFunc is a function that resolves which URL to use as proxy for a given request. // This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client. HTTPTransportProxyFunc func(*http.Request) (*url.URL, error) SignalConfig struct { Endpoint string Insecure bool TLSCfg *tls.Config Headers map[string]string Compression Compression Timeout time.Duration URLPath string // gRPC configurations GRPCCredentials credentials.TransportCredentials // HTTP configurations Proxy HTTPTransportProxyFunc HTTPClient *http.Client } Config struct { // Signal specific configurations Traces SignalConfig RetryConfig retry.Config // gRPC configurations ReconnectionPeriod time.Duration ServiceConfig string DialOptions []grpc.DialOption GRPCConn *grpc.ClientConn } ) // NewHTTPConfig returns a new Config with all settings applied from opts and // any unset setting using the default HTTP config values. func ( ...HTTPOption) Config { := Config{ Traces: SignalConfig{ Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorHTTPPort), URLPath: DefaultTracesPath, Compression: NoCompression, Timeout: DefaultTimeout, }, RetryConfig: retry.DefaultConfig, } = ApplyHTTPEnvConfigs() for , := range { = .ApplyHTTPOption() } .Traces.URLPath = cleanPath(.Traces.URLPath, DefaultTracesPath) return } // cleanPath returns a path with all spaces trimmed. If urlPath is empty, // defaultPath is returned instead. func cleanPath( string, string) string { := strings.TrimSpace() if == "" || == "." { return } if !path.IsAbs() { = "/" + } return } // NewGRPCConfig returns a new Config with all settings applied from opts and // any unset setting using the default gRPC config values. func ( ...GRPCOption) Config { := "OTel OTLP Exporter Go/" + otlptrace.Version() := Config{ Traces: SignalConfig{ Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorGRPCPort), URLPath: DefaultTracesPath, Compression: NoCompression, Timeout: DefaultTimeout, }, RetryConfig: retry.DefaultConfig, DialOptions: []grpc.DialOption{grpc.WithUserAgent()}, } = ApplyGRPCEnvConfigs() for , := range { = .ApplyGRPCOption() } if .ServiceConfig != "" { .DialOptions = append(.DialOptions, grpc.WithDefaultServiceConfig(.ServiceConfig)) } // Prioritize GRPCCredentials over Insecure (passing both is an error). if .Traces.GRPCCredentials != nil { .DialOptions = append(.DialOptions, grpc.WithTransportCredentials(.Traces.GRPCCredentials)) } else if .Traces.Insecure { .DialOptions = append(.DialOptions, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // Default to using the host's root CA. := credentials.NewTLS(nil) .Traces.GRPCCredentials = .DialOptions = append(.DialOptions, grpc.WithTransportCredentials()) } if .Traces.Compression == GzipCompression { .DialOptions = append(.DialOptions, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name))) } if .ReconnectionPeriod != 0 { := grpc.ConnectParams{ Backoff: backoff.DefaultConfig, MinConnectTimeout: .ReconnectionPeriod, } .DialOptions = append(.DialOptions, grpc.WithConnectParams()) } return } type ( // GenericOption applies an option to the HTTP or gRPC driver. GenericOption interface { ApplyHTTPOption(Config) Config ApplyGRPCOption(Config) Config // A private method to prevent users implementing the // interface and so future additions to it will not // violate compatibility. private() } // HTTPOption applies an option to the HTTP driver. HTTPOption interface { ApplyHTTPOption(Config) Config // A private method to prevent users implementing the // interface and so future additions to it will not // violate compatibility. private() } // GRPCOption applies an option to the gRPC driver. GRPCOption interface { ApplyGRPCOption(Config) Config // A private method to prevent users implementing the // interface and so future additions to it will not // violate compatibility. private() } ) // genericOption is an option that applies the same logic // for both gRPC and HTTP. type genericOption struct { fn func(Config) Config } func ( *genericOption) ( Config) Config { return .fn() } func ( *genericOption) ( Config) Config { return .fn() } func (genericOption) () {} func newGenericOption( func( Config) Config) GenericOption { return &genericOption{fn: } } // splitOption is an option that applies different logics // for gRPC and HTTP. type splitOption struct { httpFn func(Config) Config grpcFn func(Config) Config } func ( *splitOption) ( Config) Config { return .grpcFn() } func ( *splitOption) ( Config) Config { return .httpFn() } func (splitOption) () {} func newSplitOption( func( Config) Config, func( Config) Config) GenericOption { return &splitOption{httpFn: , grpcFn: } } // httpOption is an option that is only applied to the HTTP driver. type httpOption struct { fn func(Config) Config } func ( *httpOption) ( Config) Config { return .fn() } func (httpOption) () {} func ( func( Config) Config) HTTPOption { return &httpOption{fn: } } // grpcOption is an option that is only applied to the gRPC driver. type grpcOption struct { fn func(Config) Config } func ( *grpcOption) ( Config) Config { return .fn() } func (grpcOption) () {} func ( func( Config) Config) GRPCOption { return &grpcOption{fn: } } // Generic Options // WithEndpoint configures the trace host and port only; endpoint should // resemble "example.com" or "localhost:4317". To configure the scheme and path, // use WithEndpointURL. func ( string) GenericOption { return newGenericOption(func( Config) Config { .Traces.Endpoint = return }) } // WithEndpointURL configures the trace scheme, host, port, and path; the // provided value should resemble "https://example.com:4318/v1/traces". func ( string) GenericOption { return newGenericOption(func( Config) Config { , := url.Parse() if != nil { global.Error(, "otlptrace: parse endpoint url", "url", ) return } .Traces.Endpoint = .Host .Traces.URLPath = .Path .Traces.Insecure = .Scheme != "https" return }) } func ( Compression) GenericOption { return newGenericOption(func( Config) Config { .Traces.Compression = return }) } func ( string) GenericOption { return newGenericOption(func( Config) Config { .Traces.URLPath = return }) } func ( retry.Config) GenericOption { return newGenericOption(func( Config) Config { .RetryConfig = return }) } func ( *tls.Config) GenericOption { return newSplitOption(func( Config) Config { .Traces.TLSCfg = .Clone() return }, func( Config) Config { .Traces.GRPCCredentials = credentials.NewTLS() return }) } func () GenericOption { return newGenericOption(func( Config) Config { .Traces.Insecure = true return }) } func () GenericOption { return newGenericOption(func( Config) Config { .Traces.Insecure = false return }) } func ( map[string]string) GenericOption { return newGenericOption(func( Config) Config { .Traces.Headers = return }) } func ( time.Duration) GenericOption { return newGenericOption(func( Config) Config { .Traces.Timeout = return }) } func ( HTTPTransportProxyFunc) GenericOption { return newGenericOption(func( Config) Config { .Traces.Proxy = return }) } func ( *http.Client) GenericOption { return newGenericOption(func( Config) Config { .Traces.HTTPClient = return }) }