Skip to content

Commit 1fef947

Browse files
committed
fix(whisper): Improves logging in websocket.
1 parent 524115f commit 1fef947

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

src/main/java/org/jitsi/jigasi/transcription/WhisperTranscriptionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public WhisperWebsocket getConnection()
158158
if (socket == null)
159159
{
160160
logger.info(ctx + " Creating a new websocket connection.");
161-
socket = new WhisperWebsocket();
161+
socket = new WhisperWebsocket(ctx);
162162

163163
socket.connect();
164164

src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ public class WhisperWebsocket
155155

156156
private final JSONParser jsonParser = new JSONParser();
157157

158+
private final CallContext ctx;
159+
160+
public WhisperWebsocket(CallContext ctx)
161+
{
162+
this.ctx = ctx;
163+
}
164+
158165
/**
159166
* Creates a connection url by concatenating the websocket
160167
* url with the Connection Id;
@@ -164,7 +171,7 @@ private void generateWebsocketUrl()
164171
websocketUrl = websocketUrlConfig + "/" + connectionId;
165172
if (logger.isDebugEnabled())
166173
{
167-
logger.debug("Whisper URL: " + websocketUrl);
174+
logger.debug(this.ctx + " Whisper URL: " + websocketUrl);
168175
}
169176
}
170177

@@ -193,7 +200,7 @@ private void connectInternal()
193200
try
194201
{
195202
generateWebsocketUrl();
196-
logger.info("Connecting to " + websocketUrl);
203+
logger.info(ctx + " Connecting to " + websocketUrl);
197204
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
198205
if (!privateKey.isEmpty() && !privateKeyName.isEmpty())
199206
{
@@ -206,17 +213,17 @@ private void connectInternal()
206213
wsSession.setIdleTimeout(Duration.ofSeconds(300));
207214
isConnected = true;
208215
reconnecting = false;
209-
logger.info("Successfully connected to " + websocketUrl);
216+
logger.info(ctx + " Successfully connected to " + websocketUrl);
210217
break;
211218
}
212219
catch (Exception e)
213220
{
214221
Statistics.incrementTotalTranscriberConnectionErrors();
215222
int remaining = maxRetryAttempts - attempt;
216223
waitTime *= multiplier;
217-
logger.error("Failed connecting to " + websocketUrl + ". Retrying in "
224+
logger.error(ctx + " Failed connecting to " + websocketUrl + ". Retrying in "
218225
+ waitTime/1000 + "seconds for another " + remaining + " times.");
219-
logger.error(e.toString());
226+
logger.error(ctx + " " + e);
220227
}
221228
attempt++;
222229
synchronized (this)
@@ -232,7 +239,7 @@ private void connectInternal()
232239
if (!isConnected)
233240
{
234241
Statistics.incrementTotalTranscriberConnectionErrors();
235-
logger.error("Failed connecting to " + websocketUrl + ". Nothing to do.");
242+
logger.error(ctx + " Failed connecting to " + websocketUrl + ". Nothing to do.");
236243
}
237244
}
238245

@@ -270,7 +277,7 @@ public void onClose(int statusCode, String reason)
270277

271278
if (isRunning())
272279
{
273-
logger.error("Websocket closed: " + statusCode + " reason:" + reason);
280+
logger.error(ctx + " Websocket closed: " + statusCode + " reason:" + reason);
274281
}
275282

276283
wsSession = null;
@@ -299,7 +306,7 @@ private void stopWebSocketClient()
299306
}
300307
catch (Exception e)
301308
{
302-
logger.error("Error while stopping WebSocketClient", e);
309+
logger.error(ctx + " Error while stopping WebSocketClient", e);
303310
}
304311
}
305312

@@ -313,7 +320,7 @@ public void onMessage(String msg)
313320
}
314321
catch (ParseException e)
315322
{
316-
logger.error("Error parsing message: " + msg, e);
323+
logger.error(ctx + " Error parsing message: " + msg, e);
317324
}
318325
}
319326

@@ -336,7 +343,7 @@ private void onMessageInternal(String msg)
336343
double stability = (double)obj.get("variance");
337344
if (logger.isDebugEnabled())
338345
{
339-
logger.debug("Received result: " + result);
346+
logger.debug(ctx + " Received result: " + result);
340347
}
341348

342349
Instant startTranscription = participantTranscriptionStarts.getOrDefault(participantId, null);
@@ -361,8 +368,8 @@ private void onMessageInternal(String msg)
361368
i++;
362369
if (logger.isDebugEnabled())
363370
{
364-
logger.debug("ParticipantId: " + i + ", " + participantId);
365-
logger.debug("TranscriptionListener: " + l.toString());
371+
logger.debug(ctx + " ParticipantId: " + i + ", " + participantId);
372+
logger.debug(ctx + " TranscriptionListener: " + l.toString());
366373
}
367374
TranscriptionResult tsResult = new TranscriptionResult(
368375
participant,
@@ -390,7 +397,7 @@ public void onError(Throwable cause)
390397
if (!ended() && isRunning())
391398
{
392399
Statistics.incrementTotalTranscriberSendErrors();
393-
logger.error("Error while streaming audio data to transcription service.", cause);
400+
logger.error(ctx + " Error while streaming audio data to transcription service.", cause);
394401
}
395402
}
396403

@@ -399,15 +406,15 @@ private String getLanguage(Participant participant)
399406
String lang = participant.getTranslationLanguage();
400407
if (logger.isDebugEnabled())
401408
{
402-
logger.debug("Translation language is " + lang);
409+
logger.debug(ctx + " Translation language is " + lang);
403410
}
404411
if (lang == null)
405412
{
406413
lang = participant.getSourceLanguage();
407414
}
408415
if (logger.isDebugEnabled())
409416
{
410-
logger.debug("Returned language is " + lang);
417+
logger.debug(ctx + " Returned language is " + lang);
411418
}
412419
return lang;
413420
}
@@ -447,20 +454,21 @@ private void disconnectParticipantInternal(String participantId, Consumer<Boolea
447454
{
448455
participants.remove(participantId);
449456
participantListeners.remove(participantId);
450-
logger.info("Disconnected " + participantId);
457+
logger.info(ctx + " Disconnected " + participantId);
451458
}
452459

453460
if (participants.isEmpty())
454461
{
455-
logger.info("All participants have left, disconnecting from Whisper transcription server.");
462+
logger.info(ctx + " All participants have left, disconnecting from Whisper transcription server.");
456463

457464
try
458465
{
459466
wsSession.getRemote().sendBytes(EOF_MESSAGE);
460467
}
461468
catch (IOException e)
462469
{
463-
logger.error("Error while finalizing websocket connection for participant " + participantId, e);
470+
logger.error(ctx + " Error while finalizing websocket connection for participant "
471+
+ participantId, e);
464472
}
465473

466474
wsSession.disconnect();
@@ -475,21 +483,21 @@ public void sendAudio(String participantId, Participant participant, ByteBuffer
475483
{
476484
if (logger.isDebugEnabled())
477485
{
478-
logger.debug("Sending audio for " + participantId);
486+
logger.debug(ctx + " Sending audio for " + participantId);
479487
}
480488
addParticipantIfNotExists(participantId, participant);
481489
RemoteEndpoint remoteEndpoint = wsSession.getRemote();
482490
if (remoteEndpoint == null)
483491
{
484492
Statistics.incrementTotalTranscriberSendErrors();
485-
logger.error("Failed sending audio for " + participantId + ". Attempting to reconnect.");
493+
logger.error(ctx + " Failed sending audio for " + participantId + ". Attempting to reconnect.");
486494
if (!wsSession.isOpen())
487495
{
488496
reconnect();
489497
}
490498
else
491499
{
492-
logger.warn("Failed sending audio for " + participantId
500+
logger.warn(ctx + " Failed sending audio for " + participantId
493501
+ ". RemoteEndpoint is null but sessions is open.");
494502
}
495503
}
@@ -502,7 +510,7 @@ public void sendAudio(String participantId, Participant participant, ByteBuffer
502510
catch (IOException e)
503511
{
504512
Statistics.incrementTotalTranscriberSendErrors();
505-
logger.error("Failed sending audio for " + participantId + ". " + e);
513+
logger.error(ctx + " Failed sending audio for " + participantId + ". " + e);
506514
}
507515
}
508516
}

0 commit comments

Comments
 (0)