Use participant and room specific loggers (#252)
This commit is contained in:
+27
-15
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
@@ -225,8 +226,11 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
||||
pv := types.ProtocolVersion(pi.Client.Protocol)
|
||||
rtcConf := *r.rtcConfig
|
||||
rtcConf.SetBufferFactory(room.GetBufferFactor())
|
||||
sid := utils.NewGuid(utils.ParticipantPrefix)
|
||||
pLogger := rtc.LoggerWithParticipant(room.Logger, pi.Identity, sid)
|
||||
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
|
||||
Identity: pi.Identity,
|
||||
SID: sid,
|
||||
Config: &rtcConf,
|
||||
Sink: responseSink,
|
||||
AudioConfig: r.config.Audio,
|
||||
@@ -235,7 +239,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
||||
ThrottleConfig: r.config.RTC.PLIThrottle,
|
||||
EnabledCodecs: room.Room.EnabledCodecs,
|
||||
Hidden: pi.Hidden,
|
||||
Logger: room.Logger,
|
||||
Logger: pLogger,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Errorw("could not create participant", err)
|
||||
@@ -254,11 +258,11 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
||||
AutoSubscribe: pi.AutoSubscribe,
|
||||
}
|
||||
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
|
||||
logger.Errorw("could not join room", err)
|
||||
pLogger.Errorw("could not join room", err)
|
||||
return
|
||||
}
|
||||
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
|
||||
logger.Errorw("could not store participant", err)
|
||||
pLogger.Errorw("could not store participant", err)
|
||||
}
|
||||
// update roomstore with new numParticipants
|
||||
if !participant.Hidden() {
|
||||
@@ -271,7 +275,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
||||
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto())
|
||||
participant.OnClose(func(p types.Participant) {
|
||||
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
|
||||
logger.Errorw("could not delete participant", err)
|
||||
pLogger.Errorw("could not delete participant", err)
|
||||
}
|
||||
// update roomstore with new numParticipants
|
||||
if !participant.Hidden() {
|
||||
@@ -346,6 +350,11 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
||||
}()
|
||||
defer rtc.Recover()
|
||||
|
||||
pLogger := rtc.LoggerWithParticipant(
|
||||
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), room.Name()),
|
||||
participant.Identity(), participant.ID(),
|
||||
)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Millisecond * 50):
|
||||
@@ -361,7 +370,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
||||
}
|
||||
|
||||
req := obj.(*livekit.SignalRequest)
|
||||
if err := rtc.HandleParticipantSignal(room, participant, req); err != nil {
|
||||
if err := rtc.HandleParticipantSignal(room, participant, req, pLogger); err != nil {
|
||||
// more specific errors are already logged
|
||||
// treat errors returned as fatal
|
||||
return
|
||||
@@ -382,22 +391,27 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
|
||||
}
|
||||
|
||||
participant := room.GetParticipant(identity)
|
||||
pLogger := rtc.LoggerWithParticipant(
|
||||
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
|
||||
identity,
|
||||
"",
|
||||
)
|
||||
|
||||
switch rm := msg.Message.(type) {
|
||||
case *livekit.RTCNodeMessage_RemoveParticipant:
|
||||
if participant == nil {
|
||||
return
|
||||
}
|
||||
logger.Infow("removing participant", "room", roomName, "participant", identity)
|
||||
pLogger.Infow("removing participant")
|
||||
room.RemoveParticipant(identity)
|
||||
case *livekit.RTCNodeMessage_MuteTrack:
|
||||
if participant == nil {
|
||||
return
|
||||
}
|
||||
logger.Debugw("setting track muted", "room", roomName, "participant", identity,
|
||||
pLogger.Debugw("setting track muted",
|
||||
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
|
||||
if !rm.MuteTrack.Muted && !r.config.Room.EnableRemoteUnmute {
|
||||
logger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
||||
pLogger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
||||
return
|
||||
}
|
||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted, true)
|
||||
@@ -405,7 +419,7 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
|
||||
if participant == nil {
|
||||
return
|
||||
}
|
||||
logger.Debugw("updating participant", "room", roomName, "participant", identity)
|
||||
pLogger.Debugw("updating participant")
|
||||
if rm.UpdateParticipant.Metadata != "" {
|
||||
participant.SetMetadata(rm.UpdateParticipant.Metadata)
|
||||
}
|
||||
@@ -421,23 +435,21 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName, identity s
|
||||
if participant == nil {
|
||||
return
|
||||
}
|
||||
logger.Debugw("updating participant subscriptions", "room", roomName, "participant", identity)
|
||||
pLogger.Debugw("updating participant subscriptions")
|
||||
if err := room.UpdateSubscriptions(participant, rm.UpdateSubscriptions.TrackSids, rm.UpdateSubscriptions.Subscribe); err != nil {
|
||||
logger.Warnw("could not update subscription", err,
|
||||
"participant", participant.Identity(),
|
||||
"pID", participant.ID(),
|
||||
pLogger.Warnw("could not update subscription", err,
|
||||
"tracks", rm.UpdateSubscriptions.TrackSids,
|
||||
"subscribe", rm.UpdateSubscriptions.Subscribe)
|
||||
}
|
||||
case *livekit.RTCNodeMessage_SendData:
|
||||
logger.Debugw("SendData", "message", rm)
|
||||
pLogger.Debugw("SendData", "size", len(rm.SendData.Data))
|
||||
up := &livekit.UserPacket{
|
||||
Payload: rm.SendData.Data,
|
||||
DestinationSids: rm.SendData.DestinationSids,
|
||||
}
|
||||
room.SendDataPacket(up, rm.SendData.Kind)
|
||||
case *livekit.RTCNodeMessage_UpdateRoomMetadata:
|
||||
logger.Debugw("updating room", "room", roomName)
|
||||
pLogger.Debugw("updating room")
|
||||
room.SetMetadata(rm.UpdateRoomMetadata.Metadata)
|
||||
}
|
||||
}
|
||||
|
||||
+13
-14
@@ -9,8 +9,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/livekit"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
@@ -144,10 +144,14 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
pLogger := rtc.LoggerWithParticipant(
|
||||
rtc.LoggerWithRoom(logger.Logger(logger.GetLogger()), roomName),
|
||||
pi.Identity, "",
|
||||
)
|
||||
done := make(chan struct{})
|
||||
// function exits when websocket terminates, it'll close the event reading off of response sink as well
|
||||
defer func() {
|
||||
logger.Infow("server closing WS connection", "participant", pi.Identity, "connID", connId)
|
||||
pLogger.Infow("server closing WS connection", "connID", connId)
|
||||
reqSink.Close()
|
||||
close(done)
|
||||
}()
|
||||
@@ -156,7 +160,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "error", "upgrade").Add(1)
|
||||
logger.Warnw("could not upgrade to WS", err)
|
||||
pLogger.Warnw("could not upgrade to WS", err)
|
||||
handleError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -166,11 +170,9 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
prometheus.ServiceOperationCounter.WithLabelValues("signal_ws", "success", "").Add(1)
|
||||
logger.Infow("new client WS connected",
|
||||
pLogger.Infow("new client WS connected",
|
||||
"connID", connId,
|
||||
"roomID", rm.Sid,
|
||||
"room", rm.Name,
|
||||
"participant", pi.Identity,
|
||||
)
|
||||
|
||||
// handle responses
|
||||
@@ -187,22 +189,20 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
case msg := <-resSource.ReadChan():
|
||||
if msg == nil {
|
||||
logger.Infow("source closed connection",
|
||||
"participant", pi.Identity,
|
||||
pLogger.Infow("source closed connection",
|
||||
"connID", connId)
|
||||
return
|
||||
}
|
||||
res, ok := msg.(*livekit.SignalResponse)
|
||||
if !ok {
|
||||
logger.Errorw("unexpected message type", nil,
|
||||
pLogger.Errorw("unexpected message type", nil,
|
||||
"type", fmt.Sprintf("%T", msg),
|
||||
"participant", pi.Identity,
|
||||
"connID", connId)
|
||||
continue
|
||||
}
|
||||
|
||||
if err = sigConn.WriteResponse(res); err != nil {
|
||||
logger.Warnw("error writing to websocket", err)
|
||||
pLogger.Warnw("error writing to websocket", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -218,13 +218,12 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
websocket.IsCloseError(err, websocket.CloseAbnormalClosure, websocket.CloseGoingAway, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
|
||||
return
|
||||
} else {
|
||||
logger.Errorw("error reading from websocket", err)
|
||||
pLogger.Errorw("error reading from websocket", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := reqSink.WriteMessage(req); err != nil {
|
||||
logger.Warnw("error writing to request sink", err,
|
||||
"participant", pi.Identity,
|
||||
pLogger.Warnw("error writing to request sink", err,
|
||||
"connID", connId)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user