Skip to content

Commit

Permalink
Observability/faro (#47)
Browse files Browse the repository at this point in the history
* legger på grafana faro for web vitals
* fjerner browser env url'er som kun skal trenges serverside
* legger til codeowners
  • Loading branch information
kmriise authored Oct 30, 2023
1 parent bc42bcc commit 2798bb1
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ DP_RAPPORTERING_URL="https://dp-rapportering.intern.dev.nav.no"
IS_LOCALHOST="true"
DP_RAPPORTERING_TOKEN=""
NAIS_CLUSTER_NAME="dev-gcp"
USE_MSW="true"
USE_MSW="true"
FARO_URL="http://localhost:12347/collect"
2 changes: 2 additions & 0 deletions .nais/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
value: {{dekorator.env}}
- name: COMMIT
value: {{commit}}
- name: FARO_URL
value: {{faro_url}}
accessPolicy:
outbound:
external:
Expand Down
1 change: 1 addition & 0 deletions .nais/vars-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ingress: "https://dagpenger.intern.dev.nav.no/rapportering"
base_path: "/rapportering"
idporten:
level: idporten-loa-high
faro_url: "https://telemetry.ekstern.dev.nav.no/collect"
1 change: 1 addition & 0 deletions .nais/vars-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ingress: "https://dagpenger.nav.no/rapportering"
base_path: "/rapportering"
idporten:
level: Level4
faro_url: "https://telemetry.nav.no/collect"
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These owners will be the default owners for everything in
# the repo.
* @navikt/teamdagpenger
4 changes: 3 additions & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { ISanityTexts } from "./sanity/sanity.types";
import { getEnv } from "./utils/env.utils";

import indexStyle from "~/index.css";
import { initInstrumentation } from "~/utils/faro";

export const sanityClient = createClient(sanityConfig);

Expand Down Expand Up @@ -87,13 +88,14 @@ export async function loader() {
sanityTexts,
env: {
BASE_PATH: process.env.BASE_PATH,
DP_RAPPORTERING_URL: process.env.DP_RAPPORTERING_URL,
IS_LOCALHOST: process.env.IS_LOCALHOST,
FARO_URL: process.env.FARO_URL,
},
fragments,
});
}

initInstrumentation();
export default function App() {
const { env, fragments } = useLoaderData<typeof loader>();
return (
Expand Down
1 change: 1 addition & 0 deletions app/utils/env.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IEnv {
USE_MSW: string;
NAIS_APP_IMAGE: string;
COMMIT: string;
FARO_URL: string;
}

export function getEnv(value: keyof IEnv) {
Expand Down
26 changes: 26 additions & 0 deletions app/utils/faro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { type Faro, getWebInstrumentations, initializeFaro } from "@grafana/faro-web-sdk";
import { getEnv } from "~/utils/env.utils";
let faro: Faro | null = null;

export function initInstrumentation(): void {
if (typeof window === "undefined" || faro !== null) return;

getFaro();
}

export function getFaro(): Faro | null {
if (faro != null) return faro;
faro = initializeFaro({
url: getEnv("FARO_URL"), // required, see below
app: {
name: "dp-rapportering-frontend", // required
version: "0.1", // optional; useful in Grafana to get diff between versions
},
instrumentations: [
...getWebInstrumentations({
captureConsole: true,
}),
],
});
return faro;
}
191 changes: 185 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"pre-commit": "lint-staged && npm run typecheck"
},
"dependencies": {
"@grafana/faro-web-sdk": "^1.2.3",
"@navikt/aksel-icons": "^5.7.6",
"@navikt/dp-auth": "^0.3.15",
"@navikt/ds-css": "^5.7.6",
Expand Down

0 comments on commit 2798bb1

Please sign in to comment.