grafana / faro-web-sdk

The Grafana Faro Web SDK, part of the Grafana Faro project, is a highly configurable web SDK for real user monitoring (RUM) that instruments browser frontend applications to capture observability signals. Frontend telemetry can then be correlated with backend and infrastructure data for full-stack observability.
https://grafana.com/oss/faro/
Apache License 2.0
688 stars 62 forks source link

235 faroroutes support for routerprovider react router v6 #518

Closed codecapitano closed 3 months ago

codecapitano commented 3 months ago

Why

This PR adds support for the React Router V6 which is using the new RouterProvider which supporting the new Data Routers.

Setting up Routes with RouterProvider works differently then before. On result of this is that we can't wrap the React Routes with FaroRoutes anymore. Also wrapping the RouterProvider with FaroRoutes also doesn't work because FaroRoutes are using useLocation internally which is not available outside of the Data Routers.

To instrument the new routers we created the withFaroRouterInstrumentation(router) which subscribe to route changes of the passed router and sends the respective Faro route change events.

withFaroRouterInstrumentation(router) work with all current data routers which are:

Because setting up data routers is differently then other V6 routers, the Faro React setup is different as well:

 new ReactIntegration({
        router: {
          version: ReactRouterVersion.V6_data_router,
          dependencies: {
            matchRoutes,
          },
        },
      }),

Note To test the new router you can use below branch of the Faro demo which uses the data router. To test the data routers mentioned above just open the App.tsx file and replace createBrowserRouter with createHashRouter or createMemoryRouter. 👉🏼 Don't forget to rebuild the demo after you made changes to App.tsx

What

Links

Related issue: https://github.com/grafana/faro-web-sdk/issues/235

Checklist

codecapitano commented 3 months ago

looks good to me- just one comment :)

Good point Elliot, let me double check.