Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: add hasError tag in searchTraces response

makeavish244a07aef8b6
diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go
index 876c66fa18..805fce3b16 100644
--- a/pkg/query-service/app/clickhouseReader/reader.go
+++ b/pkg/query-service/app/clickhouseReader/reader.go
@@ -1537,7 +1537,7 @@ func (r *ClickHouseReader) GetSpanFilters(ctx context.Context, queryParams *mode
}
}
case "status":
- finalQuery := fmt.Sprintf("SELECT COUNT(*) as numErrors FROM %s WHERE timestamp >= ? AND timestamp <= ? AND ( ( has(tags, 'error:true') OR statusCode>=500 OR statusCode=2))", r.indexTable)
+ finalQuery := fmt.Sprintf("SELECT COUNT(*) as numErrors FROM %s WHERE timestamp >= ? AND timestamp <= ? AND hasError = 1", r.indexTable)
finalQuery += query
var dBResponse []model.DBResponseErrors
err := r.db.Select(&dBResponse, finalQuery, args...)
@@ -1582,16 +1582,16 @@ func getStatusFilters(query string, statusParams []string, excludeMap map[string
if _, ok := excludeMap["status"]; ok {
if len(statusParams) == 1 {
if statusParams[0] == "error" {
- query += " AND ((NOT ( has(tags, 'error:true')) AND statusCode<500 AND statusCode!=2))"
+ query += " AND hasError = 0"
} else if statusParams[0] == "ok" {
- query += " AND ( ( has(tags, 'error:true') OR statusCode>=500 OR statusCode=2))"
+ query += " AND hasError = 1"
}
}
} else if len(statusParams) == 1 {
if statusParams[0] == "error" {
- query += " AND ( ( has(tags, 'error:true') OR statusCode>=500 OR statusCode=2))"
+ query += " AND hasError = 1"
} else if statusParams[0] == "ok" {
- query += " AND ((NOT ( has(tags, 'error:true')) AND statusCode<500 AND statusCode!=2))"
+ query += " AND hasError = 0"
}
}
return query
@@ -2093,7 +2093,7 @@ func (r *ClickHouseReader) SearchTraces(ctx context.Context, traceId string) (*[
var searchScanReponses []model.SearchSpanReponseItem
- query := fmt.Sprintf("SELECT timestamp, spanID, traceID, serviceName, name, kind, durationNano, tagsKeys, tagsValues, references, events FROM %s WHERE traceID=?", r.indexTable)
+ query := fmt.Sprintf("SELECT timestamp, spanID, traceID, serviceName, name, kind, durationNano, tagsKeys, tagsValues, references, events, hasError FROM %s WHERE traceID=?", r.indexTable)
err := r.db.Select(&searchScanReponses, query, traceId)
@@ -2106,7 +2106,7 @@ func (r *ClickHouseReader) SearchTraces(ctx context.Context, traceId string) (*[
searchSpansResult := []model.SearchSpansResult{
model.SearchSpansResult{
- Columns: []string{"__time", "SpanId", "TraceId", "ServiceName", "Name", "Kind", "DurationNano", "TagsKeys", "TagsValues", "References", "Events"},
+ Columns: []string{"__time", "SpanId", "TraceId", "ServiceName", "Name", "Kind", "DurationNano", "TagsKeys", "TagsValues", "References", "Events", "HasError"},
Events: make([][]interface{}, len(searchScanReponses)),
},
}
diff --git a/pkg/query-service/model/response.go b/pkg/query-service/model/response.go
index d3e15490f1..eeeabeaa9c 100644
--- a/pkg/query-service/model/response.go
+++ b/pkg/query-service/model/response.go
@@ -179,6 +179,7 @@ type SearchSpanReponseItem struct {
TagsKeys []string `db:"tagsKeys"`
TagsValues []string `db:"tagsValues"`
Events []string `db:"events"`
+ HasError int32 `db:"hasError"`
}
type OtelSpanRef struct {
@@ -214,7 +215,7 @@ func (item *SearchSpanReponseItem) GetValues() []interface{} {
}
}
- returnArray := []interface{}{int64(timeObj.UnixNano() / 1000000), item.SpanID, item.TraceID, item.ServiceName, item.Name, strconv.Itoa(int(item.Kind)), strconv.FormatInt(item.DurationNano, 10), item.TagsKeys, item.TagsValues, referencesStringArray, errorEvent}
+ returnArray := []interface{}{int64(timeObj.UnixNano() / 1000000), item.SpanID, item.TraceID, item.ServiceName, item.Name, strconv.Itoa(int(item.Kind)), strconv.FormatInt(item.DurationNano, 10), item.TagsKeys, item.TagsValues, referencesStringArray, errorEvent, item.HasError}
return returnArray
}