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
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
inFlightCountintThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
commandIdlongThe ID of the canceled command.
methodstringThe protocol method name of the canceled command.
reasonCommandCancellationReasonThe reason the command was canceled.
millisecondsSinceCancellationlongThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
commandIdlongThe unique identifier for the command.
methodstringThe command method name.
elapsedMillisecondslongThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
commandIdlongThe unique identifier for the command.
methodstringThe command method name.
errorCodeErrorCodeThe protocol error code returned by the remote end.
errorTypestringThe error type returned by the remote end.
errorMessagestringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
commandIdlongThe unique identifier for the command.
methodstringThe command method name.
failureTypestringThe .NET exception type describing the send failure.
failureMessagestringThe failure message.
elapsedMillisecondslongThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
commandIdlongThe unique identifier for the command.
methodstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
commandIdlongThe unique identifier for the command.
methodstringThe command method name.
timeoutMillisecondslongThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
reasonstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
errorMessagestringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
urlstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
urlstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
eventNamestringThe name of the custom event.
eventTypestringThe .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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
moduleNamestringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
eventMethodstringThe event method name.
errorMessagestringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
eventMethodstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
messagesSentlongNumber of commands sent during the session.
messagesReceivedlongNumber of command responses received during the session.
eventsReceivedlongNumber of events received during the session.
errorsReceivedlongNumber 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
pendingCountintThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
errorMessagestringThe error message.
messageSnippetstringA 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
reasonstringThe 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
connectionIdstringThe unique identifier for the connection the event belongs to.
sessionIdstringThe unique identifier for the session the event belongs to, or an empty string when no session is in progress.
messageKindIncomingMessageKindThe IncomingMessageKind of unknown message.
messageLengthintThe length of the message in bytes.