|
| 1 | +package gotel |
| 2 | + |
| 3 | +import "errors" |
| 4 | + |
| 5 | +// OTLPCompressionType represents the compression type enum for OTLP. |
| 6 | +type OTLPCompressionType string |
| 7 | + |
| 8 | +const ( |
| 9 | + // OTLPCompressionNone is the enum that disables compression. |
| 10 | + OTLPCompressionNone OTLPCompressionType = "none" |
| 11 | + // OTLPCompressionGzip is the enum that enable compression of gzip algorithm. |
| 12 | + OTLPCompressionGzip OTLPCompressionType = "gzip" |
| 13 | +) |
| 14 | + |
| 15 | +// OTLPProtocol represents the OTLP protocol enum. |
| 16 | +type OTLPProtocol string |
| 17 | + |
| 18 | +const ( |
| 19 | + // OTLPProtocolGRPC represents the gRPC OTLP protocol enum. |
| 20 | + OTLPProtocolGRPC OTLPProtocol = "grpc" |
| 21 | + // OTLPProtocolHTTPProtobuf represents the HTTP Protobuf OTLP protocol enum. |
| 22 | + OTLPProtocolHTTPProtobuf OTLPProtocol = "http/protobuf" |
| 23 | +) |
| 24 | + |
| 25 | +// OTELMetricsExporterType defines the type of OpenTelemetry metrics exporter. |
| 26 | +type OTELMetricsExporterType string |
| 27 | + |
| 28 | +const ( |
| 29 | + // OTELMetricsExporterNone represents a enum that disables the metrics exporter. |
| 30 | + OTELMetricsExporterNone OTELMetricsExporterType = "none" |
| 31 | + // OTELMetricsExporterOTLP represents a enum that enables the metrics exporter via OTLP protocol. |
| 32 | + OTELMetricsExporterOTLP OTELMetricsExporterType = "otlp" |
| 33 | + // OTELMetricsExporterPrometheus represents a enum that enables the metrics exporter via Prometheus. |
| 34 | + OTELMetricsExporterPrometheus OTELMetricsExporterType = "prometheus" |
| 35 | +) |
| 36 | + |
| 37 | +// OTELLogsExporterType defines the type of OpenTelemetry logs exporter. |
| 38 | +type OTELLogsExporterType string |
| 39 | + |
| 40 | +const ( |
| 41 | + // OTELLogsExporterNone represents a enum that disables the logs exporter. |
| 42 | + OTELLogsExporterNone OTELLogsExporterType = "none" |
| 43 | + // OTELLogsExporterOTLP represents a enum that enables the logs exporter via OTLP protocol. |
| 44 | + OTELLogsExporterOTLP OTELLogsExporterType = "otlp" |
| 45 | +) |
| 46 | + |
| 47 | +var ( |
| 48 | + errInvalidOTLPCompressionType = errors.New( |
| 49 | + "invalid OTLP compression type, accept none, gzip only", |
| 50 | + ) |
| 51 | + errInvalidOTELMetricExporterType = errors.New("invalid OTEL metrics exporter type") |
| 52 | + errInvalidOTLPProtocol = errors.New("invalid OTLP protocol") |
| 53 | + errMetricsOTLPEndpointRequired = errors.New("OTLP endpoint is required for metrics exporter") |
| 54 | +) |
| 55 | + |
| 56 | +// OTLPConfig contains configuration for OpenTelemetry exporter. |
| 57 | +type OTLPConfig struct { |
| 58 | + // OpenTelemetry service name. |
| 59 | + ServiceName string `json:"serviceName,omitempty" yaml:"serviceName,omitempty" env:"OTEL_SERVICE_NAME" help:"OpenTelemetry service name."` |
| 60 | + // OTLP receiver endpoint that is set as default for all types. |
| 61 | + OtlpEndpoint string `json:"otlpEndpoint,omitempty" yaml:"otlpEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_ENDPOINT" help:"OTLP receiver endpoint that is set as default for all types."` |
| 62 | + // OTLP receiver endpoint for traces exporter. |
| 63 | + OtlpTracesEndpoint string `json:"otlpTracesEndpoint,omitempty" yaml:"otlpTracesEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" help:"OTLP receiver endpoint for traces."` |
| 64 | + // OTLP receiver endpoint for metrics exporter. |
| 65 | + OtlpMetricsEndpoint string `json:"otlpMetricsEndpoint,omitempty" yaml:"otlpMetricsEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" help:"OTLP receiver endpoint for metrics."` |
| 66 | + // OTLP receiver endpoint for logs exporter. |
| 67 | + OtlpLogsEndpoint string `json:"otlpLogsEndpoint,omitempty" yaml:"otlpLogsEndpoint,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT" help:"OTLP receiver endpoint for logs."` |
| 68 | + // Disable TLS for OpenTelemetry exporters. |
| 69 | + OtlpInsecure *bool `json:"otlpInsecure,omitempty" yaml:"otlpInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_INSECURE" help:"Disable TLS for OpenTelemetry exporters."` |
| 70 | + // Disable TLS for OpenTelemetry traces exporter. |
| 71 | + OtlpTracesInsecure *bool `json:"otlpTracesInsecure,omitempty" yaml:"otlpTracesInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_INSECURE" help:"Disable TLS for OpenTelemetry traces exporter."` |
| 72 | + // Disable TLS for OpenTelemetry metrics exporter. |
| 73 | + OtlpMetricsInsecure *bool `json:"otlpMetricsInsecure,omitempty" yaml:"otlpMetricsInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_INSECURE" help:"Disable TLS for OpenTelemetry metrics exporter."` |
| 74 | + // Disable TLS for OpenTelemetry logs exporter. |
| 75 | + OtlpLogsInsecure *bool `json:"otlpLogsInsecure,omitempty" yaml:"otlpLogsInsecure,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_INSECURE" help:"Disable TLS for OpenTelemetry logs exporter."` |
| 76 | + // OTLP receiver protocol for all exporters. Default is grpc. |
| 77 | + OtlpProtocol OTLPProtocol `json:"otlpProtocol,omitempty" yaml:"otlpProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for all exporters. Default is grpc"` |
| 78 | + // OTLP receiver protocol for traces. |
| 79 | + OtlpTracesProtocol OTLPProtocol `json:"otlpTracesProtocol,omitempty" yaml:"otlpTracesProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for traces."` |
| 80 | + // OTLP receiver protocol for metrics. |
| 81 | + OtlpMetricsProtocol OTLPProtocol `json:"otlpMetricsProtocol,omitempty" yaml:"otlpMetricsProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for metrics."` |
| 82 | + // OTLP receiver protocol for logs. |
| 83 | + OtlpLogsProtocol OTLPProtocol `json:"otlpLogsProtocol,omitempty" yaml:"otlpLogsProtocol,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_PROTOCOL" enum:"grpc,http/protobuf" jsonschema:"enum=grpc,enum=http/protobuf" help:"OTLP receiver protocol for logs."` |
| 84 | + // Enable compression for OTLP exporters. Accept: none, gzip |
| 85 | + OtlpCompression OTLPCompressionType `json:"otlpCompression,omitempty" yaml:"otlpCompression,omitempty" env:"OTEL_EXPORTER_OTLP_COMPRESSION" default:"gzip" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP exporters. Accept: none, gzip"` |
| 86 | + // Enable compression for OTLP traces exporter. Accept: none, gzip |
| 87 | + OtlpTracesCompression OTLPCompressionType `json:"otlpTracesCompression,omitempty" yaml:"otlpTracesCompression,omitempty" env:"OTEL_EXPORTER_OTLP_TRACES_COMPRESSION" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP traces exporter. Accept: none, gzip"` |
| 88 | + // Enable compression for OTLP metrics exporter. Accept: none, gzip |
| 89 | + OtlpMetricsCompression OTLPCompressionType `json:"otlpMetricsCompression,omitempty" yaml:"otlpMetricsCompression,omitempty" env:"OTEL_EXPORTER_OTLP_METRICS_COMPRESSION" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP metrics exporter. Accept: none, gzip"` |
| 90 | + // Enable compression for OTLP logs exporter. Accept: none, gzip |
| 91 | + OtlpLogsCompression OTLPCompressionType `json:"otlpLogsCompression,omitempty" yaml:"otlpLogsCompression,omitempty" env:"OTEL_EXPORTER_OTLP_LOGS_COMPRESSION" enum:"none,gzip" jsonschema:"enum=none,enum=gzip" help:"Enable compression for OTLP logs exporter. Accept: none, gzip"` |
| 92 | + // Metrics export type. Accept: none, otlp, prometheus |
| 93 | + MetricsExporter OTELMetricsExporterType `json:"metricsExporter,omitempty" yaml:"metricsExporter,omitempty" env:"OTEL_METRICS_EXPORTER" default:"none" enum:"none,otlp,prometheus" jsonschema:"enum=none,enum=otlp,enum=prometheus" help:"Metrics export type. Accept: none, otlp, prometheus"` |
| 94 | + // Logs export type. Accept: none, otlp |
| 95 | + LogsExporter OTELLogsExporterType `json:"logsExporter,omitempty" yaml:"logsExporter,omitempty" env:"OTEL_LOGS_EXPORTER" default:"none" enum:"none,otlp" jsonschema:"enum=none,enum=otlp" help:"Logs export type. Accept: none, otlp"` |
| 96 | + // Prometheus port for the Prometheus HTTP server. Use /metrics endpoint of the connector server if empty. |
| 97 | + PrometheusPort *uint `json:"prometheusPort,omitempty" yaml:"prometheusPort,omitempty" env:"OTEL_EXPORTER_PROMETHEUS_PORT" jsonschema:"minimum=1000,maximum=65535" help:"Prometheus port for the Prometheus HTTP server. Use /metrics endpoint of the connector server if empty"` |
| 98 | + // Disable internal Go and process metrics (prometheus exporter only). |
| 99 | + DisableGoMetrics *bool `json:"disableGoMetrics,omitempty" yaml:"disableGoMetrics,omitempty" help:"Disable internal Go and process metrics"` |
| 100 | +} |
| 101 | + |
| 102 | +// GetOTLPProtocol returns the OTLP protocol for OpenTelemetry exporters. Default is grpc. |
| 103 | +func (oc OTLPConfig) GetOTLPProtocol() OTLPProtocol { |
| 104 | + if oc.OtlpProtocol == "" { |
| 105 | + return OTLPProtocolGRPC |
| 106 | + } |
| 107 | + |
| 108 | + return oc.OtlpProtocol |
| 109 | +} |
| 110 | + |
| 111 | +// GetOTLPTracesProtocol returns the OTLP protocol for OTEL traces exporter. |
| 112 | +func (oc OTLPConfig) GetOTLPTracesProtocol() OTLPProtocol { |
| 113 | + if oc.OtlpTracesProtocol != "" { |
| 114 | + return oc.OtlpTracesProtocol |
| 115 | + } |
| 116 | + |
| 117 | + return oc.GetOTLPProtocol() |
| 118 | +} |
| 119 | + |
| 120 | +// GetOTLPMetricsProtocol returns the OTLP protocol for OTEL metrics exporter. |
| 121 | +func (oc OTLPConfig) GetOTLPMetricsProtocol() OTLPProtocol { |
| 122 | + if oc.OtlpMetricsProtocol != "" { |
| 123 | + return oc.OtlpMetricsProtocol |
| 124 | + } |
| 125 | + |
| 126 | + return oc.GetOTLPProtocol() |
| 127 | +} |
| 128 | + |
| 129 | +// GetOTLPLogsProtocol returns the OTLP protocol for OTEL logs exporter. |
| 130 | +func (oc OTLPConfig) GetOTLPLogsProtocol() OTLPProtocol { |
| 131 | + if oc.OtlpLogsProtocol != "" { |
| 132 | + return oc.OtlpLogsProtocol |
| 133 | + } |
| 134 | + |
| 135 | + return oc.GetOTLPProtocol() |
| 136 | +} |
| 137 | + |
| 138 | +// GetOTLPCompression returns the OTLP compression type. Default is gzip. |
| 139 | +func (oc OTLPConfig) GetOTLPCompression() OTLPCompressionType { |
| 140 | + if oc.OtlpCompression == "" { |
| 141 | + return OTLPCompressionGzip |
| 142 | + } |
| 143 | + |
| 144 | + return oc.OtlpCompression |
| 145 | +} |
| 146 | + |
| 147 | +// GetOTLPTracesCompression returns the OTLP traces compression type. Default is the otlpCompression value. |
| 148 | +func (oc OTLPConfig) GetOTLPTracesCompression() OTLPCompressionType { |
| 149 | + if oc.OtlpTracesCompression != "" { |
| 150 | + return oc.OtlpTracesCompression |
| 151 | + } |
| 152 | + |
| 153 | + return oc.GetOTLPCompression() |
| 154 | +} |
| 155 | + |
| 156 | +// GetOTLPMetricsCompression returns the OTLP metrics compression type. Default is the otlpCompression value. |
| 157 | +func (oc OTLPConfig) GetOTLPMetricsCompression() OTLPCompressionType { |
| 158 | + if oc.OtlpMetricsCompression != "" { |
| 159 | + return oc.OtlpMetricsCompression |
| 160 | + } |
| 161 | + |
| 162 | + return oc.GetOTLPCompression() |
| 163 | +} |
| 164 | + |
| 165 | +// GetOTLPLogsCompression returns the OTLP logs compression type. Default is the otlpCompression value. |
| 166 | +func (oc OTLPConfig) GetOTLPLogsCompression() OTLPCompressionType { |
| 167 | + if oc.OtlpLogsCompression != "" { |
| 168 | + return oc.OtlpLogsCompression |
| 169 | + } |
| 170 | + |
| 171 | + return oc.GetOTLPCompression() |
| 172 | +} |
| 173 | + |
| 174 | +// GetMetricsExporter returns the type of metrics exporter. Default is none. |
| 175 | +func (oc OTLPConfig) GetMetricsExporter() OTELMetricsExporterType { |
| 176 | + if oc.MetricsExporter == "" { |
| 177 | + return OTELMetricsExporterNone |
| 178 | + } |
| 179 | + |
| 180 | + return oc.MetricsExporter |
| 181 | +} |
| 182 | + |
| 183 | +// GetLogsExporter returns the type of logs exporter. Default is none. |
| 184 | +func (oc OTLPConfig) GetLogsExporter() OTELLogsExporterType { |
| 185 | + if oc.LogsExporter == "" { |
| 186 | + return OTELLogsExporterNone |
| 187 | + } |
| 188 | + |
| 189 | + return OTELLogsExporterOTLP |
| 190 | +} |
0 commit comments