Skip to content

Commit

Permalink
Update otlp trace grpc http transport configuration to support custom…
Browse files Browse the repository at this point in the history
… proxy function
  • Loading branch information
MickaelAlliel committed Feb 11, 2024
1 parent a38fbad commit 9c8288e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/
import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
"path"
"strings"
Expand All @@ -46,6 +47,8 @@ const (
)

type (
HTTPTransportProxyFunc func(*http.Request) (*url.URL, error)

SignalConfig struct {
Endpoint string
Insecure bool
Expand All @@ -57,6 +60,8 @@ type (

// gRPC configurations
GRPCCredentials credentials.TransportCredentials

Proxy HTTPTransportProxyFunc
}

Config struct {
Expand Down Expand Up @@ -343,3 +348,10 @@ func WithTimeout(duration time.Duration) GenericOption {
return cfg
})
}

func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Proxy = pf
return cfg
})
}
10 changes: 6 additions & 4 deletions exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ var _ otlptrace.Client = (*client)(nil)
func NewClient(opts ...Option) otlptrace.Client {
cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(opts)...)

clonedTransport := ourTransport.Clone()
httpClient := &http.Client{
Transport: ourTransport,
Transport: clonedTransport,
Timeout: cfg.Traces.Timeout,
}
if cfg.Traces.TLSCfg != nil {
transport := ourTransport.Clone()
transport.TLSClientConfig = cfg.Traces.TLSCfg
httpClient.Transport = transport
clonedTransport.TLSClientConfig = cfg.Traces.TLSCfg
}
if cfg.Traces.Proxy != nil {
clonedTransport.Proxy = cfg.Traces.Proxy
}

stopCh := make(chan struct{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/
import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
"path"
"strings"
Expand All @@ -46,6 +47,8 @@ const (
)

type (
HTTPTransportProxyFunc func(*http.Request) (*url.URL, error)

SignalConfig struct {
Endpoint string
Insecure bool
Expand All @@ -57,6 +60,8 @@ type (

// gRPC configurations
GRPCCredentials credentials.TransportCredentials

Proxy HTTPTransportProxyFunc
}

Config struct {
Expand Down Expand Up @@ -343,3 +348,10 @@ func WithTimeout(duration time.Duration) GenericOption {
return cfg
})
}

func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Proxy = pf
return cfg
})
}
2 changes: 1 addition & 1 deletion internal/shared/otlp/otlpmetric/oconf/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type (
TemporalitySelector metric.TemporalitySelector
AggregationSelector metric.AggregationSelector

Proxy HTTPTransportProxyFunc
Proxy HTTPTransportProxyFunc
}

Config struct {
Expand Down
12 changes: 12 additions & 0 deletions internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package otlpconfig
import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
"path"
"strings"
Expand All @@ -46,6 +47,8 @@ const (
)

type (
HTTPTransportProxyFunc func(*http.Request) (*url.URL, error)

SignalConfig struct {
Endpoint string
Insecure bool
Expand All @@ -57,6 +60,8 @@ type (

// gRPC configurations
GRPCCredentials credentials.TransportCredentials

Proxy HTTPTransportProxyFunc
}

Config struct {
Expand Down Expand Up @@ -343,3 +348,10 @@ func WithTimeout(duration time.Duration) GenericOption {
return cfg
})
}

func WithProxyFunc(pf HTTPTransportProxyFunc) GenericOption {
return newGenericOption(func(cfg Config) Config {
cfg.Traces.Proxy = pf
return cfg
})
}

0 comments on commit 9c8288e

Please sign in to comment.