mirror of
https://github.com/livekit/livekit.git
synced 2026-10-23 17:22:59 +00:00
Log timeout in API. (#4231)
* Log timeout in API. * make a reset function
This commit is contained in:
1 parent
541a7d6c5b
commit
ac20ccda53
2 files changed
+18
-3
No files matched your search
@@ -2867,6 +2867,7 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
"falling back to alternative video codec",
|
||||
"codec", mimeType,
|
||||
"altCodec", altCodec,
|
||||
"enabledPublishCodecs", logger.ProtoSlice(p.enabledPublishCodecs),
|
||||
"trackID", ti.Sid,
|
||||
)
|
||||
// select an alternative MIME type that's generally supported
|
||||
@@ -2894,6 +2895,7 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
"falling back to alternative audio codec",
|
||||
"codec", mimeType,
|
||||
"altCodec", altCodec,
|
||||
"enabledPublishCodecs", logger.ProtoSlice(p.enabledPublishCodecs),
|
||||
"trackID", ti.Sid,
|
||||
)
|
||||
// select an alternative MIME type that's generally supported
|
||||
|
||||
+16
-3
@@ -70,6 +70,14 @@ type twirpLogger struct {
|
||||
fieldsOrig []any
|
||||
fields []any
|
||||
startedAt time.Time
|
||||
deadline time.Time
|
||||
}
|
||||
|
||||
func (t *twirpLogger) reset() {
|
||||
t.fields = t.fieldsOrig
|
||||
t.error = nil
|
||||
t.startedAt = time.Time{}
|
||||
t.deadline = time.Time{}
|
||||
}
|
||||
|
||||
func AppendLogFields(ctx context.Context, fields ...any) {
|
||||
@@ -84,6 +92,9 @@ func AppendLogFields(ctx context.Context, fields ...any) {
|
||||
func loggerRequestReceived(ctx context.Context, twirpLoggerPool *sync.Pool) (context.Context, error) {
|
||||
r := twirpLoggerPool.Get().(*twirpLogger)
|
||||
r.startedAt = time.Now()
|
||||
if deadline, ok := ctx.Deadline(); ok {
|
||||
r.deadline = deadline
|
||||
}
|
||||
r.fields = r.fieldsOrig
|
||||
r.error = nil
|
||||
|
||||
@@ -115,6 +126,9 @@ func loggerResponseSent(ctx context.Context, twirpLoggerPool *sync.Pool) {
|
||||
}
|
||||
|
||||
r.fields = append(r.fields, "duration", time.Since(r.startedAt))
|
||||
if !r.deadline.IsZero() {
|
||||
r.fields = append(r.fields, "timeout", r.deadline.Sub(r.startedAt))
|
||||
}
|
||||
|
||||
if status, ok := twirp.StatusCode(ctx); ok {
|
||||
r.fields = append(r.fields, "status", status)
|
||||
@@ -127,9 +141,8 @@ func loggerResponseSent(ctx context.Context, twirpLoggerPool *sync.Pool) {
|
||||
serviceMethod := "API " + r.service + "." + r.method
|
||||
utils.GetLogger(ctx).WithComponent(utils.ComponentAPI).Infow(serviceMethod, r.fields...)
|
||||
|
||||
r.fields = r.fieldsOrig
|
||||
r.error = nil
|
||||
|
||||
// reset fields and return to pool
|
||||
r.reset()
|
||||
twirpLoggerPool.Put(r)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user