You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Change child loggers (getChild
) to LogSpans
With the child loggers, we ended up not seeing the logs in the rageshake because it requires a custom configuration in element call to write the child loggers (with getChild) into the rageshake log. LogSpans are a lightweight alternative that still use the same logger but only extend the prefix and hence end up in the rageshake without registering new loggers. It prohibits the footgun of not getting logs in the rageshake.
This commit is contained in:
@ -28,8 +28,8 @@ It is very specific to the MembershipManager.spec.ts file and introduces the fol
|
||||
|
||||
import { TestEnvironment } from "jest-environment-jsdom";
|
||||
|
||||
import { logger as rootLogger } from "../../../src/logger";
|
||||
const logger = rootLogger.getChild("[MatrixRTCSession]");
|
||||
import { LogSpan, logger as rootLogger } from "../../../src/logger";
|
||||
const logger = new LogSpan(rootLogger, "[MatrixRTCSession]");
|
||||
|
||||
class MemberManagerTestEnvironment extends TestEnvironment {
|
||||
handleTestEvent(event: any) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { type Logger, logger as rootLogger } from "../logger.ts";
|
||||
import { type BaseLogger, LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import { type EncryptionConfig } from "./MatrixRTCSession.ts";
|
||||
import { secureRandomBase64Url } from "../randomstring.ts";
|
||||
import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
|
||||
@ -81,7 +81,7 @@ export class EncryptionManager implements IEncryptionManager {
|
||||
|
||||
private latestGeneratedKeyIndex = -1;
|
||||
private joinConfig: EncryptionConfig | undefined;
|
||||
private logger: Logger;
|
||||
private logger: LogSpan;
|
||||
public constructor(
|
||||
private userId: string,
|
||||
private deviceId: string,
|
||||
@ -93,9 +93,9 @@ export class EncryptionManager implements IEncryptionManager {
|
||||
encryptionKeyIndex: number,
|
||||
participantId: string,
|
||||
) => void,
|
||||
parentLogger?: Logger,
|
||||
parentLogger?: BaseLogger,
|
||||
) {
|
||||
this.logger = (parentLogger ?? rootLogger).getChild(`[EncryptionManager]`);
|
||||
this.logger = new LogSpan(parentLogger ?? rootLogger, "[EncryptionManager]");
|
||||
}
|
||||
|
||||
public getEncryptionKeys(): Map<string, Array<{ key: Uint8Array; timestamp: number }>> {
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { type Logger, logger as rootLogger } from "../logger.ts";
|
||||
import { LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
|
||||
import { EventTimeline } from "../models/event-timeline.ts";
|
||||
import { type Room } from "../models/room.ts";
|
||||
@ -176,7 +176,7 @@ export class MatrixRTCSession extends TypedEventEmitter<
|
||||
private encryptionManager?: IEncryptionManager;
|
||||
// The session Id of the call, this is the call_id of the call Member event.
|
||||
private _callId: string | undefined;
|
||||
private logger: Logger;
|
||||
private logger: LogSpan;
|
||||
/**
|
||||
* This timeout is responsible to track any expiration. We need to know when we have to start
|
||||
* to ignore other call members. There is no callback for this. This timeout will always be configured to
|
||||
@ -213,7 +213,8 @@ export class MatrixRTCSession extends TypedEventEmitter<
|
||||
public static callMembershipsForRoom(
|
||||
room: Pick<Room, "getLiveTimeline" | "roomId" | "hasMembershipState">,
|
||||
): CallMembership[] {
|
||||
const logger = rootLogger.getChild(`[MatrixRTCSession ${room.roomId}]`);
|
||||
const logger = new LogSpan(rootLogger, `[MatrixRTCSession ${room.roomId}]`);
|
||||
|
||||
const roomState = room.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
if (!roomState) {
|
||||
logger.warn("Couldn't get state for room " + room.roomId);
|
||||
@ -329,7 +330,8 @@ export class MatrixRTCSession extends TypedEventEmitter<
|
||||
public memberships: CallMembership[],
|
||||
) {
|
||||
super();
|
||||
this.logger = rootLogger.getChild(`[MatrixRTCSession ${roomSubset.roomId}]`);
|
||||
this.logger = new LogSpan(rootLogger, `[MatrixRTCSession ${roomSubset.roomId}]`);
|
||||
|
||||
this._callId = memberships[0]?.callId;
|
||||
const roomState = this.roomSubset.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
// TODO: double check if this is actually needed. Should be covered by refreshRoom in MatrixRTCSessionManager
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { logger as rootLogger } from "../logger.ts";
|
||||
import { LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import { type MatrixClient, ClientEvent } from "../client.ts";
|
||||
import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
|
||||
import { type Room } from "../models/room.ts";
|
||||
@ -23,7 +23,7 @@ import { type MatrixEvent } from "../models/event.ts";
|
||||
import { MatrixRTCSession } from "./MatrixRTCSession.ts";
|
||||
import { EventType } from "../@types/event.ts";
|
||||
|
||||
const logger = rootLogger.getChild("[MatrixRTCSessionManager]");
|
||||
const logger = new LogSpan(rootLogger, `[MatrixRTCSessionManager]`);
|
||||
|
||||
export enum MatrixRTCSessionManagerEvents {
|
||||
// A member has joined the MatrixRTC session, creating an active session in a room where there wasn't previously
|
||||
|
@ -19,7 +19,7 @@ import { UpdateDelayedEventAction } from "../@types/requests.ts";
|
||||
import { type MatrixClient } from "../client.ts";
|
||||
import { UnsupportedDelayedEventsEndpointError } from "../errors.ts";
|
||||
import { ConnectionError, HTTPError, MatrixError } from "../http-api/errors.ts";
|
||||
import { type Logger, logger as rootLogger } from "../logger.ts";
|
||||
import { type BaseLogger, LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import { type Room } from "../models/room.ts";
|
||||
import { defer, type IDeferred } from "../utils.ts";
|
||||
import { type CallMembership, DEFAULT_EXPIRE_DURATION, type SessionMembershipData } from "./CallMembership.ts";
|
||||
@ -144,7 +144,7 @@ export class MembershipManager
|
||||
implements IMembershipManager
|
||||
{
|
||||
private activated = false;
|
||||
private logger: Logger;
|
||||
private logger: LogSpan;
|
||||
|
||||
public isActivated(): boolean {
|
||||
return this.activated;
|
||||
@ -281,10 +281,10 @@ export class MembershipManager
|
||||
| "_unstable_updateDelayedEvent"
|
||||
>,
|
||||
private getOldestMembership: () => CallMembership | undefined,
|
||||
parentLogger?: Logger,
|
||||
parentLogger?: BaseLogger,
|
||||
) {
|
||||
super();
|
||||
this.logger = (parentLogger ?? rootLogger).getChild(`[NewMembershipManager]`);
|
||||
this.logger = new LogSpan(parentLogger ?? rootLogger, `[NewMembershipManager]`);
|
||||
const [userId, deviceId] = [this.client.getUserId(), this.client.getDeviceId()];
|
||||
if (userId === null) throw Error("Missing userId in client");
|
||||
if (deviceId === null) throw Error("Missing deviceId in client");
|
||||
@ -297,14 +297,14 @@ export class MembershipManager
|
||||
// is equivalent to running it at the end of the loop. (just after applying the status/action list changes)
|
||||
// This order is required because this method needs to return the action updates.
|
||||
this.logger.debug(
|
||||
`MembershipManager applied action changes. Status: ${this.oldStatus} -> ${this.status}`,
|
||||
`applied action changes. Status: ${this.oldStatus} -> ${this.status}`,
|
||||
);
|
||||
if (this.oldStatus !== this.status) {
|
||||
this.emit(MembershipManagerEvent.StatusChanged, this.oldStatus, this.status);
|
||||
}
|
||||
}
|
||||
this.oldStatus = this.status;
|
||||
this.logger.debug(`MembershipManager before processing action. status=${this.oldStatus}`);
|
||||
this.logger.debug(`before processing action. status=${this.oldStatus}`);
|
||||
return this.membershipLoopHandler(type);
|
||||
}, this.logger);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { type Logger, logger as rootLogger } from "../logger.ts";
|
||||
import { type BaseLogger, LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import { type EmptyObject } from "../matrix.ts";
|
||||
import { sleep } from "../utils.ts";
|
||||
import { MembershipActionType } from "./NewMembershipManager.ts";
|
||||
@ -38,7 +38,7 @@ export type ActionUpdate =
|
||||
* @internal
|
||||
*/
|
||||
export class ActionScheduler {
|
||||
private logger: Logger;
|
||||
private logger: LogSpan;
|
||||
/**
|
||||
* This is tracking the state of the scheduler loop.
|
||||
* Only used to prevent starting the loop twice.
|
||||
@ -48,9 +48,9 @@ export class ActionScheduler {
|
||||
public constructor(
|
||||
/** This is the callback called for each scheduled action (`this.addAction()`) */
|
||||
private membershipLoopHandler: (type: MembershipActionType) => Promise<ActionUpdate>,
|
||||
parentLogger?: Logger,
|
||||
parentLogger?: BaseLogger,
|
||||
) {
|
||||
this.logger = (parentLogger ?? rootLogger).getChild(`[NewMembershipActionScheduler]`);
|
||||
this.logger = new LogSpan(parentLogger ?? rootLogger, `[NewMembershipActionScheduler]`);
|
||||
}
|
||||
|
||||
// function for the wakeup mechanism (in case we add an action externally and need to leave the current sleep)
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { logger as rootLogger, type Logger } from "../logger.ts";
|
||||
import { type BaseLogger, LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import { KeyTransportEvents, type KeyTransportEventsHandlerMap, type IKeyTransport } from "./IKeyTransport.ts";
|
||||
import { type CallMembership } from "./CallMembership.ts";
|
||||
import type { RoomKeyTransport } from "./RoomKeyTransport.ts";
|
||||
@ -49,15 +49,15 @@ export class RoomAndToDeviceTransport
|
||||
>
|
||||
implements IKeyTransport
|
||||
{
|
||||
private readonly logger: Logger;
|
||||
private readonly logger: LogSpan;
|
||||
private _enabled: EnabledTransports = { toDevice: true, room: false };
|
||||
public constructor(
|
||||
private toDeviceTransport: ToDeviceKeyTransport,
|
||||
private roomKeyTransport: RoomKeyTransport,
|
||||
parentLogger?: Logger,
|
||||
parentLogger?: BaseLogger,
|
||||
) {
|
||||
super();
|
||||
this.logger = (parentLogger ?? rootLogger).getChild(`[RoomAndToDeviceTransport]`);
|
||||
this.logger = new LogSpan(parentLogger ?? rootLogger, `[RoomAndToDeviceTransport]`);
|
||||
// update parent loggers for the sub transports so filtering for `RoomAndToDeviceTransport` contains their logs too
|
||||
this.toDeviceTransport.setParentLogger(this.logger);
|
||||
this.roomKeyTransport.setParentLogger(this.logger);
|
||||
|
@ -18,7 +18,7 @@ import type { MatrixClient } from "../client.ts";
|
||||
import type { EncryptionKeysEventContent, Statistics } from "./types.ts";
|
||||
import { EventType } from "../@types/event.ts";
|
||||
import { type MatrixError } from "../http-api/errors.ts";
|
||||
import { logger as rootLogger, type Logger } from "../logger.ts";
|
||||
import { type BaseLogger, LogSpan, logger as rootLogger, type Logger } from "../logger.ts";
|
||||
import { KeyTransportEvents, type KeyTransportEventsHandlerMap, type IKeyTransport } from "./IKeyTransport.ts";
|
||||
import { type MatrixEvent } from "../models/event.ts";
|
||||
import { type CallMembership } from "./CallMembership.ts";
|
||||
@ -29,9 +29,9 @@ export class RoomKeyTransport
|
||||
extends TypedEventEmitter<KeyTransportEvents, KeyTransportEventsHandlerMap>
|
||||
implements IKeyTransport
|
||||
{
|
||||
private logger: Logger = rootLogger;
|
||||
public setParentLogger(parentLogger: Logger): void {
|
||||
this.logger = parentLogger.getChild(`[RoomKeyTransport]`);
|
||||
private logger: BaseLogger = rootLogger;
|
||||
public setParentLogger(parentLogger: BaseLogger): void {
|
||||
this.logger = new LogSpan(parentLogger, `[RoomKeyTransport]`);
|
||||
}
|
||||
public constructor(
|
||||
private room: Pick<Room, "on" | "off" | "roomId">,
|
||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
|
||||
import { type IKeyTransport, KeyTransportEvents, type KeyTransportEventsHandlerMap } from "./IKeyTransport.ts";
|
||||
import { type Logger, logger as rootLogger } from "../logger.ts";
|
||||
import { type BaseLogger, LogSpan, logger as rootLogger } from "../logger.ts";
|
||||
import type { CallMembership } from "./CallMembership.ts";
|
||||
import type { EncryptionKeysToDeviceEventContent, Statistics } from "./types.ts";
|
||||
import { ClientEvent, type MatrixClient } from "../client.ts";
|
||||
@ -31,9 +31,9 @@ export class ToDeviceKeyTransport
|
||||
extends TypedEventEmitter<KeyTransportEvents, KeyTransportEventsHandlerMap>
|
||||
implements IKeyTransport
|
||||
{
|
||||
private logger: Logger = rootLogger;
|
||||
public setParentLogger(parentLogger: Logger): void {
|
||||
this.logger = parentLogger.getChild(`[ToDeviceKeyTransport]`);
|
||||
private logger: BaseLogger = rootLogger;
|
||||
public setParentLogger(parentLogger: BaseLogger): void {
|
||||
this.logger = new LogSpan(parentLogger, `[ToDeviceKeyTransport]`);
|
||||
}
|
||||
|
||||
public constructor(
|
||||
@ -42,7 +42,7 @@ export class ToDeviceKeyTransport
|
||||
private roomId: string,
|
||||
private client: Pick<MatrixClient, "encryptAndSendToDevice" | "on" | "off">,
|
||||
private statistics: Statistics,
|
||||
parentLogger?: Logger,
|
||||
parentLogger?: BaseLogger,
|
||||
) {
|
||||
super();
|
||||
this.setParentLogger(parentLogger ?? rootLogger);
|
||||
|
@ -42,7 +42,6 @@ export interface EncryptionKeysToDeviceEventContent {
|
||||
call_id: string;
|
||||
scope: string;
|
||||
};
|
||||
// Why is this needed?
|
||||
sent_ts?: number;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user