Browse Source

异常优化:只要http请求和数据库相关的

路佳明 2 months ago
parent
commit
8bc734141b
2 changed files with 10 additions and 8 deletions
  1. 6 5
      app/observe/service/dto/event.go
  2. 4 3
      app/observe/service/event.go

+ 6 - 5
app/observe/service/dto/event.go

@@ -71,9 +71,10 @@ type EventStatisticResp struct {
 // }
 
 type EventListsResp struct {
-	Total          int64  `json:"total" ch:"StatusMessageCount" gorm:"column:StatusMessageCount"`
-	StatusMessage1 string `json:"status_message" ch:"StatusMessage" gorm:"column:StatusMessage"`
-	ServiceId      int64  `json:"service_id"`
-	ServiceName    string `json:"service_name" ch:"ServiceName" gorm:"column:ServiceName"`
-	ServiceNameCN  string `json:"service_name_cn" ch:"ServiceCnName" gorm:"column:ServiceCnName"`
+	StatusMessageCount int64  `json:"total"`
+	ErrorType          string `json:"error_type"`
+	StatusMessage1     string `json:"status_message"`
+	ServiceId          int64  `json:"service_id"`
+	ServiceName        string `json:"service_name"`
+	ServiceNameCN      string `json:"service_name_cn"`
 }

+ 4 - 3
app/observe/service/event.go

@@ -127,11 +127,12 @@ func (e *Event) EventStatistic(c *dto.EventStatisticReq, result *[]dto.EventStat
 func (e *Event) EventLists(c *dto.EventStatisticReq, result *[]dto.EventListsResp) error {
 	res := make([]dto.EventListsResp, 0)
 	db := e.ChOrm.Table(models.TableNameTracesError)
-	db.Select([]string{
+	db.Select(
+		"ServiceName AS ServiceName",
+		"any(if(SpanAttributes['db.system'] != '', 'db', 'http')) AS ErrorType",
 		"any(StatusMessage) as StatusMessage1",
 		"COUNT(DISTINCT TraceId) AS StatusMessageCount",
-		"ServiceName",
-	})
+	)
 	if c.AppAlias != "" {
 		db.Where("AppAlias = ?", c.AppAlias)
 	}