1219b7b13e
Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
49 lines
2.5 KiB
C#
49 lines
2.5 KiB
C#
using ZB.MOM.WW.OtOpcUa.Commons.Observability;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient;
|
|
|
|
/// <summary>
|
|
/// Publishes an OPC UA Client driver instance's session/publish events (#276) on the shared
|
|
/// <c>otopcua.driver.opcuaclient.events</c> OTel counter, tagged with <c>driver_instance</c> and
|
|
/// <c>event</c>. The counter is thread-safe, so the SDK's notification / keep-alive threads record
|
|
/// directly with no locking here.
|
|
/// </summary>
|
|
internal sealed class OpcUaClientDiagnostics
|
|
{
|
|
/// <summary>A NotificationMessage arrived (one per Publish response that carried data).</summary>
|
|
public const string PublishResponse = "publish_response";
|
|
/// <summary>Items carried by notification messages.</summary>
|
|
public const string Notification = "notification";
|
|
/// <summary>One monitored-item data change was delivered.</summary>
|
|
public const string DataChange = "data_change";
|
|
/// <summary>A delivered data change carried a Bad status.</summary>
|
|
public const string BadStatusValue = "bad_status_value";
|
|
/// <summary>A Publish failed (missing publish requests, subscription errors).</summary>
|
|
public const string PublishError = "publish_error";
|
|
/// <summary>A keep-alive came back Bad.</summary>
|
|
public const string KeepAliveMiss = "keepalive_miss";
|
|
/// <summary>The reconnect handler was armed.</summary>
|
|
public const string ReconnectAttempt = "reconnect_attempt";
|
|
/// <summary>A reconnect landed a new session.</summary>
|
|
public const string ReconnectSuccess = "reconnect_success";
|
|
/// <summary>A reconnect handler exhausted its retry window.</summary>
|
|
public const string ReconnectExhausted = "reconnect_exhausted";
|
|
|
|
private readonly string _driverInstanceId;
|
|
|
|
/// <summary>Creates the recorder for one driver instance.</summary>
|
|
/// <param name="driverInstanceId">Value of the <c>driver_instance</c> tag.</param>
|
|
public OpcUaClientDiagnostics(string driverInstanceId) => _driverInstanceId = driverInstanceId;
|
|
|
|
/// <summary>Add <paramref name="count"/> to the counter for <paramref name="evt"/>.</summary>
|
|
/// <param name="evt">One of the event constants.</param>
|
|
/// <param name="count">Amount to add (default 1).</param>
|
|
public void Record(string evt, long count = 1)
|
|
{
|
|
if (count <= 0) return;
|
|
OtOpcUaTelemetry.OpcUaClientEvents.Add(count,
|
|
new KeyValuePair<string, object?>(OtOpcUaTelemetry.PollOverrunDriverInstanceTag, _driverInstanceId),
|
|
new KeyValuePair<string, object?>("event", evt));
|
|
}
|
|
}
|