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";
/// The reconnect handler was armed.
public const string ReconnectAttempt = "reconnect_attempt";
/// A reconnect landed a new session.
public const string ReconnectSuccess = "reconnect_success";
/// A reconnect handler exhausted its retry window.
public const string ReconnectExhausted = "reconnect_exhausted";
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));
}
}