Gateway: log user ID/i
Some checks failed
Build docker images / build (admin-api) (push) Failing after 1m28s
Build docker images / build (cdn) (push) Failing after 1m15s
Build docker images / build (cdn-cs) (push) Failing after 1m15s
Build / build (24.x) (push) Successful in 3m3s
Nix build / build-nix (push) Failing after 1m16s
Style / build (24.x) (push) Failing after 2m11s
Build docker images / build (api) (push) Failing after 1m16s
Build docker images / build (default) (push) Failing after 1m16s
Build docker images / build (gateway) (push) Failing after 1m15s
Build docker images / build (gateway-offload) (push) Failing after 1m27s

This commit is contained in:
Rory&
2026-02-17 18:36:17 +01:00
parent 9bd8fc2c09
commit 780d2c69b0
12 changed files with 36 additions and 24 deletions

View File

@@ -84,7 +84,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
// @ts-ignore
socket.on("message", Message);
socket.on("error", (err) => console.error("[Gateway]", err));
socket.on("error", (err) => console.error(`[Gateway/${socket.user_id ?? socket.ipAddress}]`, err));
console.log(`[Gateway] New connection from ${ipAddress}, total ${this.clients.size}`);
@@ -106,7 +106,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
// @ts-ignore
socket.encoding = searchParams.get("encoding") || "json";
if (!["json", "etf"].includes(socket.encoding)) {
console.error(`[Gateway] Unknown encoding: ${socket.encoding}`);
console.error(`[Gateway/${socket.ipAddress}] Unknown encoding: ${socket.encoding}`);
return socket.close(CLOSECODES.Decode_error);
}
@@ -114,7 +114,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
socket.version = Number(searchParams.get("version")) || 8;
if (socket.version != 8) {
console.error(`[Gateway] Invalid API version: ${socket.version}`);
console.error(`[Gateway/${socket.ipAddress}] Invalid API version: ${socket.version}`);
return socket.close(CLOSECODES.Invalid_API_version);
}
@@ -128,7 +128,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In
socket.zstdEncoder = new Encoder(6);
socket.zstdDecoder = new Decoder();
} else {
console.error(`[Gateway] Unknown compression: ${socket.compress}`);
console.error(`[Gateway/${socket.user_id}] Unknown compression: ${socket.compress}`);
return socket.close(CLOSECODES.Decode_error);
}
}

View File

@@ -63,11 +63,11 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
try {
data = erlpack.unpack(buffer);
} catch {
console.error("[Gateway] Failed to decode ETF payload");
console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Failed to decode ETF payload`);
return this.close(CLOSECODES.Decode_error);
}
} else {
console.error("[Gateway] Unknown payload format");
console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Unknown payload format`);
return this.close(CLOSECODES.Decode_error);
}
@@ -79,14 +79,14 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
await fs.mkdir(path.join("dump", id), { recursive: true });
await fs.writeFile(path.join("dump", id, `${Date.now()}.in.json`), JSON.stringify(data, null, 2));
if (!this.session_id) console.log("[Gateway] Unknown session id, dumping to unknown folder");
if (!this.session_id) console.log(`[Gateway/${this.user_id ?? this.ipAddress}] Unknown session id, dumping to unknown folder`);
}
check.call(this, PayloadSchema, data);
const OPCodeHandler = OPCodeHandlers[data.op];
if (!OPCodeHandler) {
console.error("[Gateway] Unknown opcode " + data.op);
console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Unknown opcode`, data.op);
// TODO: if all opcodes are implemented comment this out:
// this.close(CLOSECODES.Unknown_opcode);
return;
@@ -95,7 +95,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
try {
return await OPCodeHandler.call(this, data);
} catch (error) {
console.error(`Error: Op ${data.op}`, error);
console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Error: Op ${data.op}`, error);
// if (!this.CLOSED && this.CLOSING)
return this.close(CLOSECODES.Unknown_error);
}

View File

@@ -340,7 +340,12 @@ async function consume(this: WebSocket, opts: EventOpts) {
if (event === "GUILD_MEMBER_ADD") {
if ((data as PublicMember).roles === undefined || (data as PublicMember).roles === null) {
console.log(bgRedBright("[Gateway]"), "[GUILD_MEMBER_ADD] roles is undefined, setting to empty array!", opts.origin ?? "(Event origin not defined)", data);
console.log(
bgRedBright(`[Gateway/${this.user_id}]`),
"[GUILD_MEMBER_ADD] roles is undefined, setting to empty array!",
opts.origin ?? "(Event origin not defined)",
data,
);
(data as PublicMember).roles = [];
}
}

View File

@@ -19,5 +19,7 @@ export async function onGuildSubscriptionsBulk(this: WebSocket, payload: Payload
},
});
}
console.log(`[Gateway] GuildSubscriptionsBulk processed ${Object.keys(body.subscriptions).length} subscriptions for user ${this.user_id} in ${Date.now() - startTime}ms`);
console.log(
`[Gateway/${this.user_id}] GuildSubscriptionsBulk processed ${Object.keys(body.subscriptions).length} subscriptions for user ${this.user_id} in ${Date.now() - startTime}ms`,
);
}

View File

