Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Faro for SPA #254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
.env

# Editor directories and files
.vscode/*
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# todo-react

Kinsey notes:
works on node 22.

```
yarn
yarn build
yarn run preview
```

Added a `.env` file with the generated Faro url from my Grafana Cloud instance as this is sensitive data.
A drawback to this app is it's a single page app so you won't see route changes.

---


Sample todo app built with the React/ReactDOM framework. For the accompanying documentation, see
[Understanding client-side JavaScript frameworks
: React tutorials](https://wiki.developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks#React_tutorials).
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"preview": "vite preview"
},
"dependencies": {
"@grafana/faro-react": "^1.14.1",
"@grafana/faro-web-sdk": "^1.14.1",
"@grafana/faro-web-tracing": "^1.14.1",
"nanoid": "^5.1.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^7.4.0"
},
"devDependencies": {
"@types/react": "^18.2.79",
Expand Down
28 changes: 28 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
import { matchRoutes } from 'react-router-dom';
import { initializeFaro, createReactRouterV6DataOptions, ReactIntegration, getWebInstrumentations, } from '@grafana/faro-react';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';

// eslint-disable-next-line react-refresh/only-export-components
const DATA = [
Expand All @@ -10,6 +13,31 @@ const DATA = [
{ id: "todo-2", name: "Repeat", completed: false },
];

const FARO_URL = process.env.FARO_URL;

initializeFaro({
url: FARO_URL,
app: {
name: 'todo-list',
version: '1.0.0',
environment: 'production'
},
sessionTracking: {
samplingRate: 1,
persistent: true
},
instrumentations: [
// Mandatory, omits default instrumentations otherwise.
...getWebInstrumentations(),

// Tracing package to get end-to-end visibility for HTTP requests.
new TracingInstrumentation(),

// React integration without router, since this is a single-page app.
new ReactIntegration(),
],
});

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App tasks={DATA} />
Expand Down
3 changes: 2 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
base: "https://mdn.github.io/todo-react/"
// base: "https://mdn.github.io/todo-react/"
base: '/todo-react/'
})
Loading