| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package otlphttpexporter |
| 5 |
|
| 6 |
import ( |
| 7 |
"encoding" |
| 8 |
"errors" |
| 9 |
"fmt" |
| 10 |
|
| 11 |
"go.opentelemetry.io/collector/component" |
| 12 |
"go.opentelemetry.io/collector/config/confighttp" |
| 13 |
"go.opentelemetry.io/collector/config/configretry" |
| 14 |
"go.opentelemetry.io/collector/exporter/exporterhelper" |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
type EncodingType string |
| 19 |
|
| 20 |
const ( |
| 21 |
EncodingProto EncodingType = "proto" |
| 22 |
EncodingJSON EncodingType = "json" |
| 23 |
) |
| 24 |
|
| 25 |
var _ encoding.TextUnmarshaler = (*EncodingType)(nil) |
| 26 |
|
| 27 |
|
| 28 |
func (e *EncodingType) UnmarshalText(text []byte) error { |
| 29 |
if e == nil { |
| 30 |
return errors.New("cannot unmarshal to a nil *EncodingType") |
| 31 |
} |
| 32 |
|
| 33 |
str := string(text) |
| 34 |
switch str { |
| 35 |
case string(EncodingProto): |
| 36 |
*e = EncodingProto |
| 37 |
case string(EncodingJSON): |
| 38 |
*e = EncodingJSON |
| 39 |
default: |
| 40 |
return fmt.Errorf("invalid encoding type: %s", str) |
| 41 |
} |
| 42 |
|
| 43 |
return nil |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
type Config struct { |
| 48 |
ClientConfig confighttp.ClientConfig `mapstructure:",squash"` |
| 49 |
QueueConfig exporterhelper.QueueBatchConfig `mapstructure:"sending_queue"` |
| 50 |
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"` |
| 51 |
|
| 52 |
|
| 53 |
TracesEndpoint string `mapstructure:"traces_endpoint"` |
| 54 |
|
| 55 |
|
| 56 |
MetricsEndpoint string `mapstructure:"metrics_endpoint"` |
| 57 |
|
| 58 |
|
| 59 |
LogsEndpoint string `mapstructure:"logs_endpoint"` |
| 60 |
|
| 61 |
|
| 62 |
ProfilesEndpoint string `mapstructure:"profiles_endpoint"` |
| 63 |
|
| 64 |
|
| 65 |
Encoding EncodingType `mapstructure:"encoding"` |
| 66 |
} |
| 67 |
|
| 68 |
var _ component.Config = (*Config)(nil) |
| 69 |
|
| 70 |
|
| 71 |
func (cfg *Config) Validate() error { |
| 72 |
if cfg.ClientConfig.Endpoint == "" && cfg.TracesEndpoint == "" && cfg.MetricsEndpoint == "" && cfg.LogsEndpoint == "" && cfg.ProfilesEndpoint == "" { |
| 73 |
return errors.New("at least one endpoint must be specified") |
| 74 |
} |
| 75 |
return nil |
| 76 |
} |