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

feat: Integrate Grafana Faro #3139

Closed
wants to merge 3 commits 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
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ NEXT_PUBLIC_STRIPE_SUB_CANCEL_URL=https://billing.stripe.com/p/login/test_bIY8xy
NEXT_PUBLIC_OPENGRAPH_URL=https://beta.opengraph.opensauced.pizza/v1
SENTRY_DSN=https://3f5bb9023ff0407299dd22a6454558f9@o4504872488927232.ingest.sentry.io/4505082236960768

# Grafana Faro web tracing and frontend observability
# should only be configured to send metric points from beta and prod deployments.
# For testing purposes, use a valid collector URL and set the environment to "beta"
NEXT_PUBLIC_FARO_COLLECTOR_URL=""
NEXT_PUBLIC_FARO_APP_NAME="OpenSauced App"
NEXT_PUBLIC_FARO_APP_ENVIRONMENT=local

# --------------
# For running the API local, use your devices localhost address:
#
Expand Down
37 changes: 37 additions & 0 deletions lib/utils/grafana.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { getWebInstrumentations, initializeFaro, ReactIntegration } from "@grafana/faro-react";
import { TracingInstrumentation } from "@grafana/faro-web-tracing";

// Get the current, runtime version of the App to surface to Faro
import packageJson from "../../package.json";

export const initGrafanaFaro = () => {
return initializeFaro({
url: process.env.NEXT_PUBLIC_FARO_COLLECTOR_URL,

app: {
name: process.env.NEXT_PUBLIC_FARO_APP_NAME,
version: packageJson.version,
environment: process.env.NEXT_PUBLIC_FARO_ENVIRONMENT,
},

instrumentations: [
// load the mandatory web instrumentation
...getWebInstrumentations({
captureConsole: true,
}),

// add tracing instrumentation which should include the React Profiler
new TracingInstrumentation(),

new ReactIntegration({
// In the future, we may choose to integrate with React router instrumentation to
// get deeper metrics on matched routes, navigation types, etc.
// Next/router doesn't seem to be supported which won't give us route metrics.
//
// Reference: https://github.com/grafana/faro-web-sdk/tree/main/packages/react
//
// router: {}
}),
],
});
};
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const interests = [

/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
instrumentationHook: true,
},
productionBrowserSourceMaps: true,
reactStrictMode: true,
images: {
Expand Down
Loading
Loading