Merge pull request #44 from navi-ppl/TP-5555/cache-stack-trace

Tp 5555/cache stack trace
This commit is contained in:
Podili Varshitha
2025-01-02 13:24:26 +05:30
committed by GitHub
2 changed files with 22 additions and 9 deletions

View File

@@ -99,8 +99,9 @@ func (el *ElasticSearchClient) GetStackTraceByErrorHash(errorHash string, projec
log.Printf("Error getting the response: %s", err)
}
filteredDoc := map[string]interface{}{}
stackFrame, ok := response[0]["stack_trace"].([]string)
if ok {
if len(response) > 0 {
stackFrame, ok := response[0]["stack_trace"]
println("ok", ok)
filteredDoc["stack_trace"] = stackFrame
}

View File

@@ -108,6 +108,21 @@ func getSignificantStack(trace symbolicator.SymbolicatedStackTrace) string {
return ""
}
func (ep *ErrorProcessor) getCacheStack(payload Exception, hash string) ([]symbolicator.SymbolicatedFrame, error) {
cachedStack, total, err := ep.elasticSearchClient.GetStackTraceByErrorHash(hash, payload.ProjectId)
var frames []symbolicator.SymbolicatedFrame
if total > 0 {
frameBytes, marshalErr := json.Marshal(cachedStack["stack_trace"])
if marshalErr != nil {
ep.logger.Error("unable to serilize cache frame", zap.Error(marshalErr))
} else {
err = json.Unmarshal(frameBytes, &frames)
}
}
return frames, err
}
func (ep *ErrorProcessor) ProcessError(error []byte) {
ep.logger.Info("processing error in consumer")
var payload Exception
@@ -170,15 +185,12 @@ func (ep *ErrorProcessor) ProcessError(error []byte) {
//make md5 hash of error
hash := encoder.Md5Encode(string(frames) + payload.Value)
cachedStack, total, err := ep.elasticSearchClient.GetStackTraceByErrorHash(hash, payload.ProjectId)
var output symbolicator.SymbolicatedStackTrace
//cache stack processing
cachedStackTrace, err := ep.getCacheStack(payload, hash)
if total > 0 && err == nil {
frames, ok := cachedStack["stack_trace"].([]symbolicator.SymbolicatedFrame)
if ok {
output.Frames = frames
}
if len(cachedStackTrace) > 0 {
output.Frames = cachedStackTrace
} else {
command := &symbolicator.Command{
Cmd: symbolicatorCommand,