1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-10 01:51:07 +09:00

GO-3747 Send traces for long methods

This commit is contained in:
Mikhail Iudin 2024-07-11 16:50:27 +02:00 committed by Anthony Akentiev
parent 3cfb63ab5a
commit 7411c754ef
No known key found for this signature in database
GPG key ID: 017A11DC01A79831
2 changed files with 31 additions and 0 deletions

View file

@ -400,3 +400,23 @@ func (c *MethodEvent) MarshalFastJson(arena *fastjson.Arena) anymetry.JsonEvent
properties.Set("description", arena.NewString(c.description))
return event
}
type LongMethodEvent struct {
baseInfo
methodName string
middleTime int64
stack string
}
func (c *LongMethodEvent) GetBackend() anymetry.MetricsBackend {
return inhouse
}
func (c *LongMethodEvent) MarshalFastJson(arena *fastjson.Arena) anymetry.JsonEvent {
event, properties := setupProperties(arena, "LongMethodEvent")
properties.Set("methodName", arena.NewString(c.methodName))
properties.Set("middleTime", arena.NewNumberInt(int(c.middleTime)))
properties.Set("stack", arena.NewString(c.stack))
return event
}

View file

@ -104,10 +104,21 @@ func SharedLongMethodsInterceptor(ctx context.Context, req any, methodName strin
// todo: save long stack trace to files
lastTraceB := debug.CompressBytes([]byte(lastTrace.String()))
l.With("ver", 2).With("error", err).With("in_progress", false).With("goroutines", lastTraceB).With("total", time.Since(start).Milliseconds()).Warnf("grpc unary request took too long")
Service.Send(
&LongMethodEvent{
methodName: methodName,
middleTime: elapsed.Milliseconds(),
stack: lastTrace.Load(),
},
)
}
return resp, err
}
func stackTraceHasMethod(method string, stackTrace []byte) bool {
return bytes.Contains(stackTrace, []byte("core.(*Middleware)."+method+"("))
}
func SendMethodEvent(method string, err error, resp any, delta int64) {
if !lo.Contains(excludedMethods, method) {
if err != nil {