Skip to content

Commit

Permalink
Merge pull request #1611 from vector-im/dbkr/depthlimit
Browse files Browse the repository at this point in the history
Re-enable livekit rageshake logging & with depth limit
  • Loading branch information
dbkr authored Sep 27, 2023
2 parents eedd19f + 3016866 commit 03caa22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/livekit/useLiveKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
ExternalE2EEKeyProvider,
Room,
RoomOptions,
setLogLevel,
} from "livekit-client";
import { useLiveKitRoom } from "@livekit/components-react";
import { useEffect, useMemo, useRef, useState } from "react";
Expand All @@ -44,8 +43,6 @@ export type E2EEConfig = {
sharedKey: string;
};

setLogLevel("debug");

interface UseLivekitResult {
livekitRoom?: Room;
connState: ECConnectionState;
Expand Down
6 changes: 6 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ import { createRoot } from "react-dom/client";
import { createBrowserHistory } from "history";
import "./index.css";
import { logger } from "matrix-js-sdk/src/logger";
import {
setLogExtension as setLKLogExtension,
setLogLevel,
} from "livekit-client";

import App from "./App";
import { init as initRageshake } from "./settings/rageshake";
import { Initializer } from "./initializer";

initRageshake();
setLogLevel("debug");
setLKLogExtension(global.mx_rage_logger.log);

logger.info(`Element Call ${import.meta.env.VITE_APP_VERSION || "dev"}`);

Expand Down
16 changes: 14 additions & 2 deletions src/settings/rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB
// we can batch the writes a little.
const MAX_FLUSH_INTERVAL_MS = 2 * 1000;

// only descend this far into nested object trees
const DEPTH_LIMIT = 3;

enum ConsoleLoggerEvent {
Log = "log",
}
Expand All @@ -67,7 +70,7 @@ class ConsoleLogger extends EventEmitter {

public log = (
level: LogLevel,
...args: (Error | DOMException | object | string)[]
...args: (Error | DOMException | object | string | undefined)[]
): void => {
// We don't know what locale the user may be running so use ISO strings
const ts = new Date().toISOString();
Expand Down Expand Up @@ -550,12 +553,21 @@ type StringifyReplacer = (
// Injects `<$ cycle-trimmed $>` wherever it cuts a cyclical object relationship
const getCircularReplacer = (): StringifyReplacer => {
const seen = new WeakSet();
return (key: string, value: unknown): unknown => {
const depthMap = new WeakMap<object, number>();
return function (this: unknown, key: string, value: unknown): unknown {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return "<$ cycle-trimmed $>";
}
seen.add(value);

let depth = 0;
if (this) {
depth = depthMap.get(this) ?? 0;
}
depthMap.set(value, depth + 1);

if (depth > DEPTH_LIMIT) return "<$ object-pruned $>";
}
return value;
};
Expand Down

0 comments on commit 03caa22

Please sign in to comment.