Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Add more internal logs around CDP DevTools communication #14558

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion dotnet/src/webdriver/DevTools/DevToolsSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.
// </copyright>

using OpenQA.Selenium.Internal.Logging;
using System;
using System.Collections.Concurrent;
using System.Globalization;
Expand Down Expand Up @@ -56,6 +57,8 @@ public class DevToolsSession : IDevToolsSession
private DevToolsDomains domains;
private readonly DevToolsOptions options;

private readonly static ILogger logger = Internal.Logging.Log.GetLogger<DevToolsSession>();

/// <summary>
/// Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint.
/// </summary>
Expand Down Expand Up @@ -272,6 +275,11 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains

if (this.connection != null && this.connection.IsActive)
{
if (logger.IsEnabled(LogEventLevel.Trace))
{
logger.Trace($"CDP SND >> {message.CommandId} {message.CommandName}: {commandParameters.ToJsonString()}");
}

LogTrace("Sending {0} {1}: {2}", message.CommandId, message.CommandName, commandParameters.ToString());

string contents = JsonSerializer.Serialize(message);
Expand Down Expand Up @@ -540,6 +548,11 @@ private void MonitorMessageQueue()

private void ProcessMessage(string message)
{
if (logger.IsEnabled(LogEventLevel.Trace))
{
logger.Trace($"CDP RCV << {message}");
}

var messageObject = JsonObject.Parse(message).AsObject();

if (messageObject.TryGetPropertyValue("id", out var idProperty))
Expand Down Expand Up @@ -583,7 +596,22 @@ private void ProcessMessage(string message)
// DevTools commands that may be sent in the body of the attached
// event handler. If thread pool starvation seems to become a problem,
// we can switch to a channel-based queue.
Task.Run(() => OnDevToolsEventReceived(new DevToolsEventReceivedEventArgs(methodParts[0], methodParts[1], eventData)));
Task.Run(() =>
{
try
{
OnDevToolsEventReceived(new DevToolsEventReceivedEventArgs(methodParts[0], methodParts[1], eventData));
}
catch (Exception ex)
{
if (logger.IsEnabled(LogEventLevel.Warn))
{
logger.Warn($"CDP VNT ^^ Unhandled error occured in event handler of '{method}' method. {ex}");
}

throw;
}
});

return;
}
Expand Down
Loading