Skip to content

The only tool you need to know what is happening and how to fix it.

feat: added better notifications (#174)

narrow-adventurec4067a589ac5
diff --git a/backend/app/notifications/evaluator_event.go b/backend/app/notifications/evaluator_event.go
index 31605115..53c1a016 100644
--- a/backend/app/notifications/evaluator_event.go
+++ b/backend/app/notifications/evaluator_event.go
@@ -104,12 +104,13 @@ func evaluateErrorRegression(ctx context.Context, rule *models.NotificationRuleW
func getExceptionDetails(ctx context.Context, projectId uuid.UUID, hash string) ExceptionDetails {
var id uuid.UUID
- var stackTrace, appVersion, serverName, attributesJSON string
+ var traceId *uuid.UUID
+ var stackTrace, traceType, appVersion, serverName, attributesJSON string
var recordedAt time.Time
err := chdb.Conn.QueryRow(ctx,
- "SELECT id, stack_trace, attributes, app_version, server_name, recorded_at FROM exception_stack_traces WHERE project_id = ? AND exception_hash = ? ORDER BY recorded_at DESC LIMIT 1",
- projectId, hash).Scan(&id, &stackTrace, &attributesJSON, &appVersion, &serverName, &recordedAt)
+ "SELECT id, trace_id, trace_type, stack_trace, attributes, app_version, server_name, recorded_at FROM exception_stack_traces WHERE project_id = ? AND exception_hash = ? ORDER BY recorded_at DESC LIMIT 1",
+ projectId, hash).Scan(&id, &traceId, &traceType, &stackTrace, &attributesJSON, &appVersion, &serverName, &recordedAt)
details := ExceptionDetails{
Hash: hash,
@@ -125,6 +126,8 @@ func getExceptionDetails(ctx context.Context, projectId uuid.UUID, hash string)
details.AppVersion = appVersion
details.ServerName = serverName
details.RecordedAt = recordedAt
+ details.TraceType = traceType
+ details.TraceName = resolveTraceName(ctx, projectId, traceId, traceType)
if attributesJSON != "" && attributesJSON != "{}" {
attrs := make(map[string]string)
diff --git a/backend/app/notifications/evaluator_event_sqlite.go b/backend/app/notifications/evaluator_event_sqlite.go
index d2cf243f..0c6bd6db 100644
--- a/backend/app/notifications/evaluator_event_sqlite.go
+++ b/backend/app/notifications/evaluator_event_sqlite.go
@@ -100,11 +100,12 @@ func evaluateErrorRegression(ctx context.Context, rule *models.NotificationRuleW
}
func getExceptionDetails(ctx context.Context, projectId uuid.UUID, hash string) ExceptionDetails {
- var idStr, stackTrace, appVersion, serverName, attributesJSON, recordedAtStr string
+ var idStr, stackTrace, traceType, appVersion, serverName, attributesJSON, recordedAtStr string
+ var traceIdStr sql.NullString
err := db.DB.QueryRowContext(ctx,
- "SELECT id, stack_trace, attributes, app_version, server_name, recorded_at FROM exception_stack_traces WHERE project_id = ? AND exception_hash = ? ORDER BY recorded_at DESC LIMIT 1",
- projectId.String(), hash).Scan(&idStr, &stackTrace, &attributesJSON, &appVersion, &serverName, &recordedAtStr)
+ "SELECT id, trace_id, trace_type, stack_trace, attributes, app_version, server_name, recorded_at FROM exception_stack_traces WHERE project_id = ? AND exception_hash = ? ORDER BY recorded_at DESC LIMIT 1",
+ projectId.String(), hash).Scan(&idStr, &traceIdStr, &traceType, &stackTrace, &attributesJSON, &appVersion, &serverName, &recordedAtStr)
details := ExceptionDetails{
Hash: hash,
@@ -124,6 +125,15 @@ func getExceptionDetails(ctx context.Context, projectId uuid.UUID, hash string)
details.AppVersion = appVersion
details.ServerName = serverName
details.RecordedAt, _ = time.Parse(time.RFC3339Nano, recordedAtStr)
+ details.TraceType = traceType
+
+ var traceId *uuid.UUID
+ if traceIdStr.Valid {
+ if parsed, parseErr := uuid.Parse(traceIdStr.String); parseErr == nil {
+ traceId = &parsed
+ }
+ }
+ details.TraceName = resolveTraceName(ctx, projectId, traceId, traceType)
if attributesJSON != "" && attributesJSON != "{}" {
attrs := make(map[string]string)
diff --git a/backend/app/notifications/evaluator_helpers.go b/backend/app/notifications/evaluator_helpers.go
index 4443ac06..3758a470 100644
--- a/backend/app/notifications/evaluator_helpers.go
+++ b/backend/app/notifications/evaluator_helpers.go
@@ -112,6 +112,44 @@ func extractErrorType(stackTrace string) string {
return "Unknown Error"
}
+func resolveTraceName(ctx context.Context, projectId uuid.UUID, traceId *uuid.UUID, traceType string) string {
+ if traceId == nil {
+ return ""
+ }
+ switch traceType {
+ case "task":
+ task, err := repositories.TaskRepository.FindById(ctx, projectId, *traceId)
+ if err != nil {
+ traceway.CaptureException(fmt.Errorf("failed to resolve task name for notification: %w", err))
+ return ""
+ }
+ if task == nil {
+ return ""
+ }
+ return task.TaskName
+ case "ai_trace":
+ trace, err := repositories.AiTraceRepository.FindById(ctx, projectId, *traceId)
+ if err != nil {
+ traceway.CaptureException(fmt.Errorf("failed to resolve ai trace name for notification: %w", err))
+ return ""
+ }
+ if trace == nil {
+ return ""
+ }
+ return trace.TraceName
+ default:
+ endpoint, err := repositories.EndpointRepository.FindById(ctx, projectId, *traceId)
+ if err != nil {
+ traceway.CaptureException(fmt.Errorf("failed to resolve endpoint name for notification: %w", err))
+ return ""
+ }
+ if endpoint == nil {
+ return ""
+ }
+ return endpoint.Endpoint
+ }
+}
+
func getProjectName(projectId uuid.UUID) string {
project, err := db.ExecuteTransaction(func(tx *sql.Tx) (*models.Project, error) {
return repositories.ProjectRepository.FindById(tx, projectId)
diff --git a/backend/app/notifications/messages.go b/backend/app/notifications/messages.go
index 890d4d95..dc89fe07 100644
--- a/backend/app/notifications/messages.go
+++ b/backend/app/notifications/messages.go
@@ -181,6 +181,15 @@ type ExceptionDetails struct {
AppVersion string
ServerName string
RecordedAt time.Time
+ TraceType string
+ TraceName string
+}
+
+func (d ExceptionDetails) endpointForMessage() string {
+ if d.TraceType == "endpoint" {
+ return d.TraceName
+ }
+ return ""
}
func buildNewErrorMessage(details ExceptionDetails, projectName string) Message {
@@ -189,6 +198,7 @@ func buildNewErrorMessage(details ExceptionDetails, projectName string) Message
Body: buildExceptionBody("A new error has been detected: "+details.ErrorType, details),
Severity: SeverityCritical,
URL: fmt.Sprintf("/issues/%s", details.Hash),
+ Endpoint: details.endpointForMessage(),
}
}
@@ -198,6 +208,7 @@ func buildErrorRegressionMessage(details ExceptionDetails, projectName string) M
Body: buildExceptionBody("A previously resolved error has reappeared: "+details.ErrorType, details),
Severity: SeverityCritical,
URL: fmt.Sprintf("/issues/%s", details.Hash),
+ Endpoint: details.endpointForMessage(),
}
}
@@ -221,6 +232,16 @@ func buildExceptionBody(headline string, d ExceptionDetails) string {
if d.ServerName != "" {
fmt.Fprintf(&b, "\nServer: %s", d.ServerName)
}
+ if d.TraceName != "" {
+ switch d.TraceType {
+ case "task":
+ fmt.Fprintf(&b, "\nTask: %s", d.TraceName)
+ case "ai_trace":
+ fmt.Fprintf(&b, "\nAI trace: %s", d.TraceName)
+ default:
+ fmt.Fprintf(&b, "\nEndpoint: %s", d.TraceName)
+ }
+ }
if d.StackTrace != "" {
fmt.Fprintf(&b, "\n\nStack trace:\n%s", d.StackTrace)