mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
GO-3747 Send traces for long methods
This commit is contained in:
parent
6bd5f1e17e
commit
fc84d67ce7
2 changed files with 31 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue