Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Add custom trace performance monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shauryaaher committed Apr 3, 2022
1 parent 3fc176d commit 1270dd5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {

import { initializeAppCheck, ReCaptchaV3Provider } from "firebase/app-check";

import { getPerformance } from "firebase/performance";
import { getPerformance, trace } from "firebase/performance";

import { getAnalytics } from "firebase/analytics";

Expand All @@ -40,7 +40,7 @@ const firebaseConfig = {
// Initialize App
const app = initializeApp(firebaseConfig);

getPerformance(app);
const performance = getPerformance(app);
getAnalytics(app);

initializeAppCheck(app, {
Expand All @@ -54,6 +54,8 @@ const authProvider = new GoogleAuthProvider();

export default class App extends Component {
async signInWithGoogle(e) {
const t = trace(performance, "Sign in with Google");
t.start();
e.preventDefault();
try {
await signInWithPopup(auth, authProvider);
Expand All @@ -63,8 +65,11 @@ export default class App extends Component {
} catch (error) {
console.error(error);
}
t.stop();
}
async signUserOut(e) {
const t = trace(performance, "Sign out");
t.start();
e.preventDefault();
try {
await signOut(auth);
Expand All @@ -74,6 +79,7 @@ export default class App extends Component {
} catch (error) {
console.error(error);
}
t.stop();
}
async deleteAccount(e) {
e.preventDefault();
Expand Down Expand Up @@ -113,6 +119,8 @@ export default class App extends Component {
};
}
componentDidMount() {
const t = trace(performance, "Get Firestore data");
t.start();
this.changeAuthState();
const q = query(collection(firestore, "col"));
onSnapshot(q, (querySnapshot) => {
Expand All @@ -122,8 +130,11 @@ export default class App extends Component {
});
});
});
t.stop();
}
render() {
const t = trace(performance, "Load React DOM elements");
t.start();
return (
<div>
<div
Expand Down Expand Up @@ -178,5 +189,6 @@ export default class App extends Component {
<ul id="showData"><li>{JSON.stringify(this.state.data)}</li></ul>
</div>
);
t.stop();
}
}

0 comments on commit 1270dd5

Please sign in to comment.