using ZB.MOM.WW.OtOpcUa.Commons.Observability;
namespace ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient;
///
/// Publishes an OPC UA Client driver instance's session/publish events (#276) on the shared
/// otopcua.driver.opcuaclient.events OTel counter, tagged with driver_instance and
/// event. The counter is thread-safe, so the SDK's notification / keep-alive threads record
/// directly with no locking here.
///
internal sealed class OpcUaClientDiagnostics
{
/// A NotificationMessage arrived (one per Publish response that carried data).
public const string PublishResponse = "publish_response";
/// Items carried by notification messages.
public const string Notification = "notification";
/// One monitored-item data change was delivered.
public const string DataChange = "data_change";
/// A delivered data change carried a Bad status.
public const string BadStatusValue = "bad_status_value";
/// A Publish failed (missing publish requests, subscription errors).
public const string PublishError = "publish_error";
/// A keep-alive came back Bad.
public const string KeepAliveMiss = "keepalive_miss";
/// A keep-alive came back Good after a bad one on the same session (an in-place recovery, #670).
public const string KeepAliveRecovered = "keepalive_recovered";
/// A late replayed notification (source time at or below the ref's high-water mark) was dropped inside the post-recovery replay window (#670 F2).
public const string StaleNotificationDropped = "stale_notification_dropped";
private readonly string _driverInstanceId;
/// Creates the recorder for one driver instance.
/// Value of the driver_instance tag.
public OpcUaClientDiagnostics(string driverInstanceId) => _driverInstanceId = driverInstanceId;
/// Add to the counter for .
/// One of the event constants.
/// Amount to add (default 1).
public void Record(string evt, long count = 1)
{
if (count <= 0) return;
OtOpcUaTelemetry.OpcUaClientEvents.Add(count,
new KeyValuePair(OtOpcUaTelemetry.PollOverrunDriverInstanceTag, _driverInstanceId),
new KeyValuePair("event", evt));
}
}