Skip to main content

Diagnostics & Events

Overview

The SDK emits diagnostic events for every significant action — connections, subscriptions, messages, and heartbeats. Use these for logging, monitoring, or debugging.

Listening to Events

All Events

client.onDiagnostic((event) => {
console.log(`[${event.kind}]`, event);
});

Filtered by Kind

client.onDiagnostic("link:live", (event) => {
console.log("Connected!", event.ts);
});

client.onDiagnostic("topic:sub:fail", (event) => {
console.error("Subscribe failed:", event.topic, event.reason);
});

RxJS API

import { filter } from "rxjs";

client.diagnostics$
.pipe(filter((e) => e.kind.startsWith("heartbeat:")))
.subscribe((event) => {
console.log("Heartbeat event:", event);
});

Event Kinds

Connection Events

KindDescription
link:openingConnection attempt initiated
link:liveSuccessfully connected
link:failedConnection attempt failed
link:rejectedConnection ignored (already active)
link:resumingAuto-reconnection in progress
link:closingGraceful disconnect initiated
link:droppedConnection lost unexpectedly

Message Events

KindDescription
envelope:inMessage received from broker
envelope:outMessage send initiated
envelope:out:okMessage sent successfully
envelope:out:failMessage send failed

Subscription Events

KindDescription
topic:sub:trySubscribe attempt
topic:sub:okSubscribe acknowledged by broker
topic:sub:failSubscribe rejected or failed
topic:unsub:tryUnsubscribe attempt
topic:unsub:okUnsubscribe acknowledged
topic:unsub:failUnsubscribe failed

Heartbeat Events

KindDescription
heartbeat:sentPINGREQ sent to broker
heartbeat:okPINGRESP received
heartbeat:timeoutNo PINGRESP within timeout window

Event Shape

interface DiagnosticEvent {
kind: DiagnosticKind; // Event type
ts: number; // Timestamp (Date.now())
topic?: string; // Relevant topic (if applicable)
qos?: DeliveryMode; // QoS level (if applicable)
reason?: string; // Error reason (if applicable)
elapsed?: number; // Duration in ms (if applicable)
endpointInfo?: EndpointInfo;
}