Skip to content

Commit

Permalink
fix rpc logs
Browse files Browse the repository at this point in the history
  • Loading branch information
lorux0 committed Feb 11, 2025
1 parent 7e75d37 commit cb8fb4a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 36 deletions.
44 changes: 22 additions & 22 deletions Explorer/Assets/DCL/Friends/RPCFriendsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async UniTask SubscribeToIncomingFriendshipEventsAsync(CancellationToken

async UniTask OpenStreamAndProcessUpdatesAsync()
{
Debug.Log($"Friends.RPC.{SUBSCRIBE_FRIENDSHIP_UPDATES_PROCEDURE_NAME}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.{SUBSCRIBE_FRIENDSHIP_UPDATES_PROCEDURE_NAME}");

IUniTaskAsyncEnumerable<FriendshipUpdate> stream =
module!.CallServerStream<FriendshipUpdate>(SUBSCRIBE_FRIENDSHIP_UPDATES_PROCEDURE_NAME,
Expand All @@ -129,7 +129,7 @@ async UniTask OpenStreamAndProcessUpdatesAsync()
{
try
{
Debug.Log($"Friends.RPC.Received.FriendshipUpdate: {response.UpdateCase}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.FriendshipUpdate: {response.UpdateCase}");

switch (response.UpdateCase)
{
Expand Down Expand Up @@ -200,7 +200,7 @@ public async UniTask SubscribeToConnectivityStatusAsync(CancellationToken ct)

async UniTask OpenStreamAndProcessUpdatesAsync()
{
Debug.Log($"Friends.RPC.{SUBSCRIBE_TO_CONNECTIVITY_UPDATES}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.{SUBSCRIBE_TO_CONNECTIVITY_UPDATES}");

IUniTaskAsyncEnumerable<FriendConnectivityUpdate> stream =
module!.CallServerStream<FriendConnectivityUpdate>(SUBSCRIBE_TO_CONNECTIVITY_UPDATES, new Empty());
Expand All @@ -209,7 +209,7 @@ async UniTask OpenStreamAndProcessUpdatesAsync()
{
try
{
Debug.Log($"Friends.RPC.Received.ConnectivityUpdate: {response.Status} for {response.Friend.Address}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.ConnectivityUpdate: {response.Status} for {response.Friend.Address}");

switch (response.Status)
{
Expand Down Expand Up @@ -247,14 +247,14 @@ public async UniTask<PaginatedFriendsResult> GetFriendsAsync(int pageNum, int pa
},
};

Debug.Log($"Friends.RPC.Send.{GET_FRIENDS_PROCEDURE_NAME}: {payload}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Send.{GET_FRIENDS_PROCEDURE_NAME}: {payload}");

var response = await module!
.CallUnaryProcedure<PaginatedFriendsProfilesResponse>(GET_FRIENDS_PROCEDURE_NAME, payload)
.AttachExternalCancellation(ct)
.Timeout(TimeSpan.FromSeconds(TIMEOUT_SECONDS));

Debug.Log($"Friends.RPC.Received.{GET_FRIENDS_PROCEDURE_NAME}: {response}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.{GET_FRIENDS_PROCEDURE_NAME}: {response}");

foreach (var profile in response.Friends)
friendsCache.Add(profile.Address);
Expand Down Expand Up @@ -282,14 +282,14 @@ public async UniTask<PaginatedFriendsResult> GetMutualFriendsAsync(string userId
},
};

Debug.Log($"Friends.RPC.Send.{GET_MUTUAL_FRIENDS_PROCEDURE_NAME}: {payload}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Send.{GET_MUTUAL_FRIENDS_PROCEDURE_NAME}: {payload}");

var response = await module!
.CallUnaryProcedure<PaginatedFriendsProfilesResponse>(GET_MUTUAL_FRIENDS_PROCEDURE_NAME, payload)
.AttachExternalCancellation(ct)
.Timeout(TimeSpan.FromSeconds(TIMEOUT_SECONDS));

Debug.Log($"Friends.RPC.Received.{GET_MUTUAL_FRIENDS_PROCEDURE_NAME}: {response}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.{GET_MUTUAL_FRIENDS_PROCEDURE_NAME}: {response}");

var profiles = ToClientFriendProfiles(response.Friends);

Expand All @@ -308,14 +308,14 @@ public async UniTask<FriendshipStatus> GetFriendshipStatusAsync(string userId, C
},
};

Debug.Log($"Friends.RPC.Send.{GET_FRIENDSHIP_STATUS_PROCEDURE_NAME}: {payload}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Send.{GET_FRIENDSHIP_STATUS_PROCEDURE_NAME}: {payload}");

GetFriendshipStatusResponse response = await module!
.CallUnaryProcedure<GetFriendshipStatusResponse>(GET_FRIENDSHIP_STATUS_PROCEDURE_NAME, payload)
.AttachExternalCancellation(ct)
.Timeout(TimeSpan.FromSeconds(TIMEOUT_SECONDS));

Debug.Log($"Friends.RPC.Received.{GET_FRIENDSHIP_STATUS_PROCEDURE_NAME}: {response}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.{GET_FRIENDSHIP_STATUS_PROCEDURE_NAME}: {response}");

switch (response.ResponseCase)
{
Expand Down Expand Up @@ -357,15 +357,15 @@ public async UniTask<PaginatedFriendRequestsResult> GetReceivedFriendRequestsAsy
},
};

Debug.Log($"Friends.RPC.Send.{GET_RECEIVED_FRIEND_REQUESTS_PROCEDURE_NAME}: {payload}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Send.{GET_RECEIVED_FRIEND_REQUESTS_PROCEDURE_NAME}: {payload}");

PaginatedFriendshipRequestsResponse response = await module!
.CallUnaryProcedure<PaginatedFriendshipRequestsResponse>(GET_RECEIVED_FRIEND_REQUESTS_PROCEDURE_NAME,
payload)
.AttachExternalCancellation(ct)
.Timeout(TimeSpan.FromSeconds(TIMEOUT_SECONDS));

Debug.Log($"Friends.RPC.Received.{GET_RECEIVED_FRIEND_REQUESTS_PROCEDURE_NAME}: {response}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.{GET_RECEIVED_FRIEND_REQUESTS_PROCEDURE_NAME}: {response}");

Profile? myProfile = await selfProfile.ProfileAsync(ct);

Expand Down Expand Up @@ -409,15 +409,15 @@ public async UniTask<PaginatedFriendRequestsResult> GetSentFriendRequestsAsync(i
},
};

Debug.Log($"Friends.RPC.Send.{GET_SENT_FRIEND_REQUESTS_PROCEDURE_NAME}: {payload}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Send.{GET_SENT_FRIEND_REQUESTS_PROCEDURE_NAME}: {payload}");

PaginatedFriendshipRequestsResponse response = await module!
.CallUnaryProcedure<PaginatedFriendshipRequestsResponse>(GET_SENT_FRIEND_REQUESTS_PROCEDURE_NAME,
payload)
.AttachExternalCancellation(ct)
.Timeout(TimeSpan.FromSeconds(TIMEOUT_SECONDS));

Debug.Log($"Friends.RPC.Received.{GET_SENT_FRIEND_REQUESTS_PROCEDURE_NAME}: {response}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.{GET_SENT_FRIEND_REQUESTS_PROCEDURE_NAME}: {response}");

Profile? myProfile = await selfProfile.ProfileAsync(ct);

Expand Down Expand Up @@ -598,22 +598,22 @@ await UniTask.WaitWhile(() => transport!.State == WebSocketState.Connecting,
transport = new WebSocketRpcTransport(new Uri(apiUrl));
client = new RpcClient(transport);

Debug.Log("Friends.RPC.Connecting..");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.RPC.Connecting..");
await transport.ConnectAsync(ct).Timeout(TimeSpan.FromSeconds(CONNECTION_TIMEOUT_SECS));
Debug.Log("Friends.RPC.Connected");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.RPC.Connected");

string authChain = BuildAuthChain();
Debug.Log($"Friends.RPC.Authenticating: {authChain}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Authenticating: {authChain}");
// The service expects the auth-chain in json format within a 30 seconds threshold after connection
await transport.SendMessageAsync(authChain, ct);
Debug.Log("Friends.RPC.Authenticated");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.RPC.Authenticated");

transport.ListenForIncomingData();

Debug.Log("Friends.RPC.Port.Opening..");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.RPC.Port.Opening..");
port = await client.CreatePort("friends");
module = await port.LoadModule(RPC_SERVICE_NAME);
Debug.Log("Friends.RPC.Port.Opened");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.RPC.Port.Opened");

break;
}
Expand Down Expand Up @@ -649,14 +649,14 @@ string BuildAuthChain()
UpsertFriendshipPayload payload,
CancellationToken ct)
{
Debug.Log($"Friends.RPC.Send.{UPDATE_FRIENDSHIP_PROCEDURE_NAME}: {payload}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Send.{UPDATE_FRIENDSHIP_PROCEDURE_NAME}: {payload}");

UpsertFriendshipResponse response = await module!
.CallUnaryProcedure<UpsertFriendshipResponse>(UPDATE_FRIENDSHIP_PROCEDURE_NAME, payload)
.AttachExternalCancellation(ct)
.Timeout(TimeSpan.FromSeconds(TIMEOUT_SECONDS));

Debug.Log($"Friends.RPC.Received.{UPDATE_FRIENDSHIP_PROCEDURE_NAME}: {response}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.RPC.Received.{UPDATE_FRIENDSHIP_PROCEDURE_NAME}: {response}");

return response.ResponseCase switch
{
Expand Down
28 changes: 14 additions & 14 deletions Explorer/Assets/DCL/Friends/WebSocketRpcTransport.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Cysharp.Threading.Tasks;
using DCL.Diagnostics;
using rpc_csharp.transport;
using System;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using UnityEngine;
using Utility;

namespace DCL.Friends
Expand Down Expand Up @@ -39,10 +39,10 @@ public void Dispose()

try
{
Debug.Log($"Friends.WebSocket.Disposing..");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Disposing..");
webSocket.Abort();
webSocket.Dispose();
Debug.Log($"Friends.WebSocket.Disposed");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Disposed");
}
catch (ObjectDisposedException) { }
}
Expand All @@ -52,9 +52,9 @@ public async UniTask ConnectAsync(CancellationToken ct)
if (State is WebSocketState.Open or WebSocketState.Connecting)
throw new Exception("Web socket already connected");

Debug.Log($"Friends.WebSocket.Connecting: {uri}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Connecting: {uri}");
await webSocket.ConnectAsync(uri, ct);
Debug.Log("Friends.WebSocket.Connected");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.WebSocket.Connected");

OnConnectEvent?.Invoke();
}
Expand All @@ -75,7 +75,7 @@ async UniTaskVoid ListenAndProcessIncomingDataAsync(CancellationToken ct)
{
WebSocketReceiveResult result = await webSocket.ReceiveAsync(receiveBuffer, ct);

Debug.Log($"Friends.WebSocket.Received: Data size {result.Count}, data type: {result.MessageType}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Received: Data size {result.Count}, data type: {result.MessageType}");

if (result.MessageType is WebSocketMessageType.Text or WebSocketMessageType.Binary)
{
Expand Down Expand Up @@ -106,13 +106,13 @@ public async UniTask SendMessageAsync(byte[] data, CancellationToken ct)
{
try
{
Debug.Log($"Friends.WebSocket.Sending: data size {data.Length}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Sending: data size {data.Length}");
await webSocket.SendAsync(data, WebSocketMessageType.Binary, true, ct);
Debug.Log($"Friends.WebSocket.Sent: data size {data.Length}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Sent: data size {data.Length}");
}
catch (WebSocketException e)
{
Debug.Log($"Friends.WebSocket.Send.Error: {e.Message}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Send.Error: {e.Message}");
OnErrorEvent?.Invoke(e.Message);
}
}
Expand All @@ -121,13 +121,13 @@ public async UniTask SendMessageAsync(string data, CancellationToken ct)
{
try
{
Debug.Log($"Friends.WebSocket.Sending: data size {data.Length}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Sending: data size {data.Length}");
await webSocket.SendAsync(Encoding.UTF8.GetBytes(data), WebSocketMessageType.Text, true, ct);
Debug.Log($"Friends.WebSocket.Sent: data size {data.Length}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Sent: data size {data.Length}");
}
catch (WebSocketException e)
{
Debug.Log($"Friends.WebSocket.Send.Error: {e.Message}");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), $"Friends.WebSocket.Send.Error: {e.Message}");
OnErrorEvent?.Invoke(e.Message);
}
}
Expand All @@ -139,9 +139,9 @@ public async UniTask CloseAsync(CancellationToken ct)
{
if (State is WebSocketState.Open or WebSocketState.CloseReceived)
{
Debug.Log("Friends.WebSocket.Disconnecting..");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.WebSocket.Disconnecting..");
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", ct);
Debug.Log("Friends.WebSocket.Disconnected");
ReportHub.Log(new ReportData(ReportCategory.FRIENDS), "Friends.WebSocket.Disconnected");
OnCloseEvent?.Invoke();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ MonoBehaviour:
Severity: 4
- Category: ALWAYS
Severity: 1
- Category: FRIENDS
Severity: 0
- Category: FRIENDS
Severity: 4
- Category: FRIENDS
Severity: 1
- Category: FRIENDS
Severity: 2
- Category: FRIENDS
Severity: 3
sentryMatrix:
entries: []
debounceEnabled: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ MonoBehaviour:
Severity: 4
- Category: ALWAYS
Severity: 1
- Category: FRIENDS
Severity: 4
- Category: FRIENDS
Severity: 1
- Category: FRIENDS
Severity: 0
- Category: FRIENDS
Severity: 2
- Category: FRIENDS
Severity: 3
sentryMatrix:
entries:
- Category: AUDIO_SOURCES
Expand Down

0 comments on commit cb8fb4a

Please sign in to comment.