Add XML documentation across gateway, worker, and .NET client

This commit is contained in:
Joseph Doherty
2026-04-30 11:49:58 -04:00
parent 4731ab535c
commit eed1e88a37
269 changed files with 4555 additions and 13 deletions
@@ -49,6 +49,9 @@ public sealed class GatewayMetrics : IDisposable
private long _retryAttempts;
private bool _disposed;
/// <summary>
/// Initializes the gateway metrics with OpenTelemetry counters and histograms.
/// </summary>
public GatewayMetrics()
{
_meter = new Meter(MeterName, typeof(GatewayMetrics).Assembly.GetName().Version?.ToString());
@@ -75,6 +78,9 @@ public sealed class GatewayMetrics : IDisposable
_meter.CreateObservableGauge("mxgateway.events.grpc_stream_queue.depth", GetGrpcEventStreamQueueDepth);
}
/// <summary>
/// Records that a session has been opened.
/// </summary>
public void SessionOpened()
{
lock (_syncRoot)
@@ -86,6 +92,9 @@ public sealed class GatewayMetrics : IDisposable
_sessionsOpenedCounter.Add(1);
}
/// <summary>
/// Records that a session has been closed.
/// </summary>
public void SessionClosed()
{
lock (_syncRoot)
@@ -101,6 +110,9 @@ public sealed class GatewayMetrics : IDisposable
_sessionsClosedCounter.Add(1);
}
/// <summary>
/// Records that a session has been removed from registry.
/// </summary>
public void SessionRemoved()
{
lock (_syncRoot)
@@ -112,6 +124,10 @@ public sealed class GatewayMetrics : IDisposable
}
}
/// <summary>
/// Records that a worker process has started and its startup latency.
/// </summary>
/// <param name="startupDuration">Duration elapsed while starting the worker.</param>
public void WorkerStarted(TimeSpan startupDuration)
{
lock (_syncRoot)
@@ -122,6 +138,10 @@ public sealed class GatewayMetrics : IDisposable
_workerStartupLatencyHistogram.Record(startupDuration.TotalMilliseconds);
}
/// <summary>
/// Records that a worker process has stopped with the given reason.
/// </summary>
/// <param name="reason">Cause of the worker stopping.</param>
public void WorkerStopped(string reason)
{
lock (_syncRoot)
@@ -137,6 +157,10 @@ public sealed class GatewayMetrics : IDisposable
_workerExitsCounter.Add(1, new KeyValuePair<string, object?>("reason", reason));
}
/// <summary>
/// Records that a worker process was killed with the given reason.
/// </summary>
/// <param name="reason">Cause of the worker termination.</param>
public void WorkerKilled(string reason)
{
lock (_syncRoot)
@@ -147,6 +171,10 @@ public sealed class GatewayMetrics : IDisposable
_workerKillsCounter.Add(1, new KeyValuePair<string, object?>("reason", reason));
}
/// <summary>
/// Records that a command has started for the given method.
/// </summary>
/// <param name="method">Name of the command method.</param>
public void CommandStarted(string method)
{
lock (_syncRoot)
@@ -157,6 +185,11 @@ public sealed class GatewayMetrics : IDisposable
_commandsStartedCounter.Add(1, new KeyValuePair<string, object?>("method", method));
}
/// <summary>
/// Records that a command succeeded for the given method and duration.
/// </summary>
/// <param name="method">Name of the command method.</param>
/// <param name="duration">Elapsed time to complete the command.</param>
public void CommandSucceeded(string method, TimeSpan duration)
{
lock (_syncRoot)
@@ -169,6 +202,12 @@ public sealed class GatewayMetrics : IDisposable
_commandLatencyHistogram.Record(duration.TotalMilliseconds, methodTag);
}
/// <summary>
/// Records that a command failed for the given method, category, and duration.
/// </summary>
/// <param name="method">Name of the command method.</param>
/// <param name="category">Classification of the failure.</param>
/// <param name="duration">Elapsed time before command failed.</param>
public void CommandFailed(string method, string category, TimeSpan duration)
{
lock (_syncRoot)
@@ -183,6 +222,11 @@ public sealed class GatewayMetrics : IDisposable
_commandLatencyHistogram.Record(duration.TotalMilliseconds, methodTag, categoryTag);
}
/// <summary>
/// Records that an event was received for the given session and family.
/// </summary>
/// <param name="sessionId">Identifier of the session receiving the event.</param>
/// <param name="family">Event family classification.</param>
public void EventReceived(string sessionId, string family)
{
Interlocked.Increment(ref _eventsReceived);
@@ -194,6 +238,11 @@ public sealed class GatewayMetrics : IDisposable
new KeyValuePair<string, object?>("family", family));
}
/// <summary>
/// Records the latency of sending an event to a client stream.
/// </summary>
/// <param name="family">Event family name.</param>
/// <param name="duration">Time taken to send the event.</param>
public void RecordEventStreamSend(string family, TimeSpan duration)
{
_eventStreamSendLatencyHistogram.Record(
@@ -201,11 +250,19 @@ public sealed class GatewayMetrics : IDisposable
new KeyValuePair<string, object?>("family", family));
}
/// <summary>
/// Sets the worker event queue depth; delegates to SetWorkerEventQueueDepth.
/// </summary>
/// <param name="depth">Queue depth value.</param>
public void SetEventQueueDepth(int depth)
{
SetWorkerEventQueueDepth(depth);
}
/// <summary>
/// Sets the worker event queue depth to the given value.
/// </summary>
/// <param name="depth">Queue depth value.</param>
public void SetWorkerEventQueueDepth(int depth)
{
if (depth < 0)
@@ -219,6 +276,10 @@ public sealed class GatewayMetrics : IDisposable
}
}
/// <summary>
/// Adjusts the gRPC event stream queue depth by the given delta.
/// </summary>
/// <param name="delta">Amount to adjust the queue depth by.</param>
public void AdjustGrpcEventStreamQueueDepth(int delta)
{
lock (_syncRoot)
@@ -227,11 +288,19 @@ public sealed class GatewayMetrics : IDisposable
}
}
/// <summary>
/// Removes event counters for the given session.
/// </summary>
/// <param name="sessionId">Identifier of the session.</param>
public void RemoveSessionEvents(string sessionId)
{
_eventsBySession.TryRemove(sessionId, out _);
}
/// <summary>
/// Records that a queue overflow occurred for the given queue name.
/// </summary>
/// <param name="queueName">Name of the queue that overflowed.</param>
public void QueueOverflow(string queueName)
{
lock (_syncRoot)
@@ -242,6 +311,10 @@ public sealed class GatewayMetrics : IDisposable
_queueOverflowsCounter.Add(1, new KeyValuePair<string, object?>("queue", queueName));
}
/// <summary>
/// Records that a fault occurred in the given category.
/// </summary>
/// <param name="category">Category of the fault.</param>
public void Fault(string category)
{
lock (_syncRoot)
@@ -252,6 +325,10 @@ public sealed class GatewayMetrics : IDisposable
_faultsCounter.Add(1, new KeyValuePair<string, object?>("category", category));
}
/// <summary>
/// Records that a heartbeat failed for the given session.
/// </summary>
/// <param name="sessionId">Identifier of the session.</param>
public void HeartbeatFailed(string sessionId)
{
lock (_syncRoot)
@@ -262,6 +339,10 @@ public sealed class GatewayMetrics : IDisposable
_heartbeatFailuresCounter.Add(1, new KeyValuePair<string, object?>("session_id", sessionId));
}
/// <summary>
/// Records that an event stream was disconnected with the given reason.
/// </summary>
/// <param name="reason">Reason for the disconnection.</param>
public void StreamDisconnected(string reason)
{
lock (_syncRoot)
@@ -272,6 +353,10 @@ public sealed class GatewayMetrics : IDisposable
_streamDisconnectsCounter.Add(1, new KeyValuePair<string, object?>("reason", reason));
}
/// <summary>
/// Records that a retry was attempted in the given area.
/// </summary>
/// <param name="area">Area in which the retry was attempted.</param>
public void RetryAttempted(string area)
{
lock (_syncRoot)
@@ -283,6 +368,9 @@ public sealed class GatewayMetrics : IDisposable
_retryAttemptsCounter.Add(1, new KeyValuePair<string, object?>("area", area));
}
/// <summary>
/// Returns a snapshot of all current metric values.
/// </summary>
public GatewayMetricsSnapshot GetSnapshot()
{
lock (_syncRoot)
@@ -312,6 +400,9 @@ public sealed class GatewayMetrics : IDisposable
}
}
/// <summary>
/// Disposes the underlying OpenTelemetry meter.
/// </summary>
public void Dispose()
{
if (_disposed)