Skip to content

Commit

Permalink
Add more logging scopes to session IDs
Browse files Browse the repository at this point in the history
This uses prefix chaining to correlate several scopes together.
  • Loading branch information
jryans committed Feb 26, 2021
1 parent ab61a80 commit 5bba718
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/crypto/OlmDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,14 @@ OlmDevice.prototype.getSessionIdsForDevice = async function(theirDeviceIdentityK
* @param {boolean} nowait Don't wait for an in-progress session to complete.
* This should only be set to true of the calling function is the function
* that marked the session as being in-progress.
* @param {Logger} [log] A possibly customised log
* @return {Promise<?string>} session id, or null if no established session
*/
OlmDevice.prototype.getSessionIdForDevice = async function(
theirDeviceIdentityKey, nowait,
theirDeviceIdentityKey, nowait, log,
) {
const sessionInfos = await this.getSessionInfoForDevice(
theirDeviceIdentityKey, nowait,
theirDeviceIdentityKey, nowait, log,
);

if (sessionInfos.length === 0) {
Expand Down Expand Up @@ -702,10 +703,13 @@ OlmDevice.prototype.getSessionIdForDevice = async function(
* @param {boolean} nowait Don't wait for an in-progress session to complete.
* This should only be set to true of the calling function is the function
* that marked the session as being in-progress.
* @param {Logger} [log] A possibly customised log
* @return {Array.<{sessionId: string, hasReceivedMessage: Boolean}>}
*/
OlmDevice.prototype.getSessionInfoForDevice = async function(deviceIdentityKey, nowait) {
const log = logger.withPrefix("[getSessionInfoForDevice]");
OlmDevice.prototype.getSessionInfoForDevice = async function(
deviceIdentityKey, nowait, log = logger,
) {
log = log.withPrefix("[getSessionInfoForDevice]");

if (this._sessionsInProgress[deviceIdentityKey] && !nowait) {
log.debug(`Waiting for Olm session for ${deviceIdentityKey} to be created`);
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/olmlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export async function getExistingOlmSessions(
* @param {Array} [failedServers] An array to fill with remote servers that
* failed to respond to one-time-key requests.
*
* @param {Object} [log] A possibly customised log
* @param {Logger} [log] A possibly customised log
*
* @return {Promise} resolves once the sessions are complete, to
* an Object mapping from userId to deviceId to
Expand Down Expand Up @@ -257,7 +257,7 @@ export async function ensureOlmSessionsForDevices(
);
}
const sessionId = await olmDevice.getSessionIdForDevice(
key, resolveSession[key],
key, resolveSession[key], log,
);
log.debug(`Got Olm session ${sessionId} ${forWhom}`);
if (sessionId !== null && resolveSession[key]) {
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/store/indexeddb-crypto-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ export class IndexedDBCryptoStore {
* @param {function(*)} func Function called with the
* transaction object: an opaque object that should be passed
* to store functions.
* @param {object} [log] A possibly customised log
* @param {Logger} [log] A possibly customised log
* @return {Promise} Promise that resolves with the result of the `func`
* when the transaction is complete. If the backend is
* async (ie. the indexeddb backend) any of the callback
Expand Down
5 changes: 3 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ interface PrefixedLogger extends Logger {
}

function extendLogger(logger: PrefixedLogger) {
logger.withPrefix = function(prefix: string) {
return getPrefixedLogger(this.prefix + prefix);
logger.withPrefix = function(prefix: string): PrefixedLogger {
const existingPrefix = this.prefix || "";
return getPrefixedLogger(existingPrefix + prefix);
};
}

Expand Down

0 comments on commit 5bba718

Please sign in to comment.