Log timeout in API. (#4231)

* Log timeout in API.

* make a reset function
This commit is contained in:
Raja Subramanian authored and GitHub committed 2026-01-12 11:22:39 +05:30
1 parent 541a7d6c5b
commit ac20ccda53
2 files changed
+18 -3

No files matched your search

+2
View File
@@ -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
View File
@@ -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)
}