mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-28 00:35:25 +08:00
sending client version in headers
logging which client versions are getting errors closes #4475
This commit is contained in:
parent
5abc29bb76
commit
2e8c58365f
3 changed files with 17 additions and 0 deletions
|
@ -5,6 +5,7 @@ import MonkeyError from "../utils/error";
|
|||
import { incrementBadAuth } from "./rate-limit";
|
||||
import { NextFunction, Response } from "express";
|
||||
import { MonkeyResponse, handleMonkeyResponse } from "../utils/monkey-response";
|
||||
import { recordClientErrorByVersion } from "../utils/prometheus";
|
||||
|
||||
async function errorHandlingMiddleware(
|
||||
error: Error,
|
||||
|
@ -37,6 +38,10 @@ async function errorHandlingMiddleware(
|
|||
|
||||
await incrementBadAuth(req, res, monkeyResponse.status);
|
||||
|
||||
if (monkeyResponse.status >= 400 && monkeyResponse.status < 500) {
|
||||
recordClientErrorByVersion(req.headers["x-client-version"] as string);
|
||||
}
|
||||
|
||||
if (process.env.MODE !== "dev" && monkeyResponse.status >= 500) {
|
||||
const { uid, errorId } = monkeyResponse.data;
|
||||
|
||||
|
|
|
@ -179,6 +179,16 @@ export function recordServerVersion(serverVersion: string): void {
|
|||
serverVersionCounter.inc({ version: serverVersion });
|
||||
}
|
||||
|
||||
const clientErrorByVersion = new Counter({
|
||||
name: "api_client_error_by_version",
|
||||
help: "Client versions which are experiencing 400 errors",
|
||||
labelNames: ["version"],
|
||||
});
|
||||
|
||||
export function recordClientErrorByVersion(version: string): void {
|
||||
clientErrorByVersion.inc({ version });
|
||||
}
|
||||
|
||||
const authTime = new Histogram({
|
||||
name: "api_request_auth_time",
|
||||
help: "Time spent authenticating",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Auth } from "../../firebase";
|
||||
import { getIdToken } from "firebase/auth";
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import { CLIENT_VERSION } from "../../version";
|
||||
|
||||
type AxiosClientMethod = (
|
||||
endpoint: string,
|
||||
|
@ -27,6 +28,7 @@ async function adaptRequestOptions(
|
|||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
...(idToken && { Authorization: `Bearer ${idToken}` }),
|
||||
"X-Client-Version": CLIENT_VERSION,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue