Replace Raygun with Sentry

This commit is contained in:
Marks Polakovs 2021-04-25 09:48:37 +01:00
parent b57d04f894
commit 60e318bb0b
13 changed files with 172 additions and 96 deletions

1
.env
View file

@ -5,3 +5,4 @@ REACT_APP_MYRADIO_NONAPI_BASE=https://ury.org.uk/myradio-staging
REACT_APP_MYRADIO_BASE=https://ury.org.uk/api-staging/v2
REACT_APP_BROADCAST_API_BASE=https://ury.org.uk/webstudio/api/v1
REACT_APP_WS_URL=wss://ury.org.uk/webstudio/api/stream
REACT_APP_PUBLIC_SENTRY_DSN=https://7bdc2a7a1eb24ae080eb1d3af75e6307@o578586.ingest.sentry.io/5734903

View file

@ -5,6 +5,8 @@
"dependencies": {
"@babel/core": "7.6.0",
"@reduxjs/toolkit": "^1.0.4",
"@sentry/react": "^6.3.1",
"@sentry/tracing": "^6.3.1",
"@svgr/webpack": "4.3.2",
"@types/dom-mediacapture-record": "^1.0.4",
"@types/jest": "24.0.22",
@ -13,7 +15,6 @@
"@types/lodash": "^4.14.149",
"@types/node": "^13.11.0",
"@types/qs": "^6.9.0",
"@types/raygun4js": "^2.13.2",
"@types/react": "16.9.11",
"@types/react-beautiful-dnd": "^11.0.3",
"@types/react-beforeunload": "^2.1.0",
@ -72,7 +73,6 @@
"postcss-safe-parser": "4.0.1",
"prop-types": "^15.0.0",
"qs": "^6.9.1",
"raygun4js": "^2.18.3",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.4",
"react-beautiful-dnd": "^12.1.1",

View file

@ -1,9 +1,11 @@
aiohttp==3.6.2
aioice==0.6.18
aiortc==0.9.27
appdirs==1.4.4
async-timeout==3.0.1
attrs==19.3.0
av==7.0.1
black==20.8b1
blinker==1.4
certifi==2020.4.5.1
cffi==1.14.0
@ -11,6 +13,7 @@ chardet==3.0.4
click==7.1.1
crc32c==2.0
cryptography==2.8
expiringdict==1.2.1
Flask==1.1.2
Flask-Cors==3.0.8
gunicorn==20.0.4
@ -26,6 +29,7 @@ mypy==0.770
mypy-extensions==0.4.3
netifaces==0.10.9
parso==0.6.2
pathspec==0.8.1
pluggy==0.13.1
pycparser==2.20
pyee==7.0.1
@ -37,9 +41,11 @@ python-dateutil==2.8.1
python-jsonrpc-server==0.3.4
python-language-server==0.31.9
pytz==2019.3
raygun4py==4.3.0
regex==2020.11.13
requests==2.23.0
sentry-sdk==1.0.0
six==1.14.0
toml==0.10.2
twilio==6.38.1
typed-ast==1.4.1
typing-extensions==3.7.4.2

View file

@ -1,5 +1,5 @@
[raygun]
key = CHANGEME
[sentry]
dsn = CHANGEME
enable = False
[twilio]

View file

@ -15,23 +15,16 @@ import jack as Jack # type: ignore
import websockets
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription # type: ignore
from aiortc.mediastreams import MediaStreamError # type: ignore
from raygun4py import raygunprovider # type: ignore
import sentry_sdk
config = configparser.RawConfigParser()
config.read("serverconfig.ini")
if config.get("raygun", "enable") == "True":
def handle_exception(
exc_type: Type[BaseException],
exc_value: BaseException,
exc_traceback: TracebackType,
) -> None:
sys.__excepthook__(exc_type, exc_value, exc_traceback)
cl = raygunprovider.RaygunSender(config.get("raygun", "key"))
cl.send_exception(exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = handle_exception
if config.get("sentry", "enable") == "True":
sentry_sdk.init(
config.get("sentry", "dsn"),
traces_sample_rate=1.0
)
file_contents_ex = re.compile(r"^ws=\d$")
@ -331,7 +324,7 @@ class Session(object):
print(self.connection_id, "Connected")
ice_config = get_turn_credentials()
print(self.connection_id, "Obtained ICE")
# TODO Raygun user ID
sentry_sdk.set_context("session", {"session_id": self.connection_id})
await websocket.send(
json.dumps({"kind": "HELLO", "connectionId": self.connection_id, "iceServers": ice_config})
)

View file

@ -311,6 +311,7 @@ export interface User {
sname: string;
url: string;
photo: string;
public_email?: string;
}
export function getCurrentApiUser(): Promise<User> {

View file

@ -1,7 +1,7 @@
import SdpTransform from "sdp-transform";
import * as later from "later";
import raygun from "raygun4js";
import * as Sentry from "@sentry/react";
import * as BroadcastState from "./state";
@ -44,9 +44,7 @@ export class WebRTCStreamer extends Streamer {
}
async stop(reason?: string): Promise<void> {
raygun("send", {
error: new Error("Connection stop due to " + reason),
});
Sentry.captureException(new Error(`Connection STOP due to ${reason}`));
if (this.ws) {
this.ws.close();
this.ws = null as any;

View file

@ -156,7 +156,7 @@ export const registerForShow = (): AppThunk => async (dispatch, getState) => {
}
}
} else {
// let raygun handle it
// let sentry handle it
throw e;
}
}
@ -182,7 +182,7 @@ export const cancelTimeslot = (): AppThunk => async (dispatch, getState) => {
})
);
} else {
// let raygun handle it
// let sentry handle it
throw e;
}
}

