Files
outline/server/collaboration/tracing.ts
Tom Moor 15b1069bcc chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
2021-11-29 06:40:55 -08:00

61 lines
1.6 KiB
TypeScript

import {
onChangePayload,
onConnectPayload,
onDisconnectPayload,
onLoadDocumentPayload,
} from "@hocuspocus/server";
import Metrics from "@server/logging/metrics";
export default class Tracing {
onLoadDocument({ documentName, instance }: onLoadDocumentPayload) {
Metrics.increment("collaboration.load_document", {
documentName,
});
Metrics.gaugePerInstance(
"collaboration.documents_count",
instance.getDocumentsCount()
);
}
onAuthenticationFailed({ documentName }: { documentName: string }) {
Metrics.increment("collaboration.authentication_failed", {
documentName,
});
}
onConnect({ documentName, instance }: onConnectPayload) {
Metrics.increment("collaboration.connect", {
documentName,
});
Metrics.gaugePerInstance(
"collaboration.connections_count",
instance.getConnectionsCount()
);
}
onDisconnect({ documentName, instance }: onDisconnectPayload) {
Metrics.increment("collaboration.disconnect", {
documentName,
});
Metrics.gaugePerInstance(
"collaboration.connections_count",
instance.getConnectionsCount()
);
Metrics.gaugePerInstance(
"collaboration.documents_count", // -1 adjustment because hook is called before document is removed
instance.getDocumentsCount() - 1
);
}
onChange({ documentName }: onChangePayload) {
Metrics.increment("collaboration.change", {
documentName,
});
}
onDestroy() {
Metrics.gaugePerInstance("collaboration.connections_count", 0);
Metrics.gaugePerInstance("collaboration.documents_count", 0);
}
}