Table of Contents

Class WebDriverBiDiEventSource

Namespace
WebDriverBiDi
Assembly
WebDriverBiDi.dll

EventSource for WebDriver BiDi protocol instrumentation. This EventSource provides structured diagnostic events for monitoring, tracing, and troubleshooting WebDriver BiDi operations.

[EventSource(Name = "WebDriverBiDi")]
public sealed class WebDriverBiDiEventSource : EventSource, IDisposable
Inheritance
WebDriverBiDiEventSource
Implements
Inherited Members

Remarks

This EventSource can be consumed by:

  • EventListener (custom in-process listeners)
  • ETW (Event Tracing for Windows)
  • EventPipe (cross-platform event collection)
  • dotnet-trace (CLI diagnostics tool)
  • OpenTelemetry (via EventSource integration)
  • Application Insights, Dynatrace, etc. (via bridges)

Usage Examples:

Example 1: Custom EventListener

public class WebDriverBiDiEventListener : EventListener
{
    protected override void OnEventSourceCreated(EventSource source)
    {
        if (source.Name == "WebDriverBiDi")
        {
            EnableEvents(source, EventLevel.Informational);
        }
    }

    protected override void OnEventWritten(EventWrittenEventArgs eventData)
    {
        // Payload[0] and [1] are the connection and session identifiers on every event except
        // AsyncHandlerTaskCount; the values specific to the event follow them.
        string connectionId = eventData.Payload?.Count > 0 ? eventData.Payload[0]?.ToString() ?? string.Empty : string.Empty;
        string detail = eventData.Payload?.Count > 2 ? eventData.Payload[2]?.ToString() ?? string.Empty : string.Empty;
        Console.WriteLine($"[{eventData.Level}] {connectionId} {eventData.EventName}: {detail}");
    }
}

Example 2: dotnet-trace

dotnet-trace collect --providers WebDriverBiDi --process-id <pid>

Example 3: EventPipe from another process

// Microsoft.Diagnostics.NETCore.Client, from the target process's ID:
DiagnosticsClient client = new(processId);
using EventPipeSession session = client.StartEventPipeSession(new EventPipeProvider("WebDriverBiDi", EventLevel.Informational));
// Read session.EventStream with TraceEvent...

Fields

RaiseEvent

The singleton instance of the WebDriverBiDiEventSource.

public static readonly WebDriverBiDiEventSource RaiseEvent

Field Value

WebDriverBiDiEventSource

Methods

AsyncHandlerTaskCount(int)

Logs the current count of in-flight asynchronous event handler tasks.

[Event(23, Level = EventLevel.Verbose, Message = "In-flight async handler tasks: {0}")]
public void AsyncHandlerTaskCount(int inFlightCount)

Parameters

inFlightCount int

The number of in-flight asynchronous handler tasks.

Remarks

This counter tracks handlers registered with RunHandlerAsynchronously whose returned Task has not yet completed. A persistently growing value indicates that asynchronous handlers are accumulating faster than they complete; this may precede memory pressure and should prompt investigation of handler duration or event rate. The counter is process-global across all BiDiDriver instances, and so carries no connection or session identifier, unlike every other event on this source.

CanceledCommandResponseDiscarded(string, string, long, string, CommandCancellationReason, long)

Raises the event indicating that a response was received for a command the local end had already stopped waiting for (because it timed out, was canceled, or the connection was closed), and that the response was discarded.

[NonEvent]
public void CanceledCommandResponseDiscarded(string connectionId, string sessionId, long commandId, string method, CommandCancellationReason reason, long millisecondsSinceCancellation)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

commandId long

The ID of the canceled command.

method string

The protocol method name of the canceled command.

reason CommandCancellationReason

The reason the command was canceled.

millisecondsSinceCancellation long

The time, in milliseconds, between the cancellation and the arrival of the response.

CommandCompleted(string, string, long, string, long)

Logs when a command response is received from the remote end.

[NonEvent]
public void CommandCompleted(string connectionId, string sessionId, long commandId, string method, long elapsedMilliseconds)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

commandId long

The unique identifier for the command.

method string

The command method name.

elapsedMilliseconds long

The elapsed time in milliseconds.

CommandError(string, string, long, string, ErrorCode, string, string)

Logs when a command receives an error response from the remote end.

[NonEvent]
public void CommandError(string connectionId, string sessionId, long commandId, string method, ErrorCode errorCode, string errorType, string errorMessage)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

commandId long

The unique identifier for the command.

method string

The command method name.

errorCode ErrorCode

The protocol error code returned by the remote end.

errorType string

The error type returned by the remote end.

errorMessage string

The error message returned by the remote end.

CommandSendFailed(string, string, long, string, string, string, long)

Logs when a command fails before it can be successfully transmitted.

[NonEvent]
public void CommandSendFailed(string connectionId, string sessionId, long commandId, string method, string failureType, string failureMessage, long elapsedMilliseconds)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

commandId long

The unique identifier for the command.

method string

The command method name.

failureType string

The .NET exception type describing the send failure.

failureMessage string

The failure message.

elapsedMilliseconds long

The elapsed time in milliseconds before the send failed.

CommandSending(string, string, long, string)

Logs when a command is being sent to the remote end.

[NonEvent]
public void CommandSending(string connectionId, string sessionId, long commandId, string method)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

commandId long

The unique identifier for the command.

method string

The command method name.

CommandTimeout(string, string, long, string, long)

Logs when a command times out waiting for a response.

