Created
January 31, 2021 16:44
-
-
Save jasonLaster/eafcec73fd48f1560691e044ffc43c60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/ui/components/App.tsx b/src/ui/components/App.tsx | |
index 31622494..e3d8d941 100644 | |
--- a/src/ui/components/App.tsx | |
+++ b/src/ui/components/App.tsx | |
@@ -12,7 +12,6 @@ import { selectors } from "ui/reducers"; | |
import { actions } from "ui/actions"; | |
import { hasLoadingParam } from "ui/utils/environment"; | |
import ResizeObserverPolyfill from "resize-observer-polyfill"; | |
-import hooks from "ui/hooks"; | |
import LogRocket from "ui/utils/logrocket"; | |
import "styles.css"; | |
@@ -54,19 +53,10 @@ function App({ theme, recordingId, modal, updateNarrowMode }: AppProps) { | |
}, [theme]); | |
useEffect(() => { | |
- const setUserInLogRocket = async () => { | |
- if (auth.user) { | |
- const userId = await hooks.fetchUserId(auth.user.sub); | |
- LogRocket.identify(auth.user.sub, { | |
- name: auth.user.name, | |
- email: auth.user.email, | |
- id: userId, | |
- }); | |
- } | |
- }; | |
- | |
setUserInBrowserPrefs(auth.user); | |
- setUserInLogRocket(); | |
+ if (auth.user) { | |
+ LogRocket.createSession(auth); | |
+ } | |
}, [auth.user]); | |
if ((!isDeployPreview() && auth.isLoading) || hasLoadingParam()) { | |
diff --git a/src/ui/utils/bootstrap/bootstrap.tsx b/src/ui/utils/bootstrap/bootstrap.tsx | |
index e36c38d2..bb3ad7ac 100644 | |
--- a/src/ui/utils/bootstrap/bootstrap.tsx | |
+++ b/src/ui/utils/bootstrap/bootstrap.tsx | |
@@ -10,7 +10,6 @@ import App, { AppProps } from "ui/components/App"; | |
const { PopupBlockedError } = require("ui/components/shared/Error"); | |
import tokenManager from "ui/utils/tokenManager"; | |
import useToken from "ui/utils/useToken"; | |
-import LogRocket from "ui/utils/logrocket"; | |
import { createApolloClient } from "ui/utils/apolloClient"; | |
import { ApolloProvider } from "@apollo/client"; | |
@@ -18,19 +17,6 @@ import { isDevelopment, isTest } from "../environment"; | |
import { UIStore } from "ui/actions"; | |
const skipTelemetry = isTest() || isDevelopment(); | |
-function setupLogRocket() { | |
- if (skipTelemetry) { | |
- return; | |
- } | |
- | |
- LogRocket.init(); | |
- LogRocket.getSessionURL(sessionURL => { | |
- Sentry.configureScope(scope => { | |
- scope.setExtra("sessionURL", sessionURL); | |
- }); | |
- }); | |
-} | |
- | |
export function setupSentry(context: Record<string, any>) { | |
const ignoreList = ["Current thread has paused or resumed", "Current thread has changed"]; | |
@@ -79,7 +65,6 @@ function ApolloWrapper({ children }: { children: ReactNode }) { | |
export function bootstrapApp(props: AppProps, context: Record<string, any>, store: UIStore) { | |
setupSentry(context); | |
- setupLogRocket(); | |
ReactDOM.render( | |
<Router> | |
diff --git a/src/ui/utils/environment.ts b/src/ui/utils/environment.ts | |
index a97f01fd..8579cb23 100644 | |
--- a/src/ui/utils/environment.ts | |
+++ b/src/ui/utils/environment.ts | |
@@ -16,6 +16,10 @@ export function isTest() { | |
return getTest() != null; | |
} | |
+export function skipTelemetry() { | |
+ return isTest() || isDevelopment(); | |
+} | |
+ | |
export function isDeployPreview() { | |
return url.hostname.includes("replay-devtools.netlify.app"); | |
} | |
diff --git a/src/ui/utils/logrocket.ts b/src/ui/utils/logrocket.ts | |
index 25b34e6e..8c53ee96 100644 | |
--- a/src/ui/utils/logrocket.ts | |
+++ b/src/ui/utils/logrocket.ts | |
@@ -1,16 +1,32 @@ | |
import LogRocket from "logrocket"; | |
import setupLogRocketReact from "logrocket-react"; | |
+import * as Sentry from "@sentry/react"; | |
+import { skipTelemetry } from "./environment"; | |
let setup = false; | |
export default { | |
- init: () => { | |
+ createSession: (auth: any) => { | |
+ if (skipTelemetry()) { | |
+ return; | |
+ } | |
+ | |
setup = true; | |
setupLogRocketReact(LogRocket); | |
LogRocket.init("4sdo4i/replay"); | |
+ LogRocket.getSessionURL(sessionURL => { | |
+ Sentry.configureScope(scope => { | |
+ scope.setExtra("sessionURL", sessionURL); | |
+ }); | |
+ }); | |
+ | |
+ LogRocket.identify(auth.user.sub, { | |
+ name: auth.user.name, | |
+ email: auth.user.email, | |
+ id: auth.user.email, | |
+ }); | |
}, | |
- identify: (uuid: string, attributes: Record<string, string | number | boolean>) => | |
- setup && LogRocket.identify(uuid, attributes), | |
+ | |
getSessionURL: (callback: (sessionUrl: string) => void) => | |
setup && LogRocket.getSessionURL(callback), | |
reduxMiddleware: () => |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment