Log timeout in API. (#4231)
* Log timeout in API. * make a reset function
This commit is contained in:
@@ -2867,6 +2867,7 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
|||||||
"falling back to alternative video codec",
|
"falling back to alternative video codec",
|
||||||
"codec", mimeType,
|
"codec", mimeType,
|
||||||
"altCodec", altCodec,
|
"altCodec", altCodec,
|
||||||
|
"enabledPublishCodecs", logger.ProtoSlice(p.enabledPublishCodecs),
|
||||||
"trackID", ti.Sid,
|
"trackID", ti.Sid,
|
||||||
)
|
)
|
||||||
// select an alternative MIME type that's generally supported
|
// 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",
|
"falling back to alternative audio codec",
|
||||||
"codec", mimeType,
|
"codec", mimeType,
|
||||||
"altCodec", altCodec,
|
"altCodec", altCodec,
|
||||||
|
"enabledPublishCodecs", logger.ProtoSlice(p.enabledPublishCodecs),
|
||||||
"trackID", ti.Sid,
|
"trackID", ti.Sid,
|
||||||
)
|
)
|
||||||
// select an alternative MIME type that's generally supported
|
// select an alternative MIME type that's generally supported
|
||||||
|
|||||||
+16
-3
@@ -70,6 +70,14 @@ type twirpLogger struct {
|
|||||||
fieldsOrig []any
|
fieldsOrig []any
|
||||||
fields []any
|
fields []any
|
||||||
startedAt time.Time
|
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) {
|
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) {
|
func loggerRequestReceived(ctx context.Context, twirpLoggerPool *sync.Pool) (context.Context, error) {
|
||||||
r := twirpLoggerPool.Get().(*twirpLogger)
|
r := twirpLoggerPool.Get().(*twirpLogger)
|
||||||
r.startedAt = time.Now()
|
r.startedAt = time.Now()
|
||||||
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
|
r.deadline = deadline
|
||||||
|
}
|
||||||
r.fields = r.fieldsOrig
|
r.fields = r.fieldsOrig
|
||||||
r.error = nil
|
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))
|
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 {
|
if status, ok := twirp.StatusCode(ctx); ok {
|
||||||
r.fields = append(r.fields, "status", status)
|
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
|
serviceMethod := "API " + r.service + "." + r.method
|
||||||
utils.GetLogger(ctx).WithComponent(utils.ComponentAPI).Infow(serviceMethod, r.fields...)
|
utils.GetLogger(ctx).WithComponent(utils.ComponentAPI).Infow(serviceMethod, r.fields...)
|
||||||
|
|
||||||
r.fields = r.fieldsOrig
|
// reset fields and return to pool
|
||||||
r.error = nil
|
r.reset()
|
||||||
|
|
||||||
twirpLoggerPool.Put(r)
|
twirpLoggerPool.Put(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user