View file

@ -4,25 +4,30 @@ import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorkerLoader";
import raygun from "raygun4js";
import * as Sentry from "@sentry/react";
import { Integrations } from "@sentry/tracing";
import store, { getActionHistory } from "./store";
import store from "./store";
import { Provider } from "react-redux";
raygun("apiKey", "mtj24r3YzPoYyCG8cVArA");
raygun("enableCrashReporting", true);
if (
typeof process.env.REACT_APP_VERSION === "string" &&
process.env.REACT_APP_VERSION.length > 0
) {
raygun("setVersion", process.env.REACT_APP_VERSION);
function getEnvironment() {
// this is only set when building for prod
if (process.env.REACT_APP_PRODUCTION === "true") {
return "production";
}
if (process.env.NODE_ENV === "production") {
return "webstudio-dev";
}
return process.env.NODE_ENV;
}
raygun("withCustomData", function() {
return {
state: store.getState(),
actionHistory: getActionHistory(),
};
Sentry.init({
dsn: process.env.REACT_APP_SENTRY_PUBLIC_DSN,
integrations: [new Integrations.BrowserTracing()],
tracesSampleRate: 1.0,
environment: getEnvironment(),
release: process.env.REACT_APP_VERSION,
normalizeDepth: 10,
});
function render() {

View file

@ -8,7 +8,7 @@ import {
doesCurrentUserHavePermission,
} from "../api";
import raygun from "raygun4js";
import * as Sentry from "@sentry/react";
const BROADCAST_PERMISSION_ID = 340;
@ -86,10 +86,10 @@ export const getUser = (): AppThunk => async (dispatch) => {
getCurrentApiUser(),
doesCurrentUserHavePermission(BROADCAST_PERMISSION_ID),
]);
raygun("setUser", {
identifier: user.memberid.toString(10),
firstName: user.fname,
fullName: user.fname + " " + user.sname,
Sentry.setUser({
id: user.memberid.toString(10),
email: user.public_email,
username: user.fname + " " + user.sname,
});
dispatch(sessionState.actions.setCurrentUser({ user, canBroadcast }));
} catch (e) {
@ -102,6 +102,7 @@ export const getTimeslot = (): AppThunk => async (dispatch) => {
dispatch(sessionState.actions.getTimeslotStarting());
try {
const timeslot = await getCurrentApiTimeslot();
Sentry.setTag("timeslot_id", timeslot.timeslot_id);
dispatch(sessionState.actions.getTimeslotSuccess(timeslot));
} catch (e) {
console.log("Failed to get selected timeslot. " + e.toString());

View file

@ -3,7 +3,7 @@ import * as api from "../api";
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { AppThunk } from "../store";
import { cloneDeep } from "lodash";
import raygun from "raygun4js";
import * as Sentry from "@sentry/react";
export interface ItemGhost {
type: "ghost";
@ -359,11 +359,12 @@ export const moveItem = (
if (getState().settings.saveShowPlanChanges) {
const result = await api.updateShowplan(timeslotid, ops);
if (!result.every((x) => x.status)) {
raygun("send", {
error: new Error("Showplan update failure [moveItem]"),
customData: {
ops,
result,
Sentry.captureException(new Error("Showplan update failure [moveItem]"), {
contexts: {
updateShowplan: {
ops,
result,
},
},
});
dispatch(showplan.actions.planSaveError("Failed to update show plan."));
@ -443,11 +444,12 @@ export const addItem = (
});
const result = await api.updateShowplan(timeslotId, ops);
if (!result.every((x) => x.status)) {
raygun("send", {
error: new Error("Showplan update failure [addItem]"),
customData: {
ops,
result,
Sentry.captureException(new Error("Showplan update failure [addItem]"), {
contexts: {
updateShowplan: {
ops,
result,
},
},
});
dispatch(showplan.actions.planSaveError("Failed to update show plan."));
@ -506,11 +508,12 @@ export const removeItem = (
if (getState().settings.saveShowPlanChanges) {
const result = await api.updateShowplan(timeslotId, ops);
if (!result.every((x) => x.status)) {
raygun("send", {
error: new Error("Showplan update failure [removeItem]"),
customData: {
ops,
result,
Sentry.captureException(new Error("Showplan update failure [addItem]"), {
contexts: {
updateShowplan: {
ops,
result,
},
},
});
dispatch(showplan.actions.planSaveError("Failed to update show plan."));

View file

@ -1,10 +1,4 @@
import {
configureStore,
Action,
getDefaultMiddleware,
Middleware,
Dispatch,
} from "@reduxjs/toolkit";
import { configureStore, Action, getDefaultMiddleware } from "@reduxjs/toolkit";
import rootReducer, { RootState } from "./rootReducer";
import { ThunkAction } from "redux-thunk";
import {
@ -21,27 +15,30 @@ import {
PURGE,
REGISTER,
} from "redux-persist";
import * as Sentry from "@sentry/react";
const ACTION_HISTORY_MAX_SIZE = 20;
// const ACTION_HISTORY_MAX_SIZE = 20;
const actionHistory: Array<Action> = [];
// const actionHistory: Array<Action> = [];
const actionHistoryMiddleware: Middleware<{}, RootState, Dispatch<any>> = (
store
) => (next) => (action) => {
while (actionHistory.length > ACTION_HISTORY_MAX_SIZE) {
actionHistory.shift();
}
actionHistory.push({
...action,
_timestamp: new Date().toString(),
});
return next(action);
};
// const actionHistoryMiddleware: Middleware<{}, RootState, Dispatch<any>> = (
// store
// ) => (next) => (action) => {
// while (actionHistory.length > ACTION_HISTORY_MAX_SIZE) {
// actionHistory.shift();
// }
// actionHistory.push({
// ...action,
// _timestamp: new Date().toString(),
// });
// return next(action);
// };
export function getActionHistory() {
return actionHistory;
}
// export function getActionHistory() {
// return actionHistory;
// }
const sentryEnhancer = Sentry.createReduxEnhancer({});
// See https://github.com/rt2zz/redux-persist/issues/988 for getDefaultMiddleware tweak.
const store = configureStore({
@ -49,13 +46,14 @@ const store = configureStore({
middleware: [
mixerMiddleware,
mixerKeyboardShortcutsMiddleware,
actionHistoryMiddleware,
// actionHistoryMiddleware,
...getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}),
],
enhancers: [sentryEnhancer],
});
if (process.env.NODE_ENV === "development" && module.hot) {

View file

@ -1425,6 +1425,81 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"
"@sentry/browser@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-6.3.1.tgz#6142dd4c72308f4e1a12e585e3300fd54ca058cd"
integrity sha512-Ri4tYsyuJIeLQnvQUqbpGzailUYpbjFSYM0+yEM63gPsjiXdg+W8yKHluA6cs6FLWVN3oWfwHW7Kd61echlGuw==
dependencies:
"@sentry/core" "6.3.1"
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
tslib "^1.9.3"
"@sentry/core@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-6.3.1.tgz#5e32ca919c9be30fec0bb3125a556bc711584bdf"
integrity sha512-aVuvVbaehGeN86jZlLDGGkhEtprdOtB6lvYLfGy40Dj1Tkh2mGWE550QsRXAXAqYvQzIYwQR23r6m3o8FujgVg==
dependencies:
"@sentry/hub" "6.3.1"
"@sentry/minimal" "6.3.1"
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
tslib "^1.9.3"
"@sentry/hub@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-6.3.1.tgz#dda07888a82d1c48bbefa00205bfa9d035691f07"
integrity sha512-2er+OeVlsdVZkhl9kXQAANwgjwoCdM1etK2iFuhzX8xkMaJlAuZLyQInv2U1BbXBlIfWjvzRM8B95hCWvVrR3Q==
dependencies:
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
tslib "^1.9.3"
"@sentry/minimal@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-6.3.1.tgz#38f71c77e8820555effb6e868336d4f5672018cd"
integrity sha512-0eN9S7HvXsCQEjX/qXHTMgvSb3mwrnZEWS9Qz/Bz5ig9pEGXKgJ1om5NTTHVHhXqd3wFCjdvIo6slufLHoCtSw==
dependencies:
"@sentry/hub" "6.3.1"
"@sentry/types" "6.3.1"
tslib "^1.9.3"
"@sentry/react@^6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-6.3.1.tgz#5082aa145972eec38cc8ceea8e5d8ee3f7f5f86a"
integrity sha512-3eFSqdS0QAb4RFNxS0gzVm05q8c5KQp+3TlmqBjoovqWL/FvGvDoqaBmFT+arvPZ88qngveMEk1v6445L0gFTg==
dependencies:
"@sentry/browser" "6.3.1"
"@sentry/minimal" "6.3.1"
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
hoist-non-react-statics "^3.3.2"
tslib "^1.9.3"
"@sentry/tracing@^6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-6.3.1.tgz#3b96aabf4d9cebadfec070c006db79801a68ee24"
integrity sha512-qveDmoWsXy9qLEblZJwJ1OU/zZRlEd/q7Jhd0Hnwlob8Ci96huABEbYyGdJs18BKVHEFU3gSdVfvrikUE/W17g==
dependencies:
"@sentry/hub" "6.3.1"
"@sentry/minimal" "6.3.1"
"@sentry/types" "6.3.1"
"@sentry/utils" "6.3.1"
tslib "^1.9.3"
"@sentry/types@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.3.1.tgz#af3b54728b29f633f38fbe51b8c10e3834fbc158"
integrity sha512-BEBn8JX1yaooCAuonbaMci9z0RjwwMbQ3Eny/eyDdd+rjXprZCZaStZnCvSThbNBqAJ8YaUqY2YBMnEwJxarAw==
"@sentry/utils@6.3.1":
version "6.3.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.3.1.tgz#6d8e691139b5b49d8c655ad1dcaf2cb3ff0d0b03"
integrity sha512-cdtl/QWC9FtinAuW3w8QfvSfh/Q9ui5vwvjzVHiS1ga/U38edi2XX+cttY39ZYwz0SQG99cE10GOIhd1p7/mAA==
dependencies:
"@sentry/types" "6.3.1"
tslib "^1.9.3"
"@surma/rollup-plugin-off-main-thread@^1.1.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-1.4.1.tgz#bf1343e5a926e5a1da55e3affd761dda4ce143ef"
@ -1735,11 +1810,6 @@
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.3.tgz#b755a0934564a200d3efdf88546ec93c369abd03"
integrity sha512-7s9EQWupR1fTc2pSMtXRQ9w9gLOcrJn+h7HOXw4evxyvVqMi4f+q7d2tnFe3ng3SNHjtK+0EzGMGFUQX4/AQRA==
"@types/raygun4js@^2.13.2":
version "2.13.3"
resolved "https://registry.yarnpkg.com/@types/raygun4js/-/raygun4js-2.13.3.tgz#24be92a9e21ae5fa7b954b5ed31922987b5c77cb"
integrity sha512-tx7hfTXUTYF3XxPrRaVwL/nYQAdQS1PuOkyvkgJyzoAleLs+ezIG66lb5aEfNZ0NzBDp7/hanEvFuptCjjGzPg==
"@types/react-beautiful-dnd@^11.0.3":
version "11.0.5"
resolved "https://registry.yarnpkg.com/@types/react-beautiful-dnd/-/react-beautiful-dnd-11.0.5.tgz#2f5bc733dd46da28312c8ee0c126ab7202b90247"
@ -5856,7 +5926,7 @@ hoek@^4.2.1:
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb"
integrity sha512-QLg82fGkfnJ/4iy1xZ81/9SIJiq1NGFUMGs6ParyjBZr6jW2Ufj/snDqTHixNlHdPNwN2RLVD0Pi3igeK9+JfA==
hoist-non-react-statics@^3.3.0:
hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
@ -10068,11 +10138,6 @@ raw-body@2.4.0:
iconv-lite "0.4.24"
unpipe "1.0.0"
raygun4js@^2.18.3:
version "2.18.4"
resolved "https://registry.yarnpkg.com/raygun4js/-/raygun4js-2.18.4.tgz#30fc802c3280b02ef0efe2eee309e030250071d5"
integrity sha512-EwE4FRtlxB3J8Fdw//1mMay8WKOaG6MyyU/8zROLe3rbi2CFoi6YBHK5/E9Z21CCqx/B6fwiKM+mON00p/1d2A==
react-app-polyfill@^1.0.4, react-app-polyfill@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/react-app-polyfill/-/react-app-polyfill-1.0.6.tgz#890f8d7f2842ce6073f030b117de9130a5f385f0"
@ -12199,6 +12264,11 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==
tslib@^1.9.3:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
tsutils@^3.17.1:
version "3.17.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"