[NonEvent]
public void CommandTimeout(string connectionId, string sessionId, long commandId, string method, long timeoutMilliseconds)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

commandId long

The unique identifier for the command.

method string

The command method name.

timeoutMilliseconds long

The timeout duration in milliseconds.

ConnectionClosed(string, string)

Logs when a connection has been closed.

[Event(4, Level = EventLevel.Informational, Message = "[{0}/{1}] Connection closed")]
public void ConnectionClosed(string connectionId, string sessionId)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

ConnectionClosing(string, string, string)

Logs when a connection is being closed.

[Event(3, Level = EventLevel.Informational, Message = "[{0}/{1}] Closing connection: {2}")]
public void ConnectionClosing(string connectionId, string sessionId, string reason)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

reason string

The reason for closing the connection.

ConnectionError(string, string, string)

Logs when a connection error occurs.

[Event(5, Level = EventLevel.Error, Message = "[{0}/{1}] Connection error: {2}")]
public void ConnectionError(string connectionId, string sessionId, string errorMessage)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

errorMessage string

The error message.

ConnectionOpened(string, string, string)

Logs when a connection has been successfully opened.

[Event(2, Level = EventLevel.Informational, Message = "[{0}/{1}] Connection opened to {2}")]
public void ConnectionOpened(string connectionId, string sessionId, string url)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

url string

The URL that was connected to.

ConnectionOpening(string, string, string)

Logs when a connection is being opened to the remote end.

[Event(1, Level = EventLevel.Informational, Message = "[{0}/{1}] Opening connection to {2}")]
public void ConnectionOpening(string connectionId, string sessionId, string url)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

url string

The URL being connected to.

CustomEventRegistered(string, string, string, string)

Logs when a custom event type is registered with the driver.

[Event(20, Level = EventLevel.Informational, Message = "[{0}/{1}] Custom event registered: {2} -> {3}")]
public void CustomEventRegistered(string connectionId, string sessionId, string eventName, string eventType)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

eventName string

The name of the custom event.

eventType string

The .NET type handling the event.

CustomModuleRegistered(string, string, string)

Logs when a custom module is registered with the driver.

[Event(19, Level = EventLevel.Informational, Message = "[{0}/{1}] Custom module registered: {2}")]
public void CustomModuleRegistered(string connectionId, string sessionId, string moduleName)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

moduleName string

The name of the custom module.

EventHandlerError(string, string, string, string)

Logs when an error occurs in an event handler.

[Event(15, Level = EventLevel.Warning, Message = "[{0}/{1}] Event handler error for {2}: {3}")]
public void EventHandlerError(string connectionId, string sessionId, string eventMethod, string errorMessage)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

eventMethod string

The event method name.

errorMessage string

The error message from the exception.

EventReceived(string, string, string)

Logs when an event is received from the remote end.

[Event(10, Level = EventLevel.Verbose, Message = "[{0}/{1}] Event received: {2}")]
public void EventReceived(string connectionId, string sessionId, string eventMethod)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

eventMethod string

The event method name.

MessageStatistics(string, string, long, long, long, long)

Logs detailed message processing statistics.

[Event(21, Level = EventLevel.Verbose, Message = "[{0}/{1}] Stats: sent={2}, received={3}, events={4}, errors={5}")]
public void MessageStatistics(string connectionId, string sessionId, long messagesSent, long messagesReceived, long eventsReceived, long errorsReceived)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

messagesSent long

Number of commands sent during the session.

messagesReceived long

Number of command responses received during the session.

eventsReceived long

Number of events received during the session.

errorsReceived long

Number of error responses received during the session.

Remarks

Raised when a session of the transport ends, by disconnection or by loss of the connection, with the counts for that session alone. A message counts only once it has been processed, so a message still waiting to be processed when the snapshot is taken is not included.

PendingCommandCount(string, string, int)

Logs the current count of pending commands waiting for responses.

[Event(16, Level = EventLevel.Verbose, Message = "[{0}/{1}] Pending commands: {2}")]
public void PendingCommandCount(string connectionId, string sessionId, int pendingCount)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

pendingCount int

The number of pending commands.

ProtocolError(string, string, string, string)

Logs when a protocol error occurs during message processing.

[Event(14, Level = EventLevel.Error, Message = "[{0}/{1}] Protocol error: {2} (message: {3})")]
public void ProtocolError(string connectionId, string sessionId, string errorMessage, string messageSnippet)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

errorMessage string

The error message.

messageSnippet string

A snippet of the problematic message (truncated for safety).

TransportStarted(string, string)

Logs when the transport starts processing messages.

[Event(17, Level = EventLevel.Informational, Message = "[{0}/{1}] Transport started")]
public void TransportStarted(string connectionId, string sessionId)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

TransportStopped(string, string, string)

Logs when the transport stops processing messages.

[Event(18, Level = EventLevel.Informational, Message = "[{0}/{1}] Transport stopped: {2}")]
public void TransportStopped(string connectionId, string sessionId, string reason)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

reason string

The reason for stopping.

UnknownMessageReceived(string, string, IncomingMessageKind, int)

Logs when an unknown message is received from the remote end.

[NonEvent]
public void UnknownMessageReceived(string connectionId, string sessionId, IncomingMessageKind messageKind, int messageLength)

Parameters

connectionId string

The unique identifier for the connection the event belongs to.

sessionId string

The unique identifier for the session the event belongs to, or an empty string when no session is in progress.

messageKind IncomingMessageKind

The IncomingMessageKind of unknown message.

messageLength int

The length of the message in bytes.