Skip to content

Commit

Permalink
1. Truncated Arguments length to 128
Browse files Browse the repository at this point in the history
2. Removed arguments from InvokeMethodStop and SendRequestStop events as they can be correlated with their Start events using request Id
3. Added Opcode and Task in Event attribute
  • Loading branch information
Shyam-Gupta committed Aug 16, 2019
1 parent d8eb3e6 commit 47a39ad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
15 changes: 11 additions & 4 deletions src/StreamJsonRpc/JsonRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,13 +1182,13 @@ protected async Task<TResult> InvokeCoreAsync<TResult>(long? id, string targetNa

if (JsonRpcEventSource.Instance.IsEnabled())
{
responseDetails = $"Success!, Result.Id = \"{result.Id}\"";
responseDetails = $"Success!";
}
}

if (JsonRpcEventSource.Instance.IsEnabled())
{
JsonRpcEventSource.Instance.SendRequestStop($"ResponseDetails: {responseDetails}; RequestDetails: Id: \"{request.Id}\", Method: \"{request.Method}\", Arguments: \"{JsonRpcEventSource.GetArgumentsString(request.Arguments)}\"");
JsonRpcEventSource.Instance.SendRequestStop($"ResponseDetails: {responseDetails}; RequestDetails: Id: \"{request.Id}\", Method: \"{request.Method}\"");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -1578,7 +1578,7 @@ private async ValueTask<JsonRpcMessage> DispatchIncomingRequestAsync(JsonRpcRequ
{
if (request.IsResponseExpected)
{
JsonRpcEventSource.Instance.InvokeMethodStop($"TargetMethod = {targetMethod}; Result: {result}; RequestDetails: Id = \"{request.Id}\", Method = \"{request.Method}\", Arguments = \"{JsonRpcEventSource.GetArgumentsString(request.Arguments)}\"");
JsonRpcEventSource.Instance.InvokeMethodStop($"TargetMethod = {targetMethod}; Result: {result}; RequestDetails: Id = \"{request.Id}\", Method = \"{request.Method}\"");
}
else
{
Expand Down Expand Up @@ -1668,7 +1668,14 @@ private JsonRpcMessage HandleInvocationTaskResult(JsonRpcRequest request, Task t

if (JsonRpcEventSource.Instance.IsEnabled())
{
JsonRpcEventSource.Instance.InvokeMethodStop($"Result: Id = \"{request.Id}\", Method = \"{request.Method}\", IsNotification = \"{request.IsNotification}\", Arguments: \"{JsonRpcEventSource.GetArgumentsString(request.Arguments)}\"");
if (request.IsResponseExpected)
{
JsonRpcEventSource.Instance.InvokeMethodStop($"Result: Id = \"{request.Id}\", Method = \"{request.Method}\"");
}
else
{
JsonRpcEventSource.Instance.InvokeNotificationStop($"Result: Method = \"{request.Method}\", Arguments: \"{JsonRpcEventSource.GetArgumentsString(request.Arguments)}\"");
}
}

return new JsonRpcResult
Expand Down
47 changes: 28 additions & 19 deletions src/StreamJsonRpc/JsonRpcEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal sealed class JsonRpcEventSource : EventSource
/// Send Notification start.
/// </summary>
/// <param name="message">Notification details.</param>
[Event(SendNotificationStartEvent, Level = EventLevel.Verbose)]
[Event(SendNotificationStartEvent, Task = Tasks.SendNotification, Opcode = EventOpcode.Start, Level = EventLevel.Verbose)]
public void SendNotificationStart(string message)
{
this.WriteEvent(SendNotificationStartEvent, message);
Expand All @@ -79,7 +79,7 @@ public void SendNotificationStart(string message)
/// Send Notification end.
/// </summary>
/// <param name="message">Notification details.</param>
[Event(SendNotificationStopEvent, Level = EventLevel.Verbose)]
[Event(SendNotificationStopEvent, Task = Tasks.SendNotification, Opcode = EventOpcode.Stop, Level = EventLevel.Verbose)]
public void SendNotificationStop(string message)
{
this.WriteEvent(SendNotificationStopEvent, message);
Expand All @@ -89,7 +89,7 @@ public void SendNotificationStop(string message)
/// Send Request start.
/// </summary>
/// <param name="message">Request details.</param>
[Event(SendRequestStartEvent, Level = EventLevel.Verbose)]
[Event(SendRequestStartEvent, Task = Tasks.SendRequest, Opcode = EventOpcode.Start, Level = EventLevel.Verbose)]
public void SendRequestStart(string message)
{
this.WriteEvent(SendRequestStartEvent, message);
Expand All @@ -99,7 +99,7 @@ public void SendRequestStart(string message)
/// Send Request end.
/// </summary>
/// <param name="message">Request details.</param>
[Event(SendRequestStopEvent, Level = EventLevel.Verbose)]
[Event(SendRequestStopEvent, Task = Tasks.SendRequest, Opcode = EventOpcode.Stop, Level = EventLevel.Verbose)]
public void SendRequestStop(string message)
{
this.WriteEvent(SendRequestStopEvent, message);
Expand All @@ -109,7 +109,7 @@ public void SendRequestStop(string message)
/// Invoke Method start.
/// </summary>
/// <param name="message">Request and method details.</param>
[Event(InvokeMethodStartEvent, Level = EventLevel.Verbose)]
[Event(InvokeMethodStartEvent, Task = Tasks.InvokeMethod, Opcode = EventOpcode.Start, Level = EventLevel.Verbose)]
public void InvokeMethodStart(string message)
{
this.WriteEvent(InvokeMethodStartEvent, message);
Expand All @@ -119,7 +119,7 @@ public void InvokeMethodStart(string message)
/// Invoke Method end.
/// </summary>
/// <param name="message">Request and method details.</param>
[Event(InvokeMethodStopEvent, Level = EventLevel.Verbose)]
[Event(InvokeMethodStopEvent, Task = Tasks.InvokeMethod, Opcode = EventOpcode.Stop, Level = EventLevel.Verbose)]
public void InvokeMethodStop(string message)
{
this.WriteEvent(InvokeMethodStopEvent, message);
Expand All @@ -129,7 +129,7 @@ public void InvokeMethodStop(string message)
/// Cancel Request start.
/// </summary>
/// <param name="message">Cancellation message.</param>
[Event(CancelRequestStartEvent, Level = EventLevel.Verbose)]
[Event(CancelRequestStartEvent, Task = Tasks.CancelRequest, Opcode = EventOpcode.Start, Level = EventLevel.Verbose)]
public void CancelRequestStart(string message)
{
this.WriteEvent(CancelRequestStartEvent, message);
Expand All @@ -139,7 +139,7 @@ public void CancelRequestStart(string message)
/// Cancel Request end.
/// </summary>
/// <param name="message">Cancellation message.</param>
[Event(CancelRequestStopEvent, Level = EventLevel.Verbose)]
[Event(CancelRequestStopEvent, Task = Tasks.CancelRequest, Opcode = EventOpcode.Stop, Level = EventLevel.Verbose)]
public void CancelRequestStop(string message)
{
this.WriteEvent(CancelRequestStopEvent, message);
Expand All @@ -149,7 +149,7 @@ public void CancelRequestStop(string message)
/// Invoke Notification.
/// </summary>
/// <param name="message">Details of the Notification.</param>
[Event(InvokeNotificationStartEvent, Level = EventLevel.Verbose)]
[Event(InvokeNotificationStartEvent, Task = Tasks.InvokeNotification, Opcode = EventOpcode.Start, Level = EventLevel.Verbose)]
public void InvokeNotificationStart(string message)
{
this.WriteEvent(InvokeNotificationStartEvent, message);
Expand All @@ -159,14 +159,14 @@ public void InvokeNotificationStart(string message)
/// Notification completed.
/// </summary>
/// <param name="message">Details of the Notification.</param>
[Event(InvokeNotificationStopEvent, Level = EventLevel.Verbose)]
[Event(InvokeNotificationStopEvent, Task = Tasks.InvokeNotification, Opcode = EventOpcode.Stop, Level = EventLevel.Verbose)]
public void InvokeNotificationStop(string message)
{
this.WriteEvent(InvokeNotificationStopEvent, message);
}

/// <summary>
/// Creates a string representation of arguments of max 1024 characters for logging.
/// Creates a string representation of arguments of max 200 characters for logging.
/// </summary>
/// <param name="arguments">A single argument or an array of arguments.</param>
/// <returns>String representation of first argument only.</returns>
Expand All @@ -177,7 +177,7 @@ internal static string GetArgumentsString(object arguments)
return string.Empty;
}

const int maxLength = 1024;
const int maxLength = 128;

if (arguments is object[] args)
{
Expand All @@ -186,10 +186,10 @@ internal static string GetArgumentsString(object arguments)
{
for (int i = 0; i < args.Length; ++i)
{
stringBuilder.Append($"arg{i}: {args[i].ToString()}, ");
stringBuilder.Append($"arg{i}: {args[i]}, ");
if (stringBuilder.Length > maxLength)
{
return $"{stringBuilder.ToString().Substring(0, maxLength)}...(truncated)";
return $"{stringBuilder.ToString(0, maxLength)}...(truncated)";
}
}
}
Expand Down Expand Up @@ -219,14 +219,23 @@ internal static string GetErrorDetails(JsonRpcError error)
if (error.Error != null)
{
errorDetails += $"Error.Code = \"{error.Error.Code}\", ";

if (!string.IsNullOrEmpty(error.Error.Message))
{
errorDetails += $"Error.Message = \"{error.Error.Message}\"";
}
}

return errorDetails;
}

/// <summary>
/// Names of constants in this class make up the middle term in the event name
/// E.g.: Microsoft-VisualStudio-StreamJsonRpc/InvokeMethod/Start.
/// </summary>
/// <remarks>Name of this class is important for EventSource.</remarks>
public static class Tasks
{
public const EventTask SendNotification = (EventTask)1;
public const EventTask SendRequest = (EventTask)2;
public const EventTask InvokeMethod = (EventTask)3;
public const EventTask CancelRequest = (EventTask)4;
public const EventTask InvokeNotification = (EventTask)5;
}
}
}

0 comments on commit 47a39ad

Please sign in to comment.