@@ -530,52 +530,9 @@ func ParseConfigMap(ctx context.Context, cfgm *v1.ConfigMap, nginxPlus bool, has
530
530
}
531
531
}
532
532
533
- if otelExporterEndpoint , exists := cfgm .Data ["otel-exporter-endpoint" ]; exists {
534
- otelExporterEndpoint = strings .TrimSpace (otelExporterEndpoint )
535
- if otelExporterEndpoint != "" {
536
- cfgParams .MainOtelExporterEndpoint = otelExporterEndpoint
537
- }
538
- }
539
-
540
- if otelExporterTrustedCA , exists := cfgm .Data ["otel-exporter-trusted-ca" ]; exists {
541
- otelExporterTrustedCA = strings .TrimSpace (otelExporterTrustedCA )
542
- if otelExporterTrustedCA != "" {
543
- cfgParams .MainOtelExporterTrustedCA = otelExporterTrustedCA
544
- }
545
- }
546
-
547
- if otelExporterHeaderName , exists := cfgm .Data ["otel-exporter-header-name" ]; exists {
548
- otelExporterHeaderName = strings .TrimSpace (otelExporterHeaderName )
549
- if otelExporterHeaderName != "" {
550
- cfgParams .MainOtelExporterHeaderName = otelExporterHeaderName
551
- }
552
- }
553
-
554
- if otelExporterHeaderValue , exists := cfgm .Data ["otel-exporter-header-value" ]; exists {
555
- otelExporterHeaderValue = strings .TrimSpace (otelExporterHeaderValue )
556
- if otelExporterHeaderValue != "" {
557
- cfgParams .MainOtelExporterHeaderValue = otelExporterHeaderValue
558
- }
559
- }
560
-
561
- if otelServiceName , exists := cfgm .Data ["otel-service-name" ]; exists {
562
- otelServiceName = strings .TrimSpace (otelServiceName )
563
- if otelServiceName != "" {
564
- cfgParams .MainOtelServiceName = otelServiceName
565
- }
566
- }
567
-
568
- if otelGlobalTraceEnabled , exists , err := GetMapKeyAsBool (cfgm .Data , "otel-global-trace-enabled" , cfgm ); exists {
569
- if err != nil {
570
- nl .Error (l , err )
571
- eventLog .Event (cfgm , v1 .EventTypeWarning , nl .EventReasonInvalidValue , err .Error ())
572
- configOk = false
573
- }
574
- cfgParams .MainOtelGlobalTraceEnabled = otelGlobalTraceEnabled
575
- }
576
-
577
- if cfgParams .MainOtelExporterEndpoint != "" {
578
- cfgParams .MainOtelLoadModule = true
533
+ _ , otelErr := parseConfigMapOpenTelemetry (l , cfgm , cfgParams , eventLog )
534
+ if otelErr != nil {
535
+ configOk = false
579
536
}
580
537
581
538
if hasAppProtect {
@@ -788,6 +745,79 @@ func parseConfigMapZoneSync(l *slog.Logger, cfgm *v1.ConfigMap, cfgParams *Confi
788
745
return & cfgParams .ZoneSync , nil
789
746
}
790
747
748
+ //nolint:gocyclo
749
+ func parseConfigMapOpenTelemetry (l * slog.Logger , cfgm * v1.ConfigMap , cfgParams * ConfigParams , eventLog record.EventRecorder ) (* ConfigParams , error ) {
750
+ if otelExporterEndpoint , exists := cfgm .Data ["otel-exporter-endpoint" ]; exists {
751
+ otelExporterEndpoint = strings .TrimSpace (otelExporterEndpoint )
752
+ if otelExporterEndpoint != "" {
753
+ cfgParams .MainOtelExporterEndpoint = otelExporterEndpoint
754
+ }
755
+ }
756
+
757
+ if otelExporterHeaderName , exists := cfgm .Data ["otel-exporter-header-name" ]; exists {
758
+ otelExporterHeaderName = strings .TrimSpace (otelExporterHeaderName )
759
+ if otelExporterHeaderName != "" {
760
+ cfgParams .MainOtelExporterHeaderName = otelExporterHeaderName
761
+ }
762
+ }
763
+
764
+ if otelExporterHeaderValue , exists := cfgm .Data ["otel-exporter-header-value" ]; exists {
765
+ otelExporterHeaderValue = strings .TrimSpace (otelExporterHeaderValue )
766
+ if otelExporterHeaderValue != "" {
767
+ cfgParams .MainOtelExporterHeaderValue = otelExporterHeaderValue
768
+ }
769
+ }
770
+
771
+ if otelServiceName , exists := cfgm .Data ["otel-service-name" ]; exists {
772
+ otelServiceName = strings .TrimSpace (otelServiceName )
773
+ if otelServiceName != "" {
774
+ cfgParams .MainOtelServiceName = otelServiceName
775
+ }
776
+ }
777
+
778
+ otelValid := true
779
+
780
+ if otelTraceInHTTP , exists , err := GetMapKeyAsBool (cfgm .Data , "otel-trace-in-http" , cfgm ); exists {
781
+ if err != nil {
782
+ nl .Error (l , err )
783
+ eventLog .Event (cfgm , v1 .EventTypeWarning , nl .EventReasonInvalidValue , err .Error ())
784
+ otelValid = false
785
+ }
786
+ cfgParams .MainOtelTraceInHTTP = otelTraceInHTTP
787
+ }
788
+
789
+ if (cfgParams .MainOtelExporterHeaderName != "" && cfgParams .MainOtelExporterHeaderValue == "" ) ||
790
+ (cfgParams .MainOtelExporterHeaderName == "" && cfgParams .MainOtelExporterHeaderValue != "" ) {
791
+ errorText := "Both 'otel-exporter-header-name' and 'otel-exporter-header-value' must be set or neither"
792
+ nl .Error (l , errorText )
793
+ eventLog .Event (cfgm , v1 .EventTypeWarning , nl .EventReasonInvalidValue , errorText )
794
+ otelValid = false
795
+ }
796
+
797
+ if cfgParams .MainOtelExporterEndpoint != "" {
798
+ cfgParams .MainOtelLoadModule = true
799
+ }
800
+
801
+ if cfgParams .MainOtelExporterEndpoint == "" &&
802
+ (cfgParams .MainOtelExporterTrustedCA != "" ||
803
+ cfgParams .MainOtelExporterHeaderName != "" ||
804
+ cfgParams .MainOtelExporterHeaderValue != "" ||
805
+ cfgParams .MainOtelServiceName != "" ||
806
+ cfgParams .MainOtelTraceInHTTP ) {
807
+ errorText := "ConfigMap key 'otel-exporter-endpoint' is required when other otel fields are set"
808
+ nl .Error (l , errorText )
809
+ eventLog .Event (cfgm , v1 .EventTypeWarning , nl .EventReasonInvalidValue , errorText )
810
+ otelValid = false
811
+ cfgParams .MainOtelTraceInHTTP = false
812
+ }
813
+
814
+ if ! otelValid {
815
+ return nil , errors .New ("invalid OpenTelemetry configuration" )
816
+ }
817
+
818
+ return cfgParams , nil
819
+ }
820
+
791
821
// ParseMGMTConfigMap parses the mgmt block ConfigMap into MGMTConfigParams.
792
822
//
793
823
//nolint:gocyclo
@@ -940,11 +970,6 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
940
970
ResolverValid : config .ZoneSync .ResolverValid ,
941
971
}
942
972
943
- mainOtelExporterTrustedCA := ""
944
- if config .MainOtelExporterTrustedCA != "" {
945
- mainOtelExporterTrustedCA = fmt .Sprintf ("%s-%s-%s" , os .Getenv ("POD_NAMESPACE" ), config .MainOtelExporterTrustedCA , CACrtKey )
946
- }
947
-
948
973
nginxCfg := & version1.MainConfig {
949
974
AccessLog : config .MainAccessLog ,
950
975
DefaultServerAccessLogOff : config .DefaultServerAccessLogOff ,
@@ -967,9 +992,8 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
967
992
NginxStatusAllowCIDRs : staticCfgParams .NginxStatusAllowCIDRs ,
968
993
NginxStatusPort : staticCfgParams .NginxStatusPort ,
969
994
MainOtelLoadModule : config .MainOtelLoadModule ,
970
- MainOtelGlobalTraceEnabled : config .MainOtelGlobalTraceEnabled ,
995
+ MainOtelGlobalTraceEnabled : config .MainOtelTraceInHTTP ,
971
996
MainOtelExporterEndpoint : config .MainOtelExporterEndpoint ,
972
- MainOtelExporterTrustedCA : mainOtelExporterTrustedCA ,
973
997
MainOtelExporterHeaderName : config .MainOtelExporterHeaderName ,
974
998
MainOtelExporterHeaderValue : config .MainOtelExporterHeaderValue ,
975
999
MainOtelServiceName : config .MainOtelServiceName ,
0 commit comments