mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-04 09:43:23 +02:00
Use port 4318 for otlp*http client default (#2625)
* Use port 4318 for otlptracehttp client default * Use port 4318 for otlpmetrichttp client default * Add changes to changelog * Fix arg pass error * Simplify defaultPath path parsing
This commit is contained in:
parent
94b1848a56
commit
0a6e4d8218
@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Remove the OTLP trace exporter limit of SpanEvents when exporting. (#2616)
|
- Remove the OTLP trace exporter limit of SpanEvents when exporting. (#2616)
|
||||||
|
- Use port `4318` instead of `4317` for default for the `otlpmetrichttp` and `otlptracehttp` client. (#2614, #2625)
|
||||||
|
|
||||||
## [1.4.1] - 2022-02-16
|
## [1.4.1] - 2022-02-16
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -72,24 +74,48 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDefaultConfig() Config {
|
// NewHTTPConfig returns a new Config with all settings applied from opts and
|
||||||
c := Config{
|
// any unset setting using the default HTTP config values.
|
||||||
|
func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||||
|
cfg := Config{
|
||||||
Metrics: SignalConfig{
|
Metrics: SignalConfig{
|
||||||
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorPort),
|
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorHTTPPort),
|
||||||
URLPath: DefaultMetricsPath,
|
URLPath: DefaultMetricsPath,
|
||||||
Compression: NoCompression,
|
Compression: NoCompression,
|
||||||
Timeout: DefaultTimeout,
|
Timeout: DefaultTimeout,
|
||||||
},
|
},
|
||||||
RetryConfig: retry.DefaultConfig,
|
RetryConfig: retry.DefaultConfig,
|
||||||
}
|
}
|
||||||
|
cfg = ApplyHTTPEnvConfigs(cfg)
|
||||||
|
for _, opt := range opts {
|
||||||
|
cfg = opt.ApplyHTTPOption(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
return c
|
tmp := strings.TrimSpace(cfg.Metrics.URLPath)
|
||||||
|
if tmp == "" {
|
||||||
|
tmp = DefaultMetricsPath
|
||||||
|
} else {
|
||||||
|
tmp = path.Clean(tmp)
|
||||||
|
if !path.IsAbs(tmp) {
|
||||||
|
tmp = fmt.Sprintf("/%s", tmp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg.Metrics.URLPath = tmp
|
||||||
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGRPCConfig returns a new Config with all settings applied from opts and
|
// NewGRPCConfig returns a new Config with all settings applied from opts and
|
||||||
// any unset setting using the default gRPC config values.
|
// any unset setting using the default gRPC config values.
|
||||||
func NewGRPCConfig(opts ...GRPCOption) Config {
|
func NewGRPCConfig(opts ...GRPCOption) Config {
|
||||||
cfg := NewDefaultConfig()
|
cfg := Config{
|
||||||
|
Metrics: SignalConfig{
|
||||||
|
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorGRPCPort),
|
||||||
|
URLPath: DefaultMetricsPath,
|
||||||
|
Compression: NoCompression,
|
||||||
|
Timeout: DefaultTimeout,
|
||||||
|
},
|
||||||
|
RetryConfig: retry.DefaultConfig,
|
||||||
|
}
|
||||||
cfg = ApplyGRPCEnvConfigs(cfg)
|
cfg = ApplyGRPCEnvConfigs(cfg)
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
cfg = opt.ApplyGRPCOption(cfg)
|
cfg = opt.ApplyGRPCOption(cfg)
|
||||||
|
@ -76,7 +76,11 @@ func TestConfigs(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Test default configs",
|
name: "Test default configs",
|
||||||
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
|
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
|
||||||
assert.Equal(t, "localhost:4317", c.Metrics.Endpoint)
|
if grpcOption {
|
||||||
|
assert.Equal(t, "localhost:4317", c.Metrics.Endpoint)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, "localhost:4318", c.Metrics.Endpoint)
|
||||||
|
}
|
||||||
assert.Equal(t, otlpconfig.NoCompression, c.Metrics.Compression)
|
assert.Equal(t, otlpconfig.NoCompression, c.Metrics.Compression)
|
||||||
assert.Equal(t, map[string]string(nil), c.Metrics.Headers)
|
assert.Equal(t, map[string]string(nil), c.Metrics.Headers)
|
||||||
assert.Equal(t, 10*time.Second, c.Metrics.Timeout)
|
assert.Equal(t, 10*time.Second, c.Metrics.Timeout)
|
||||||
@ -386,11 +390,7 @@ func TestConfigs(t *testing.T) {
|
|||||||
t.Cleanup(func() { otlpconfig.DefaultEnvOptionsReader = origEOR })
|
t.Cleanup(func() { otlpconfig.DefaultEnvOptionsReader = origEOR })
|
||||||
|
|
||||||
// Tests Generic options as HTTP Options
|
// Tests Generic options as HTTP Options
|
||||||
cfg := otlpconfig.NewDefaultConfig()
|
cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(tt.opts)...)
|
||||||
cfg = otlpconfig.ApplyHTTPEnvConfigs(cfg)
|
|
||||||
for _, opt := range tt.opts {
|
|
||||||
cfg = opt.ApplyHTTPOption(cfg)
|
|
||||||
}
|
|
||||||
tt.asserts(t, &cfg, false)
|
tt.asserts(t, &cfg, false)
|
||||||
|
|
||||||
// Tests Generic options as gRPC Options
|
// Tests Generic options as gRPC Options
|
||||||
@ -400,6 +400,14 @@ func TestConfigs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func asHTTPOptions(opts []otlpconfig.GenericOption) []otlpconfig.HTTPOption {
|
||||||
|
converted := make([]otlpconfig.HTTPOption, len(opts))
|
||||||
|
for i, o := range opts {
|
||||||
|
converted[i] = otlpconfig.NewHTTPOption(o.ApplyHTTPOption)
|
||||||
|
}
|
||||||
|
return converted
|
||||||
|
}
|
||||||
|
|
||||||
func asGRPCOptions(opts []otlpconfig.GenericOption) []otlpconfig.GRPCOption {
|
func asGRPCOptions(opts []otlpconfig.GenericOption) []otlpconfig.GRPCOption {
|
||||||
converted := make([]otlpconfig.GRPCOption, len(opts))
|
converted := make([]otlpconfig.GRPCOption, len(opts))
|
||||||
for i, o := range opts {
|
for i, o := range opts {
|
||||||
|
@ -17,9 +17,10 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultCollectorPort is the port the Exporter will attempt connect to
|
// DefaultCollectorGRPCPort is the default gRPC port of the collector.
|
||||||
// if no collector port is provided.
|
DefaultCollectorGRPCPort uint16 = 4317
|
||||||
DefaultCollectorPort uint16 = 4317
|
// DefaultCollectorHTTPPort is the default HTTP port of the collector.
|
||||||
|
DefaultCollectorHTTPPort uint16 = 4318
|
||||||
// DefaultCollectorHost is the host address the Exporter will attempt
|
// DefaultCollectorHost is the host address the Exporter will attempt
|
||||||
// connect to if no collector address is provided.
|
// connect to if no collector address is provided.
|
||||||
DefaultCollectorHost string = "localhost"
|
DefaultCollectorHost string = "localhost"
|
||||||
|
@ -24,9 +24,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -77,26 +75,7 @@ type client struct {
|
|||||||
|
|
||||||
// NewClient creates a new HTTP metric client.
|
// NewClient creates a new HTTP metric client.
|
||||||
func NewClient(opts ...Option) otlpmetric.Client {
|
func NewClient(opts ...Option) otlpmetric.Client {
|
||||||
cfg := otlpconfig.NewDefaultConfig()
|
cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(opts)...)
|
||||||
cfg = otlpconfig.ApplyHTTPEnvConfigs(cfg)
|
|
||||||
for _, opt := range opts {
|
|
||||||
cfg = opt.applyHTTPOption(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
for pathPtr, defaultPath := range map[*string]string{
|
|
||||||
&cfg.Metrics.URLPath: otlpconfig.DefaultMetricsPath,
|
|
||||||
} {
|
|
||||||
tmp := strings.TrimSpace(*pathPtr)
|
|
||||||
if tmp == "" {
|
|
||||||
tmp = defaultPath
|
|
||||||
} else {
|
|
||||||
tmp = path.Clean(tmp)
|
|
||||||
if !path.IsAbs(tmp) {
|
|
||||||
tmp = fmt.Sprintf("/%s", tmp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*pathPtr = tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
httpClient := &http.Client{
|
httpClient := &http.Client{
|
||||||
Transport: ourTransport,
|
Transport: ourTransport,
|
||||||
|
@ -40,6 +40,14 @@ type Option interface {
|
|||||||
applyHTTPOption(otlpconfig.Config) otlpconfig.Config
|
applyHTTPOption(otlpconfig.Config) otlpconfig.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func asHTTPOptions(opts []Option) []otlpconfig.HTTPOption {
|
||||||
|
converted := make([]otlpconfig.HTTPOption, len(opts))
|
||||||
|
for i, o := range opts {
|
||||||
|
converted[i] = otlpconfig.NewHTTPOption(o.applyHTTPOption)
|
||||||
|
}
|
||||||
|
return converted
|
||||||
|
}
|
||||||
|
|
||||||
// RetryConfig defines configuration for retrying batches in case of export
|
// RetryConfig defines configuration for retrying batches in case of export
|
||||||
// failure using an exponential backoff.
|
// failure using an exponential backoff.
|
||||||
type RetryConfig retry.Config
|
type RetryConfig retry.Config
|
||||||
@ -52,11 +60,10 @@ func (w wrappedOption) applyHTTPOption(cfg otlpconfig.Config) otlpconfig.Config
|
|||||||
return w.ApplyHTTPOption(cfg)
|
return w.ApplyHTTPOption(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithEndpoint allows one to set the address of the collector
|
// WithEndpoint allows one to set the address of the collector endpoint that
|
||||||
// endpoint that the driver will use to send metrics. If
|
// the driver will use to send metrics. If unset, it will instead try to use
|
||||||
// unset, it will instead try to use
|
// the default endpoint (localhost:4318). Note that the endpoint must not
|
||||||
// the default endpoint (localhost:4317). Note that the endpoint
|
// contain any URL path.
|
||||||
// must not contain any URL path.
|
|
||||||
func WithEndpoint(endpoint string) Option {
|
func WithEndpoint(endpoint string) Option {
|
||||||
return wrappedOption{otlpconfig.WithEndpoint(endpoint)}
|
return wrappedOption{otlpconfig.WithEndpoint(endpoint)}
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,14 @@ override the default configuration. For more information about how each of
|
|||||||
these environment variables is interpreted, see [the OpenTelemetry
|
these environment variables is interpreted, see [the OpenTelemetry
|
||||||
specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.8.0/specification/protocol/exporter.md).
|
specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.8.0/specification/protocol/exporter.md).
|
||||||
|
|
||||||
| Environment variable | Option | Default value |
|
| Environment variable | Option | Default value |
|
||||||
| ------------------------------------------------------------------------ |------------------------------ | ----------------------------------- |
|
| ------------------------------------------------------------------------ |------------------------------ | -------------------------------------------------------- |
|
||||||
| `OTEL_EXPORTER_OTLP_ENDPOINT` `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | `WithEndpoint` `WithInsecure` | `https://localhost:4317` |
|
| `OTEL_EXPORTER_OTLP_ENDPOINT` `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | `WithEndpoint` `WithInsecure` | `https://localhost:4317` or `https://localhost:4318`[^1] |
|
||||||
| `OTEL_EXPORTER_OTLP_CERTIFICATE` `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` | `WithTLSClientConfig` | |
|
| `OTEL_EXPORTER_OTLP_CERTIFICATE` `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` | `WithTLSClientConfig` | |
|
||||||
| `OTEL_EXPORTER_OTLP_HEADERS` `OTEL_EXPORTER_OTLP_TRACES_HEADERS` | `WithHeaders` | |
|
| `OTEL_EXPORTER_OTLP_HEADERS` `OTEL_EXPORTER_OTLP_TRACES_HEADERS` | `WithHeaders` | |
|
||||||
| `OTEL_EXPORTER_OTLP_COMPRESSION` `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` | `WithCompression` | |
|
| `OTEL_EXPORTER_OTLP_COMPRESSION` `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` | `WithCompression` | |
|
||||||
| `OTEL_EXPORTER_OTLP_TIMEOUT` `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` | `WithTimeout` | `10s` |
|
| `OTEL_EXPORTER_OTLP_TIMEOUT` `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` | `WithTimeout` | `10s` |
|
||||||
|
|
||||||
|
[^1]: The gRPC client defaults to `https://localhost:4317` and the HTTP client `https://localhost:4318`.
|
||||||
|
|
||||||
Configuration using options have precedence over the environment variables.
|
Configuration using options have precedence over the environment variables.
|
||||||
|
@ -17,6 +17,8 @@ package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -65,24 +67,48 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDefaultConfig() Config {
|
// NewHTTPConfig returns a new Config with all settings applied from opts and
|
||||||
c := Config{
|
// any unset setting using the default HTTP config values.
|
||||||
|
func NewHTTPConfig(opts ...HTTPOption) Config {
|
||||||
|
cfg := Config{
|
||||||
Traces: SignalConfig{
|
Traces: SignalConfig{
|
||||||
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorPort),
|
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorHTTPPort),
|
||||||
URLPath: DefaultTracesPath,
|
URLPath: DefaultTracesPath,
|
||||||
Compression: NoCompression,
|
Compression: NoCompression,
|
||||||
Timeout: DefaultTimeout,
|
Timeout: DefaultTimeout,
|
||||||
},
|
},
|
||||||
RetryConfig: retry.DefaultConfig,
|
RetryConfig: retry.DefaultConfig,
|
||||||
}
|
}
|
||||||
|
cfg = ApplyHTTPEnvConfigs(cfg)
|
||||||
|
for _, opt := range opts {
|
||||||
|
cfg = opt.ApplyHTTPOption(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
return c
|
tmp := strings.TrimSpace(cfg.Traces.URLPath)
|
||||||
|
if tmp == "" {
|
||||||
|
tmp = DefaultTracesPath
|
||||||
|
} else {
|
||||||
|
tmp = path.Clean(tmp)
|
||||||
|
if !path.IsAbs(tmp) {
|
||||||
|
tmp = fmt.Sprintf("/%s", tmp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg.Traces.URLPath = tmp
|
||||||
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGRPCConfig returns a new Config with all settings applied from opts and
|
// NewGRPCConfig returns a new Config with all settings applied from opts and
|
||||||
// any unset setting using the default gRPC config values.
|
// any unset setting using the default gRPC config values.
|
||||||
func NewGRPCConfig(opts ...GRPCOption) Config {
|
func NewGRPCConfig(opts ...GRPCOption) Config {
|
||||||
cfg := NewDefaultConfig()
|
cfg := Config{
|
||||||
|
Traces: SignalConfig{
|
||||||
|
Endpoint: fmt.Sprintf("%s:%d", DefaultCollectorHost, DefaultCollectorGRPCPort),
|
||||||
|
URLPath: DefaultTracesPath,
|
||||||
|
Compression: NoCompression,
|
||||||
|
Timeout: DefaultTimeout,
|
||||||
|
},
|
||||||
|
RetryConfig: retry.DefaultConfig,
|
||||||
|
}
|
||||||
cfg = ApplyGRPCEnvConfigs(cfg)
|
cfg = ApplyGRPCEnvConfigs(cfg)
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
cfg = opt.ApplyGRPCOption(cfg)
|
cfg = opt.ApplyGRPCOption(cfg)
|
||||||
|
@ -76,7 +76,11 @@ func TestConfigs(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Test default configs",
|
name: "Test default configs",
|
||||||
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
|
asserts: func(t *testing.T, c *otlpconfig.Config, grpcOption bool) {
|
||||||
assert.Equal(t, "localhost:4317", c.Traces.Endpoint)
|
if grpcOption {
|
||||||
|
assert.Equal(t, "localhost:4317", c.Traces.Endpoint)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, "localhost:4318", c.Traces.Endpoint)
|
||||||
|
}
|
||||||
assert.Equal(t, otlpconfig.NoCompression, c.Traces.Compression)
|
assert.Equal(t, otlpconfig.NoCompression, c.Traces.Compression)
|
||||||
assert.Equal(t, map[string]string(nil), c.Traces.Headers)
|
assert.Equal(t, map[string]string(nil), c.Traces.Headers)
|
||||||
assert.Equal(t, 10*time.Second, c.Traces.Timeout)
|
assert.Equal(t, 10*time.Second, c.Traces.Timeout)
|
||||||
@ -384,11 +388,7 @@ func TestConfigs(t *testing.T) {
|
|||||||
t.Cleanup(func() { otlpconfig.DefaultEnvOptionsReader = origEOR })
|
t.Cleanup(func() { otlpconfig.DefaultEnvOptionsReader = origEOR })
|
||||||
|
|
||||||
// Tests Generic options as HTTP Options
|
// Tests Generic options as HTTP Options
|
||||||
cfg := otlpconfig.NewDefaultConfig()
|
cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(tt.opts)...)
|
||||||
cfg = otlpconfig.ApplyHTTPEnvConfigs(cfg)
|
|
||||||
for _, opt := range tt.opts {
|
|
||||||
cfg = opt.ApplyHTTPOption(cfg)
|
|
||||||
}
|
|
||||||
tt.asserts(t, &cfg, false)
|
tt.asserts(t, &cfg, false)
|
||||||
|
|
||||||
// Tests Generic options as gRPC Options
|
// Tests Generic options as gRPC Options
|
||||||
@ -398,6 +398,14 @@ func TestConfigs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func asHTTPOptions(opts []otlpconfig.GenericOption) []otlpconfig.HTTPOption {
|
||||||
|
converted := make([]otlpconfig.HTTPOption, len(opts))
|
||||||
|
for i, o := range opts {
|
||||||
|
converted[i] = otlpconfig.NewHTTPOption(o.ApplyHTTPOption)
|
||||||
|
}
|
||||||
|
return converted
|
||||||
|
}
|
||||||
|
|
||||||
func asGRPCOptions(opts []otlpconfig.GenericOption) []otlpconfig.GRPCOption {
|
func asGRPCOptions(opts []otlpconfig.GenericOption) []otlpconfig.GRPCOption {
|
||||||
converted := make([]otlpconfig.GRPCOption, len(opts))
|
converted := make([]otlpconfig.GRPCOption, len(opts))
|
||||||
for i, o := range opts {
|
for i, o := range opts {
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig"
|
package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultCollectorPort is the port the Exporter will attempt connect to
|
// DefaultCollectorGRPCPort is the default gRPC port of the collector.
|
||||||
// if no collector port is provided.
|
DefaultCollectorGRPCPort uint16 = 4317
|
||||||
DefaultCollectorPort uint16 = 4317
|
// DefaultCollectorHTTPPort is the default HTTP port of the collector.
|
||||||
|
DefaultCollectorHTTPPort uint16 = 4318
|
||||||
// DefaultCollectorHost is the host address the Exporter will attempt
|
// DefaultCollectorHost is the host address the Exporter will attempt
|
||||||
// connect to if no collector address is provided.
|
// connect to if no collector address is provided.
|
||||||
DefaultCollectorHost string = "localhost"
|
DefaultCollectorHost string = "localhost"
|
||||||
|
@ -24,9 +24,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -79,26 +77,7 @@ var _ otlptrace.Client = (*client)(nil)
|
|||||||
|
|
||||||
// NewClient creates a new HTTP trace client.
|
// NewClient creates a new HTTP trace client.
|
||||||
func NewClient(opts ...Option) otlptrace.Client {
|
func NewClient(opts ...Option) otlptrace.Client {
|
||||||
cfg := otlpconfig.NewDefaultConfig()
|
cfg := otlpconfig.NewHTTPConfig(asHTTPOptions(opts)...)
|
||||||
cfg = otlpconfig.ApplyHTTPEnvConfigs(cfg)
|
|
||||||
for _, opt := range opts {
|
|
||||||
cfg = opt.applyHTTPOption(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
for pathPtr, defaultPath := range map[*string]string{
|
|
||||||
&cfg.Traces.URLPath: otlpconfig.DefaultTracesPath,
|
|
||||||
} {
|
|
||||||
tmp := strings.TrimSpace(*pathPtr)
|
|
||||||
if tmp == "" {
|
|
||||||
tmp = defaultPath
|
|
||||||
} else {
|
|
||||||
tmp = path.Clean(tmp)
|
|
||||||
if !path.IsAbs(tmp) {
|
|
||||||
tmp = fmt.Sprintf("/%s", tmp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*pathPtr = tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
httpClient := &http.Client{
|
httpClient := &http.Client{
|
||||||
Transport: ourTransport,
|
Transport: ourTransport,
|
||||||
|
@ -40,6 +40,14 @@ type Option interface {
|
|||||||
applyHTTPOption(otlpconfig.Config) otlpconfig.Config
|
applyHTTPOption(otlpconfig.Config) otlpconfig.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func asHTTPOptions(opts []Option) []otlpconfig.HTTPOption {
|
||||||
|
converted := make([]otlpconfig.HTTPOption, len(opts))
|
||||||
|
for i, o := range opts {
|
||||||
|
converted[i] = otlpconfig.NewHTTPOption(o.applyHTTPOption)
|
||||||
|
}
|
||||||
|
return converted
|
||||||
|
}
|
||||||
|
|
||||||
// RetryConfig defines configuration for retrying batches in case of export
|
// RetryConfig defines configuration for retrying batches in case of export
|
||||||
// failure using an exponential backoff.
|
// failure using an exponential backoff.
|
||||||
type RetryConfig retry.Config
|
type RetryConfig retry.Config
|
||||||
@ -55,7 +63,7 @@ func (w wrappedOption) applyHTTPOption(cfg otlpconfig.Config) otlpconfig.Config
|
|||||||
// WithEndpoint allows one to set the address of the collector
|
// WithEndpoint allows one to set the address of the collector
|
||||||
// endpoint that the driver will use to send spans. If
|
// endpoint that the driver will use to send spans. If
|
||||||
// unset, it will instead try to use
|
// unset, it will instead try to use
|
||||||
// the default endpoint (localhost:4317). Note that the endpoint
|
// the default endpoint (localhost:4318). Note that the endpoint
|
||||||
// must not contain any URL path.
|
// must not contain any URL path.
|
||||||
func WithEndpoint(endpoint string) Option {
|
func WithEndpoint(endpoint string) Option {
|
||||||
return wrappedOption{otlpconfig.WithEndpoint(endpoint)}
|
return wrappedOption{otlpconfig.WithEndpoint(endpoint)}
|
||||||
|
Loading…
Reference in New Issue
Block a user