Add back posthog connection time tracking (#2316)
Signed-off-by: Timo K <toger5@hotmail.de> Co-authored-by: Robin <robin@robin.town>
This commit is contained in:
@@ -31,6 +31,7 @@ import {
|
|||||||
UndecryptableToDeviceEventTracker,
|
UndecryptableToDeviceEventTracker,
|
||||||
QualitySurveyEventTracker,
|
QualitySurveyEventTracker,
|
||||||
CallDisconnectedEventTracker,
|
CallDisconnectedEventTracker,
|
||||||
|
CallConnectDurationTracker,
|
||||||
} from "./PosthogEvents";
|
} from "./PosthogEvents";
|
||||||
import { Config } from "../config/Config";
|
import { Config } from "../config/Config";
|
||||||
import { getUrlParams } from "../UrlParams";
|
import { getUrlParams } from "../UrlParams";
|
||||||
@@ -444,4 +445,5 @@ export class PosthogAnalytics {
|
|||||||
public eventUndecryptableToDevice = new UndecryptableToDeviceEventTracker();
|
public eventUndecryptableToDevice = new UndecryptableToDeviceEventTracker();
|
||||||
public eventQualitySurvey = new QualitySurveyEventTracker();
|
public eventQualitySurvey = new QualitySurveyEventTracker();
|
||||||
public eventCallDisconnected = new CallDisconnectedEventTracker();
|
public eventCallDisconnected = new CallDisconnectedEventTracker();
|
||||||
|
public eventCallConnectDuration = new CallConnectDurationTracker();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { DisconnectReason } from "livekit-client";
|
import { DisconnectReason } from "livekit-client";
|
||||||
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IPosthogEvent,
|
IPosthogEvent,
|
||||||
@@ -201,3 +202,38 @@ export class CallDisconnectedEventTracker {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CallConnectDuration extends IPosthogEvent {
|
||||||
|
eventName: "CallConnectDuration";
|
||||||
|
totalDuration: number;
|
||||||
|
websocketDuration: number;
|
||||||
|
peerConnectionDuration: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CallConnectDurationTracker {
|
||||||
|
private connectStart = 0;
|
||||||
|
private websocketConnected = 0;
|
||||||
|
public cacheConnectStart(): void {
|
||||||
|
this.connectStart = Date.now();
|
||||||
|
}
|
||||||
|
public cacheWsConnect(): void {
|
||||||
|
this.websocketConnected = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public track(options = { log: false }): void {
|
||||||
|
const now = Date.now();
|
||||||
|
const totalDuration = now - this.connectStart;
|
||||||
|
const websocketDuration = this.websocketConnected - this.connectStart;
|
||||||
|
const peerConnectionDuration = now - this.websocketConnected;
|
||||||
|
PosthogAnalytics.instance.trackEvent<CallConnectDuration>({
|
||||||
|
eventName: "CallConnectDuration",
|
||||||
|
totalDuration,
|
||||||
|
websocketDuration,
|
||||||
|
peerConnectionDuration,
|
||||||
|
});
|
||||||
|
if (options.log)
|
||||||
|
logger.log(
|
||||||
|
`Time to connect:\ntotal: ${totalDuration}ms\npeerConnection: ${websocketDuration}ms\nwebsocket: ${peerConnectionDuration}ms`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import { logger } from "matrix-js-sdk/src/logger";
|
|||||||
import * as Sentry from "@sentry/react";
|
import * as Sentry from "@sentry/react";
|
||||||
|
|
||||||
import { SFUConfig, sfuConfigEquals } from "./openIDSFU";
|
import { SFUConfig, sfuConfigEquals } from "./openIDSFU";
|
||||||
|
import { PosthogAnalytics } from "../analytics/PosthogAnalytics";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -131,6 +132,11 @@ async function connectAndPublish(
|
|||||||
micTrack: LocalTrack | undefined,
|
micTrack: LocalTrack | undefined,
|
||||||
screenshareTracks: MediaStreamTrack[],
|
screenshareTracks: MediaStreamTrack[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const tracker = PosthogAnalytics.instance.eventCallConnectDuration;
|
||||||
|
// Track call connect duration
|
||||||
|
tracker.cacheConnectStart();
|
||||||
|
livekitRoom.once(RoomEvent.SignalConnected, tracker.cacheWsConnect);
|
||||||
|
|
||||||
await livekitRoom!.connect(sfuConfig!.url, sfuConfig!.jwt, {
|
await livekitRoom!.connect(sfuConfig!.url, sfuConfig!.jwt, {
|
||||||
// Due to stability issues on Firefox we are testing the effect of different
|
// Due to stability issues on Firefox we are testing the effect of different
|
||||||
// timeouts, and allow these values to be set through the console
|
// timeouts, and allow these values to be set through the console
|
||||||
@@ -138,6 +144,10 @@ async function connectAndPublish(
|
|||||||
websocketTimeout: window.websocketTimeout ?? 45000,
|
websocketTimeout: window.websocketTimeout ?? 45000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// remove listener in case the connect promise rejects before `SignalConnected` is emitted.
|
||||||
|
livekitRoom.off(RoomEvent.SignalConnected, tracker.cacheWsConnect);
|
||||||
|
tracker.track({ log: true });
|
||||||
|
|
||||||
if (micTrack) {
|
if (micTrack) {
|
||||||
logger.info(`Publishing precreated mic track`);
|
logger.info(`Publishing precreated mic track`);
|
||||||
await livekitRoom.localParticipant.publishTrack(micTrack, {
|
await livekitRoom.localParticipant.publishTrack(micTrack, {
|
||||||
|
|||||||
Reference in New Issue
Block a user