mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description The `xconfmap.Validator` interface has existed in some form for a very long time now and is ready to be stabilized. Similarly, the `xconfmap.Validate` method has existed in it's current state for over a year and doesn't have any open issues I'm aware of. It should also be ready for stabilization. Many modules depend on `xconfmap` merely for the validation facilities (as can be seen by the go.mod diffs), so this will allow them to depend on only stable modules. --------- Co-authored-by: Alex Boten <[email protected]>
55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package otlpexporter // import "go.opentelemetry.io/collector/exporter/otlpexporter"
|
|
|
|
import (
|
|
"errors"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/config/configgrpc"
|
|
"go.opentelemetry.io/collector/config/configoptional"
|
|
"go.opentelemetry.io/collector/config/configretry"
|
|
"go.opentelemetry.io/collector/confmap"
|
|
"go.opentelemetry.io/collector/exporter/exporterhelper"
|
|
)
|
|
|
|
// Config defines configuration for OTLP exporter.
|
|
type Config struct {
|
|
TimeoutConfig exporterhelper.TimeoutConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
|
QueueConfig configoptional.Optional[exporterhelper.QueueBatchConfig] `mapstructure:"sending_queue"`
|
|
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`
|
|
ClientConfig configgrpc.ClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
|
|
|
|
// prevent unkeyed literal initialization
|
|
_ struct{}
|
|
}
|
|
|
|
var (
|
|
_ component.Config = (*Config)(nil)
|
|
_ confmap.Validator = (*Config)(nil)
|
|
)
|
|
|
|
func (c *Config) Validate() error {
|
|
if endpoint := c.sanitizedEndpoint(); endpoint == "" {
|
|
return errors.New(`requires a non-empty "endpoint"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *Config) sanitizedEndpoint() string {
|
|
switch {
|
|
case strings.HasPrefix(c.ClientConfig.Endpoint, "http://"):
|
|
return strings.TrimPrefix(c.ClientConfig.Endpoint, "http://")
|
|
case strings.HasPrefix(c.ClientConfig.Endpoint, "https://"):
|
|
return strings.TrimPrefix(c.ClientConfig.Endpoint, "https://")
|
|
case strings.HasPrefix(c.ClientConfig.Endpoint, "dns://"):
|
|
r := regexp.MustCompile(`^dns:///?`)
|
|
return r.ReplaceAllString(c.ClientConfig.Endpoint, "")
|
|
default:
|
|
return c.ClientConfig.Endpoint
|
|
}
|
|
}
|