sentry db instrumentation for gateway events
This commit is contained in:
parent
eebd61b19d
commit
2fc3c5dbd4
@ -16,15 +16,15 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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 * 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 BigIntJson from "json-bigint";
|
||||||
import path from "path";
|
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 });
|
const bigIntJson = BigIntJson({ storeAsString: true });
|
||||||
|
|
||||||
let erlpack: ErlpackType | null = null;
|
let erlpack: ErlpackType | null = null;
|
||||||
@ -88,33 +88,28 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const transaction =
|
try {
|
||||||
data.op != 1
|
return await Sentry.startActiveSpan(
|
||||||
? Sentry.startTransaction({
|
{
|
||||||
op: OPCODES[data.op],
|
op: "websocket.server",
|
||||||
name: `GATEWAY ${OPCODES[data.op]}`,
|
name: `GATEWAY ${OPCODES[data.op]}`,
|
||||||
data: {
|
data: {
|
||||||
...data.d,
|
...data.d,
|
||||||
token: data?.d?.token ? "[Redacted]" : undefined,
|
token: data?.d?.token ? "[Redacted]" : undefined,
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
: undefined;
|
async () => {
|
||||||
|
|
||||||
try {
|
|
||||||
const ret = await OPCodeHandler.call(this, data);
|
const ret = await OPCodeHandler.call(this, data);
|
||||||
Sentry.withScope((scope) => {
|
Sentry.setUser({ id: this.user_id });
|
||||||
scope.setSpan(transaction);
|
|
||||||
scope.setUser({ id: this.user_id });
|
|
||||||
transaction?.finish();
|
|
||||||
});
|
|
||||||
return ret;
|
return ret;
|
||||||
|
},
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Sentry.withScope((scope) => {
|
Sentry.captureException(error, {
|
||||||
scope.setSpan(transaction);
|
user: {
|
||||||
if (this.user_id) scope.setUser({ id: this.user_id });
|
id: this.user_id,
|
||||||
Sentry.captureException(error);
|
},
|
||||||
});
|
});
|
||||||
transaction?.finish();
|
|
||||||
console.error(`Error: Op ${data.op}`, error);
|
console.error(`Error: Op ${data.op}`, error);
|
||||||
// if (!this.CLOSED && this.CLOSING)
|
// if (!this.CLOSED && this.CLOSING)
|
||||||
return this.close(CLOSECODES.Unknown_error);
|
return this.close(CLOSECODES.Unknown_error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user