mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 14:54:23 +08:00
fix(otel): resolve exporter protocol through startup configuration
This commit is contained in:
@@ -33,9 +33,10 @@ var rootCmd = &cobra.Command{
|
||||
Compress: config.Config.Log.Compress,
|
||||
})
|
||||
trace.Init(trace.Config{
|
||||
AppName: config.Config.App.AppName,
|
||||
SamplingRate: config.Config.Otel.SamplingRate,
|
||||
TracerName: config.Config.Otel.TracerName,
|
||||
AppName: config.Config.App.AppName,
|
||||
SamplingRate: config.Config.Otel.SamplingRate,
|
||||
TracerName: config.Config.Otel.TracerName,
|
||||
ExportProtocol: config.Config.Otel.ExportProtocol,
|
||||
})
|
||||
},
|
||||
PreRun: func(_ *cobra.Command, _ []string) {
|
||||
|
||||
@@ -273,6 +273,14 @@ func applyEnvOverrides(c *configModel) {
|
||||
c.Log.Output = envStr("LOG_OUTPUT", c.Log.Output)
|
||||
|
||||
// ─── OTel ───
|
||||
protocol := strings.TrimSpace(envStr("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", ""))
|
||||
if protocol == "" {
|
||||
protocol = strings.TrimSpace(envStr("OTEL_EXPORTER_OTLP_PROTOCOL", ""))
|
||||
}
|
||||
if protocol == "" {
|
||||
protocol = c.Otel.ExportProtocol
|
||||
}
|
||||
c.Otel.ExportProtocol = strings.ToLower(strings.TrimSpace(protocol))
|
||||
c.Otel.SamplingRate = envFloat64("OTEL_SAMPLING_RATE", c.Otel.SamplingRate)
|
||||
c.Otel.TracerName = envStr("OTEL_TRACER_NAME", c.Otel.TracerName)
|
||||
|
||||
|
||||
@@ -47,3 +47,24 @@ func TestApplyClickHouseDefaultsEnablesWhenConfigured(t *testing.T) {
|
||||
t.Fatalf("hosts default not applied: %v", cfg.ClickHouse.Hosts)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOTLPProtocolPrecedence covers signal-specific, general, YAML and default settings.
|
||||
func TestOTLPProtocolPrecedence(t *testing.T) {
|
||||
for _, tt := range []struct{ name, signal, general, configured, want string }{
|
||||
{name: "default"},
|
||||
{name: "yaml", configured: "http/protobuf", want: "http/protobuf"},
|
||||
{name: "general", general: "http/protobuf", configured: "grpc", want: "http/protobuf"},
|
||||
{name: "signal", signal: " HTTP/PROTOBUF ", general: "grpc", want: "http/protobuf"},
|
||||
{name: "empty_signal", signal: " ", general: "grpc", configured: "http/protobuf", want: "grpc"},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", tt.signal)
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_PROTOCOL", tt.general)
|
||||
cfg := &configModel{Otel: otelConfig{ExportProtocol: tt.configured}}
|
||||
applyEnvOverrides(cfg)
|
||||
if cfg.Otel.ExportProtocol != tt.want {
|
||||
t.Errorf("OTLP protocol = %q, want %q", cfg.Otel.ExportProtocol, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ type QueueConfig struct {
|
||||
|
||||
// otelConfig OpenTelemetry 配置
|
||||
type otelConfig struct {
|
||||
SamplingRate float64 `mapstructure:"sampling_rate"`
|
||||
TracerName string `mapstructure:"tracer_name"`
|
||||
ExportProtocol string `mapstructure:"export_protocol"`
|
||||
SamplingRate float64 `mapstructure:"sampling_rate"`
|
||||
TracerName string `mapstructure:"tracer_name"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user