Skip to content

Commit e8d4453

Browse files
committed
setup faro to replace sentry for ./web
1 parent 6d839b2 commit e8d4453

File tree

11 files changed

+1024
-259
lines changed

11 files changed

+1024
-259
lines changed

package-lock.json

Lines changed: 947 additions & 213 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"@dzcode.io/data": "*",
1616
"@dzcode.io/models": "*",
1717
"@dzcode.io/utils": "*",
18-
"@sentry/react": "^8.27.0",
18+
"@grafana/faro-react": "^1.17.2",
19+
"@grafana/faro-web-tracing": "^1.17.2",
1920
"react": "^18.3.1",
2021
"react-dom": "^18.3.1",
2122
"react-helmet-async": "^2.0.5"
2223
},
2324
"devDependencies": {
25+
"@grafana/faro-webpack-plugin": "^0.5.1",
2426
"@loadable/component": "^5.16.4",
2527
"@reduxjs/toolkit": "^2.2.6",
2628
"@rsbuild/core": "1.0.9",
@@ -73,7 +75,6 @@
7375
"generate:bundle-info": "tsx ../packages/tooling/bundle-info.ts",
7476
"generate:htmls": "npx tsx src/_build/gen-multiple-htmls.ts",
7577
"generate:robots-txt": "npx tsx src/_build/gen-robots-txt.ts",
76-
"generate:sentry-release": "tsx ../packages/tooling/sentry-release.ts web bundle",
7778
"generate:sitemap": "npx tsx src/_build/sitemap.ts",
7879
"lh:collect": "npx --yes @lhci/cli collect",
7980
"lh:upload": "npx --yes @lhci/cli upload",

web/rsbuild.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { environments } from "@dzcode.io/utils/dist/config/environment";
22
import { defineConfig } from "@rsbuild/core";
33
import { pluginReact } from "@rsbuild/plugin-react";
44
import { readFileSync } from "fs";
5+
import FaroSourceMapUploaderPlugin from "@grafana/faro-webpack-plugin";
56

67
let stage = process.env.STAGE;
78

@@ -21,6 +22,20 @@ try {
2122

2223
export default defineConfig({
2324
plugins: [pluginReact()],
25+
tools: {
26+
webpack: {
27+
plugins: [
28+
new FaroSourceMapUploaderPlugin({
29+
appName: "dzcode",
30+
endpoint: "https://faro-api-prod-eu-west-2.grafana.net/faro/api/v1",
31+
appId: "2897",
32+
stackId: "1236993",
33+
apiKey: process.env.GRAFANA_SOURCEMAP_TOKEN!,
34+
gzipContents: true,
35+
}),
36+
],
37+
},
38+
},
2439
source: {
2540
alias: {
2641
src: "./src",

web/src/_build/gen-multiple-htmls.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { join } from "path";
66
import { readFileSync, writeFileSync, mkdirSync } from "fs";
77
import { allPages } from "./pages";
88
import { Environment, environments } from "@dzcode.io/utils/dist/config/environment";
9-
import { SENTRY_ORIGIN } from "../../src/utils/sentry-origin";
109
import { fsConfig } from "@dzcode.io/utils/dist/config";
1110

1211
let stage = process.env.STAGE as Environment;
@@ -63,7 +62,6 @@ allPages.forEach((pageInfo) => {
6362
pageInfo.canonicalUrl || `${config.web.url}${pageInfo.uri}`,
6463
);
6564
newHtml = newHtml.replace(/{{ogImage}}/g, pageInfo.ogImage);
66-
newHtml = newHtml.replace(/{{sentryOrigin}}/g, `https://${SENTRY_ORIGIN}`);
6765

6866
mkdirSync(outputHtmlParentDir, { recursive: true });
6967
writeFileSync(outputHtmlPath, newHtml);

web/src/_entry/app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./style.css";
22

33
import { HelmetProvider } from "react-helmet-async";
4-
import { BrowserRouter, Route, RouteProps, Routes } from "react-router-dom";
4+
import { BrowserRouter, Route, RouteProps } from "react-router-dom";
55
import { Footer, FooterProps } from "src/components/footer";
66
import { Loadable } from "src/components/loadable";
77
import { TopBar, TopBarProps } from "src/components/top-bar";
@@ -10,6 +10,7 @@ import { getInitialLanguageCode } from "src/utils/website-language";
1010
import React from "react";
1111
import { Search } from "src/components/search";
1212
import { DEFAULT_LANGUAGE } from "@dzcode.io/models/dist/language";
13+
import { Routes } from "src/components/instrumented-routes";
1314

1415
let routes: Array<
1516
RouteProps & {

web/src/_entry/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<meta charset="UTF-8" />
77
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
88
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9-
<link rel="preconnect" href="{{sentryOrigin}}" />
109

1110
<meta name="keywords" content="{{keywords}}" />
1211
<meta name="theme-color" content="{{themeColor}}" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Routes as ReactRouterRoutes } from "react-router-dom";
2+
3+
import { FaroRoutes } from "@grafana/faro-react";
4+
import { getEnv } from "src/utils/environment";
5+
6+
const env = getEnv();
7+
8+
export const Routes = env === "development" ? ReactRouterRoutes : FaroRoutes;

web/src/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Sentry initialization should be imported first!
2-
import "src/utils/setup-sentry";
1+
import "src/utils/setup-faro";
32

43
import React from "react";
54
import { StrictMode } from "react";

web/src/utils/sentry-origin.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

web/src/utils/setup-faro.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {
2+
createRoutesFromChildren,
3+
matchRoutes,
4+
Routes,
5+
useLocation,
6+
useNavigationType,
7+
} from "react-router-dom";
8+
import {
9+
createReactRouterV6Options,
10+
getWebInstrumentations,
11+
initializeFaro,
12+
ReactIntegration,
13+
} from "@grafana/faro-react";
14+
import { TracingInstrumentation } from "@grafana/faro-web-tracing";
15+
16+
import { getEnv } from "./environment";
17+
18+
const env = getEnv();
19+
20+
if (env !== "development") {
21+
initializeFaro({
22+
url: "https://grafana.zak-man.com/faro-proxy/9c90470e84483b225a6a5a0378aa0d97",
23+
app: {
24+
name: "dzcode",
25+
version: window.bundleInfo.version,
26+
environment: env,
27+
},
28+
29+
instrumentations: [
30+
// Mandatory, omits default instrumentations otherwise.
31+
...getWebInstrumentations(),
32+
33+
// Tracing package to get end-to-end visibility for HTTP requests.
34+
new TracingInstrumentation(),
35+
36+
// React integration for React applications.
37+
new ReactIntegration({
38+
router: createReactRouterV6Options({
39+
createRoutesFromChildren,
40+
matchRoutes,
41+
Routes,
42+
useLocation,
43+
useNavigationType,
44+
}),
45+
}),
46+
],
47+
});
48+
}

0 commit comments

Comments
 (0)