summary refs log tree commit diff
path: root/src/gateway/events/Message.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-22 15:39:15 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-09-22 15:46:35 +1000
commit3c4691499249e184f4e418ae798379f98d5f4cff (patch)
tree952a1f634bd860aec68064151580aed0cbbfb78f /src/gateway/events/Message.ts
parenta ton of broken shit and approx 1 nice function (diff)
parentMerge branch 'master' of github.com:spacebarchat/server (diff)
downloadserver-feat/federation.tar.xz
Merge branch 'master' into feat/federation feat/federation
Diffstat (limited to 'src/gateway/events/Message.ts')
-rw-r--r--src/gateway/events/Message.ts55
1 files changed, 25 insertions, 30 deletions
diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts

index 45790146..52d9edd8 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts
@@ -16,15 +16,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { WebSocket, Payload, CLOSECODES, OPCODES } from "@spacebar/gateway"; -import OPCodeHandlers from "../opcodes"; -import { check } from "../opcodes/instanceOf"; -import WS from "ws"; -import { PayloadSchema, ErlpackType } from "@spacebar/util"; import * as Sentry from "@sentry/node"; +import { CLOSECODES, OPCODES, Payload, WebSocket } from "@spacebar/gateway"; +import { ErlpackType, PayloadSchema } from "@spacebar/util"; +import fs from "fs/promises"; import BigIntJson from "json-bigint"; import path from "path"; -import fs from "fs/promises"; +import WS from "ws"; +import OPCodeHandlers from "../opcodes"; +import { check } from "../opcodes/instanceOf"; const bigIntJson = BigIntJson({ storeAsString: true }); let erlpack: ErlpackType | null = null; @@ -88,33 +88,28 @@ export async function Message(this: WebSocket, buffer: WS.Data) { return; } - const transaction = - data.op != 1 - ? Sentry.startTransaction({ - op: OPCODES[data.op], - name: `GATEWAY ${OPCODES[data.op]}`, - data: { - ...data.d, - token: data?.d?.token ? "[Redacted]" : undefined, - }, - }) - : undefined; - try { - const ret = await OPCodeHandler.call(this, data); - Sentry.withScope((scope) => { - scope.setSpan(transaction); - scope.setUser({ id: this.user_id }); - transaction?.finish(); - }); - return ret; + return await Sentry.startActiveSpan( + { + op: "websocket.server", + name: `GATEWAY ${OPCODES[data.op]}`, + data: { + ...data.d, + token: data?.d?.token ? "[Redacted]" : undefined, + }, + }, + async () => { + const ret = await OPCodeHandler.call(this, data); + Sentry.setUser({ id: this.user_id }); + return ret; + }, + ); } catch (error) { - Sentry.withScope((scope) => { - scope.setSpan(transaction); - if (this.user_id) scope.setUser({ id: this.user_id }); - Sentry.captureException(error); + Sentry.captureException(error, { + user: { + id: this.user_id, + }, }); - transaction?.finish(); console.error(`Error: Op ${data.op}`, error); // if (!this.CLOSED && this.CLOSING) return this.close(CLOSECODES.Unknown_error);