Debian Codegraph @

exporter/otlphttpexporter/config.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otlphttpexporter // import "go.opentelemetry.io/collector/exporter/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 // EncodingType defines the type for content encoding
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 // UnmarshalText unmarshalls text to an EncodingType.
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 // Config defines configuration for OTLP/HTTP exporter.
47 type Config struct {
48 ClientConfig confighttp.ClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
49 QueueConfig exporterhelper.QueueBatchConfig `mapstructure:"sending_queue"`
50 RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`
51
52 // The URL to send traces to. If omitted the Endpoint + "/v1/traces" will be used.
53 TracesEndpoint string `mapstructure:"traces_endpoint"`
54
55 // The URL to send metrics to. If omitted the Endpoint + "/v1/metrics" will be used.
56 MetricsEndpoint string `mapstructure:"metrics_endpoint"`
57
58 // The URL to send logs to. If omitted the Endpoint + "/v1/logs" will be used.
59 LogsEndpoint string `mapstructure:"logs_endpoint"`
60
61 // The URL to send profiles to. If omitted the Endpoint + "/v1development/profiles" will be used.
62 ProfilesEndpoint string `mapstructure:"profiles_endpoint"`
63
64 // The encoding to export telemetry (default: "proto")
65 Encoding EncodingType `mapstructure:"encoding"`
66 }
67
68 var _ component.Config = (*Config)(nil)
69
70 // Validate checks if the exporter configuration is valid
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 }