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

Open
wants to merge 3 commits into
base: beta
Choose a base branch
from
Open

feat: Integrate Grafana Faro #3139

wants to merge 3 commits into from

Conversation

jpmcb
Copy link
Member

@jpmcb jpmcb commented Apr 5, 2024

Description

Adds the react integrations and Faro error boundary around the app.
Initializes the default tracing/web integrations for Faro to get us some internal metrics and tracing.

Related Tickets & Documents

N/a - related to ongoing observability and performance work

Mobile & Desktop Screenshots/Recordings

Here's a snapshot after running this locally and getting some of those metrics into our Grafana:

Screenshot 2024-04-05 at 9 53 57 AM

Steps to QA

  1. Run app locally
  2. Modify the environment variables to use the collector and set the env to "beta" to bypass check

Tier (staff will fill in)

  • Tier 1
  • Tier 2
  • Tier 3
  • Tier 4

[optional] Are there any post-deployment tasks we need to perform?

Need to update Netlify env vars to use these

[optional] What gif best describes this PR or how it makes you feel?

@jpmcb jpmcb requested a review from a team April 5, 2024 16:22
Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for design-insights ready!

Name Link
🔨 Latest commit 15a0567
🔍 Latest deploy log https://app.netlify.com/sites/design-insights/deploys/66106cb8717d3500088879da
😎 Deploy Preview https://deploy-preview-3139--design-insights.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for oss-insights ready!

Name Link
🔨 Latest commit 15a0567
🔍 Latest deploy log https://app.netlify.com/sites/oss-insights/deploys/66106cb8f9734600085726c4
😎 Deploy Preview https://deploy-preview-3139--oss-insights.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Adds the react integrations and Faro error boundary around the app
and initializes the default tracing/web integrations

Signed-off-by: John McBride <[email protected]>
pages/_app.tsx Outdated
Comment on lines 67 to 72
useEffect(() => {
if (process.env.NEXT_PUBLIC_FARO_COLLECTOR_URL && process.env.NEXT_PUBLIC_FARO_APP_ENVIRONMENT != "local") {
initGrafanaFaro();
}
}, []);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure this is doing what I expect it to do: Faro needs to initialize on the client (not the server) so I figured that a userEffect would get the app to

But it only seems to capture traces/profiles when the App first loads on the /feed and I see this log go through:

Faro
 Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property

which makes me think that maybe there's a different way to instantiate it - Investigating.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up going with a useRef which now doesn't seem to cause Faro to be re-initilized

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do the Faro docs recommend for a React app?

pages/_app.tsx Outdated
@@ -151,13 +165,15 @@ function MyApp({ Component, pageProps }: ComponentWithPageLayout) {
<SessionContextProvider supabaseClient={supabaseClient} initialSession={pageProps.initialSession}>
<PostHogProvider client={posthog}>
<TipProvider>
{Component.PageLayout ? (
<Component.PageLayout>
<FaroErrorBoundary>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right place for the error boundary ... their React docs make it seem like this should wrap a rendered <App /> and I'm not seeing errors flow through when testing.

Comment on lines 25 to 31
// In the future, we may choose to integrate with the 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: {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not getting any additional routes besides feed/ in the traces and I think it's because it's due to there note being a router config here (and not really seeing a way for it to support next/router, only React router)

@jpmcb
Copy link
Member Author

jpmcb commented Apr 5, 2024

After experimenting abit with this, we can definitely get this in and start getting some good latency data. But there are some missing integrations in the library with NextJS that i think make it abit half baked. We can draft this for now and I can watch to see when they land some Next integrations.

@jpmcb
Copy link
Member Author

jpmcb commented Apr 5, 2024

Pushing logs and errors through is working 👍🏼 tested it out with a dummy throw new Error(...)

Screenshot 2024-04-05 at 3 31 03 PM

I say let's get this in and we can keep an eye on their NextJS instrumentation coming through

@jpmcb jpmcb closed this Apr 5, 2024
@jpmcb jpmcb reopened this Apr 5, 2024
Comment on lines +67 to +77
const faroRef = useRef<null | Faro>(null);

useEffect(() => {
if (
process.env.NEXT_PUBLIC_FARO_COLLECTOR_URL &&
process.env.NEXT_PUBLIC_FARO_APP_ENVIRONMENT != "local" &&
!faroRef.current
) {
faroRef.current = initGrafanaFaro();
}
}, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useRef seems unnecessary. If all you're trying to do is initialize this for the client-side only, this should suffice.

Suggested change
const faroRef = useRef<null | Faro>(null);
useEffect(() => {
if (
process.env.NEXT_PUBLIC_FARO_COLLECTOR_URL &&
process.env.NEXT_PUBLIC_FARO_APP_ENVIRONMENT != "local" &&
!faroRef.current
) {
faroRef.current = initGrafanaFaro();
}
}, []);
useEffect(() => {
if (
process.env.NEXT_PUBLIC_FARO_COLLECTOR_URL &&
process.env.NEXT_PUBLIC_FARO_APP_ENVIRONMENT != "local"
) {
initGrafanaFaro();
}
}, []);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I tried initially but would see this pop up in:

Faro
 Faro is already registered. Either add instrumentations, transports etc. to the global faro instance or use the "isolate" property

But that must be due to a re-render that happens? Either way, seems to be fine since the points still get sent to the collector endpoint ok:

Screenshot 2024-04-05 at 3 52 47 PM

@erkattak
Copy link

erkattak commented May 7, 2024

I'm curious - is the entirety of your app client-side only, or are you doing server-side rendering of components where you're using faro?

@jpmcb
Copy link
Member Author

jpmcb commented May 8, 2024

is the entirety of your app client-side only, or are you doing server-side rendering of components where you're using faro?

We do have server side rendering. Unfortunately, Faro is not well supported for Next JS yet so we're uncertain the future of this integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants