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
This commit is contained in:
60
server/collaboration/tracing.ts
Normal file
60
server/collaboration/tracing.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user