Skip to content

Commit

Permalink
alerting: also log to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Mar 11, 2024
1 parent f7a823f commit ddce4a4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions flow/alerting/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,32 @@ func (a *Alerter) sendTelemetryMessage(ctx context.Context, flowName string, mor
}

func (a *Alerter) LogFlowError(ctx context.Context, flowName string, err error) {
logger := logger.LoggerFromCtx(ctx)
errorWithStack := fmt.Sprintf("%+v", err)
logger.Error(err.Error(), slog.Any("stack", errorWithStack))
_, err = a.catalogPool.Exec(ctx,
"INSERT INTO peerdb_stats.flow_errors(flow_name,error_message,error_type) VALUES($1,$2,$3)",
flowName, errorWithStack, "error")
if err != nil {
logger.LoggerFromCtx(ctx).Warn("failed to insert flow error", slog.Any("error", err))
logger.Warn("failed to insert flow error", slog.Any("error", err))
return
}
a.sendTelemetryMessage(ctx, flowName, errorWithStack, telemetry.ERROR)
}

func (a *Alerter) LogFlowEvent(ctx context.Context, flowName string, info string) {
logger.LoggerFromCtx(ctx).Info(info)
a.sendTelemetryMessage(ctx, flowName, info, telemetry.INFO)
}

func (a *Alerter) LogFlowInfo(ctx context.Context, flowName string, info string) {
logger := logger.LoggerFromCtx(ctx)
logger.Info(info)
_, err := a.catalogPool.Exec(ctx,
"INSERT INTO peerdb_stats.flow_errors(flow_name,error_message,error_type) VALUES($1,$2,$3)",
flowName, info, "info")
if err != nil {
logger.LoggerFromCtx(ctx).Warn("failed to insert flow info", slog.Any("error", err))
logger.Warn("failed to insert flow info", slog.Any("error", err))
return
}
}

0 comments on commit ddce4a4

Please sign in to comment.