@@ -105,7 +105,7 @@ var (
105105 // MultitenantNamespaceCount indicates the number of unique k8s namespaces enabled for multi-tenancy
106106 MultitenantNamespaceCount int
107107 // Regex to capture Received and Published EPS values from GigOtlpDataOutput log lines
108- otlpEPSRegex = regexp .MustCompile (`Received EPS:(\d+(?:\.\d+)?),\s*Published EPS:(\d+(?:\.\d+)?)` )
108+ OtlpEPSRegex = regexp .MustCompile (`Received EPS:(\d+(?:\.\d+)?),\s*Published EPS:(\d+(?:\.\d+)?)` )
109109)
110110
111111const (
@@ -456,19 +456,26 @@ func SendTracesAsMetrics(telemetryPushIntervalProperty string) {
456456 TracesMetricsTicker = time .NewTicker (time .Second * time .Duration (telemetryPushInterval ))
457457
458458 for ; true ; <- TracesMetricsTicker .C {
459+ // Capture and clear error metrics atomically
459460 TracesErrorMetricsMutex .Lock ()
460- for metricName , metricValue := range TracesErrorMetrics {
461- TelemetryClient .Track (appinsights .NewMetricTelemetry (metricName , metricValue ))
462- }
461+ errorMetricsSnapshot := TracesErrorMetrics
463462 TracesErrorMetrics = map [string ]float64 {}
464463 TracesErrorMetricsMutex .Unlock ()
465464
466- TracesInfoMetricsMutex . Lock ()
467- for metricName , metricValue := range TracesInfoMetrics {
465+ // Send metrics outside the lock
466+ for metricName , metricValue := range errorMetricsSnapshot {
468467 TelemetryClient .Track (appinsights .NewMetricTelemetry (metricName , metricValue ))
469468 }
469+
470+ // Same pattern for info metrics
471+ TracesInfoMetricsMutex .Lock ()
472+ infoMetricsSnapshot := TracesInfoMetrics
470473 TracesInfoMetrics = map [string ]float64 {}
471474 TracesInfoMetricsMutex .Unlock ()
475+
476+ for metricName , metricValue := range infoMetricsSnapshot {
477+ TelemetryClient .Track (appinsights .NewMetricTelemetry (metricName , metricValue ))
478+ }
472479 }
473480}
474481
@@ -686,7 +693,7 @@ func UpdateTracesInfoMetrics(key string, logEntry string) {
686693
687694// extractOtlpEPS returns Received and Published EPS values when present in a log entry
688695func extractOtlpEPS (logEntry string ) (float64 , float64 , bool ) {
689- matches := otlpEPSRegex .FindStringSubmatch (logEntry )
696+ matches := OtlpEPSRegex .FindStringSubmatch (logEntry )
690697 if len (matches ) != 3 {
691698 return 0 , 0 , false
692699 }
@@ -745,16 +752,20 @@ func PushToAppInsightsTraces(records []map[interface{}]interface{}, severityLeve
745752 // This error occurs when the OTLP receiver receives data in an unsupported protocol or compression is enabled.
746753 UpdateTracesErrorMetrics ("OtlpInvalidConfig" )
747754 } else if matched , _ := regexp .MatchString (`ContentType .* not supported` , logEntry ); matched {
748- UpdateTracesErrorMetrics ("OtlpInvalidContentType " )
755+ UpdateTracesErrorMetrics ("InvalidContentType " )
749756 } else if strings .Contains (logEntry , "GigLA Token not available" ) {
750- UpdateTracesErrorMetrics ("OtlpInvalidToken" )
751- } else if strings .Contains (logEntry , "GigOtlpDataOutput" ) && strings .Contains (logEntry , "Event:Log" ) {
752- UpdateTracesInfoMetrics ("OtlpLogsEPS" , logEntry )
753- } else if strings .Contains (logEntry , "GigOtlpDataOutput" ) && strings .Contains (logEntry , "Event:Span" ) {
754- UpdateTracesInfoMetrics ("OtlpSpansEPS" , logEntry )
757+ UpdateTracesErrorMetrics ("InvalidGigLAToken" )
758+ } else if strings .Contains (logEntry , "GigOtlpDataOutput" ) {
759+ if strings .Contains (logEntry , "Event:Log" ) {
760+ UpdateTracesInfoMetrics ("OtlpLogsEPS" , logEntry )
761+ } else if strings .Contains (logEntry , "Event:Span" ) {
762+ UpdateTracesInfoMetrics ("OtlpSpansEPS" , logEntry )
763+ }
764+ } else if ! strings .Contains (logEntry , "Information" ) {
765+ logLines = append (logLines , logEntry )
755766 }
756767 } else {
757- if ! strings .Contains (tag , "addon-token-adapter" ) && ! ( strings . Contains ( tag , "microsoft.linuxmonagent.amaca.log" ) && strings . Contains ( logEntry , "Information" )) {
768+ if ! strings .Contains (tag , "addon-token-adapter" ) {
758769 logLines = append (logLines , logEntry )
759770 }
760771 }
0 commit comments