@@ -71,14 +71,14 @@ export async function onGuildSync(this: WebSocket, { d }: Payload) {
// not awaiting lol
Promise.all(tasks)
.then((res) => {
console.log(`[Gateway] GUILD_SYNC processed ${guild_ids.length} guilds in ${sw.elapsed().totalMilliseconds}ms:`, {
console.log(`[Gateway/${this.user_id}] GUILD_SYNC processed ${guild_ids.length} guilds in ${sw.elapsed().totalMilliseconds}ms:`, {
...Object.fromEntries(
res.map((r) => [r.result.id, `${r.result.id}: ${r.result.members.length}U/${r.result.presences.length}P in ${r.elapsed.totalMilliseconds}ms`]),
),
});
})
.catch((err) => {
console.error("[Gateway] Error processing GUILD_SYNC:", err);
console.error(`[Gateway/${this.user_id}] Error processing GUILD_SYNC:`, err);
});
}

View File

@@ -103,7 +103,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
const user = tokenData.user;
if (!user) {
console.log("[Gateway] Failed to identify user");
console.log(`[Gateway/${this.ipAddress}] Failed to identify user`);
return this.close(CLOSECODES.Authentication_failed);
}
@@ -124,7 +124,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
if (this.shard_count == null || this.shard_id == null || this.shard_id > this.shard_count || this.shard_id < 0 || this.shard_count <= 0) {
// TODO: why do we even care about this right now?
console.log(`[Gateway] Invalid sharding from ${user.id}: ${identify.shard}`);
console.log(`[Gateway/${this.user_id}] Invalid sharding from ${user.id}: ${identify.shard}`);
return this.close(CLOSECODES.Invalid_shard);
}
}
@@ -374,7 +374,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
trace.micros = totalSw.elapsed().totalMicroseconds;
mergeMemberGuildsTrace.calls!.push(`guild_${m.guild_id}`, trace);
} else {
console.error(`[Gateway] Member ${m.id} has invalid guild_id ${m.guild_id}`);
console.error(`[Gateway/${this.user_id}] Member ${m.id} has invalid guild_id ${m.guild_id}`);
mergeMemberGuildsTrace.calls!.push(`guild_~~${m.guild_id}~~`, trace);
}
});
@@ -781,7 +781,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
]
: [],
},
})?.catch((e) => console.error(`[Gateway] error when sending bot guilds`, e));
})?.catch((e) => console.error(`[Gateway/${this.user_id}] error when sending bot guilds`, e));
}),
);
@@ -815,5 +815,8 @@ export async function onIdentify(this: WebSocket, data: Payload) {
//TODO send GUILD_MEMBER_LIST_UPDATE
//TODO send VOICE_STATE_UPDATE to let the client know if another device is already connected to a voice channel
await setupListener.call(this);
console.log(`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, process.env.LOG_GATEWAY_TRACES ? JSON.stringify(d._trace, null, 2) : "");
console.log(
`[Gateway/${this.user_id}] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`,
process.env.LOG_GATEWAY_TRACES ? JSON.stringify(d._trace, null, 2) : "",
);
}

View File

@@ -275,5 +275,5 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
},
});
console.log(`[Gateway] LAZY_REQUEST ${guild_id} ${channel_id} took ${Date.now() - startTime}ms`);
console.log(`[Gateway/${this.user_id}] LAZY_REQUEST ${guild_id} ${channel_id} took ${Date.now() - startTime}ms`);
}

View File

@@ -184,5 +184,5 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
});
});
console.log(`[Gateway] REQUEST_GUILD_MEMBERS took ${Date.now() - startTime}ms for guild ${guild_id} with ${members.length} members`);
console.log(`[Gateway/${this.user_id}] REQUEST_GUILD_MEMBERS took ${Date.now() - startTime}ms for guild ${guild_id} with ${members.length} members`);
}

View File

@@ -109,7 +109,7 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
channel_id: voiceState.channel_id,
} as VoiceStateUpdateEvent);
console.log(`[Gateway] STREAM_CREATE for user ${this.user_id} in channel ${body.channel_id} with stream key ${streamKey} in ${Date.now() - startTime}ms`);
console.log(`[Gateway/${this.user_id}] STREAM_CREATE for user ${this.user_id} in channel ${body.channel_id} with stream key ${streamKey} in ${Date.now() - startTime}ms`);
}
//stream key:

View File

@@ -69,5 +69,5 @@ export async function onStreamDelete(this: WebSocket, data: Payload) {
channel_id: channelId,
} as StreamDeleteEvent);
console.log(`[Gateway] STREAM_DELETE for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
console.log(`[Gateway/${this.user_id}] STREAM_DELETE for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
}

View File

@@ -82,5 +82,5 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
user_id: this.user_id,
} as StreamServerUpdateEvent);
console.log(`[Gateway] STREAM_WATCH for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
console.log(`[Gateway/${this.user_id}] STREAM_WATCH for user ${this.user_id} in channel ${channelId} with stream key ${body.stream_key} in ${Date.now() - startTime}ms`);
}

View File

@@ -141,5 +141,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
} as VoiceServerUpdateEvent);
}
console.log(`[Gateway] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`);
console.log(
`[Gateway/${this.user_id}] VOICE_STATE_UPDATE for user ${this.user_id} in channel ${voiceState.channel_id} in guild ${voiceState.guild_id} in ${Date.now() - startTime}ms`,
);
}