package worker import ( "context" "sync" ) type recordingWorkerTelemetry struct { mu sync.Mutex intentOutcomes []intentOutcomeTelemetryRecord malformedIntents []malformedIntentTelemetryRecord userEnrichment []userEnrichmentTelemetryRecord routePublishAttempts []routePublishTelemetryRecord routeRetries []routeTelemetryRecord routeDeadLetters []routeDeadLetterTelemetryRecord } func (telemetry *recordingWorkerTelemetry) RecordIntentOutcome(_ context.Context, notificationType string, producer string, audienceKind string, outcome string) { telemetry.mu.Lock() defer telemetry.mu.Unlock() telemetry.intentOutcomes = append(telemetry.intentOutcomes, intentOutcomeTelemetryRecord{ notificationType: notificationType, producer: producer, audienceKind: audienceKind, outcome: outcome, }) } func (telemetry *recordingWorkerTelemetry) RecordMalformedIntent(_ context.Context, failureCode string, notificationType string, producer string) { telemetry.mu.Lock() defer telemetry.mu.Unlock() telemetry.malformedIntents = append(telemetry.malformedIntents, malformedIntentTelemetryRecord{ failureCode: failureCode, notificationType: notificationType, producer: producer, }) } func (telemetry *recordingWorkerTelemetry) RecordUserEnrichmentAttempt(_ context.Context, notificationType string, result string) { telemetry.mu.Lock() defer telemetry.mu.Unlock() telemetry.userEnrichment = append(telemetry.userEnrichment, userEnrichmentTelemetryRecord{ notificationType: notificationType, result: result, }) } func (telemetry *recordingWorkerTelemetry) RecordRoutePublishAttempt(_ context.Context, channel string, notificationType string, result string, failureClassification string) { telemetry.mu.Lock() defer telemetry.mu.Unlock() telemetry.routePublishAttempts = append(telemetry.routePublishAttempts, routePublishTelemetryRecord{ channel: channel, notificationType: notificationType, result: result, failureClassification: failureClassification, }) } func (telemetry *recordingWorkerTelemetry) RecordRouteRetry(_ context.Context, channel string, notificationType string) { telemetry.mu.Lock() defer telemetry.mu.Unlock() telemetry.routeRetries = append(telemetry.routeRetries, routeTelemetryRecord{ channel: channel, notificationType: notificationType, }) } func (telemetry *recordingWorkerTelemetry) RecordRouteDeadLetter(_ context.Context, channel string, notificationType string, failureClassification string) { telemetry.mu.Lock() defer telemetry.mu.Unlock() telemetry.routeDeadLetters = append(telemetry.routeDeadLetters, routeDeadLetterTelemetryRecord{ channel: channel, notificationType: notificationType, failureClassification: failureClassification, }) } func (telemetry *recordingWorkerTelemetry) hasIntentOutcome(outcome string) bool { telemetry.mu.Lock() defer telemetry.mu.Unlock() for _, record := range telemetry.intentOutcomes { if record.outcome == outcome { return true } } return false } func (telemetry *recordingWorkerTelemetry) hasMalformedIntent(failureCode string) bool { telemetry.mu.Lock() defer telemetry.mu.Unlock() for _, record := range telemetry.malformedIntents { if record.failureCode == failureCode { return true } } return false } func (telemetry *recordingWorkerTelemetry) hasRoutePublishAttempt(channel string, result string, failureClassification string) bool { telemetry.mu.Lock() defer telemetry.mu.Unlock() for _, record := range telemetry.routePublishAttempts { if record.channel == channel && record.result == result && record.failureClassification == failureClassification { return true } } return false } func (telemetry *recordingWorkerTelemetry) hasRouteRetry(channel string) bool { telemetry.mu.Lock() defer telemetry.mu.Unlock() for _, record := range telemetry.routeRetries { if record.channel == channel { return true } } return false } func (telemetry *recordingWorkerTelemetry) hasRouteDeadLetter(channel string, failureClassification string) bool { telemetry.mu.Lock() defer telemetry.mu.Unlock() for _, record := range telemetry.routeDeadLetters { if record.channel == channel && record.failureClassification == failureClassification { return true } } return false } type intentOutcomeTelemetryRecord struct { notificationType string producer string audienceKind string outcome string } type malformedIntentTelemetryRecord struct { failureCode string notificationType string producer string } type userEnrichmentTelemetryRecord struct { notificationType string result string } type routePublishTelemetryRecord struct { channel string notificationType string result string failureClassification string } type routeTelemetryRecord struct { channel string notificationType string } type routeDeadLetterTelemetryRecord struct { channel string notificationType string failureClassification string }