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

web-vitals is undefined #620

Closed
tiennguyen1293 opened this issue Jun 19, 2024 · 10 comments
Closed

web-vitals is undefined #620

tiennguyen1293 opened this issue Jun 19, 2024 · 10 comments
Labels
bug Report a bug

Comments

@tiennguyen1293
Copy link

tiennguyen1293 commented Jun 19, 2024

Description

  • web-vitals has been imported but all methods are undefined, please see the image below.

Please help me to investigate

Steps to reproduce

  • trigger initializeFaro will face the issue
import { trace, context } from '@opentelemetry/api'
import {
  ReactIntegration,
  ReactRouterHistory,
  ReactRouterVersion,
  initializeFaro as coreInit,
  getWebInstrumentations,
} from '@grafana/faro-react'
import {
  FaroSessionSpanProcessor,
  FaroTraceExporter,
  TracingInstrumentation,
} from '@grafana/faro-web-tracing'

export const initializeFaro = () => {
  const faro = coreInit({
    url: config.FARO_URL,
    apiKey: config.FARO_API_KEY,
    app: {
      name: packageJSON.name,
      version: packageJSON.version,
    },
    sessionTracking: {
      enabled: true,
      samplingRate: 0.25,
    },
    instrumentations: [
      ...getWebInstrumentations({
        captureConsole: true,
      }),

  
      new TracingInstrumentation({
        instrumentationOptions: {
          propagateTraceHeaderCorsUrls: [], 
        },
      }),
      new ReactIntegration({
        router: {
          version: ReactRouterVersion.V4,
          dependencies: {
            history: history as ReactRouterHistory, 
            Route,
          },
        },
      }),
    ],
  })

   faro?.api.pushLog(['Faro was initialized'])
   faro?.api.initOTEL(trace, context)
  
   return faro
 }

Expected behavior

  • Worked

Actual behavior

image

image

Environment

"@grafana/faro-react": "^1.3.8",
"@grafana/faro-web-tracing": "^1.3.8",
"react": "^18.3.1",

Node@20.13.1

@tiennguyen1293 tiennguyen1293 added the bug Report a bug label Jun 19, 2024
@codecapitano
Copy link
Collaborator

Hi @tiennguyen1293 first time I see this and unfortunately can't reproduce the error.

  • Do you use Faro with a standard react web-app or maybe with some mobile framework?
  • Do you use the CDN version or the NPM package?
  • When/where do you initialize Faro?
  • Since you set to auto update Faro to the most current minor or patch version I assume you are on the most recent Faro version which is 1.7.3 ?

@tiennguyen1293
Copy link
Author

Hi @codecapitano thank for quick response:

  • I'm using react web-app.
  • use NPM package.
  • when init Web-app I will initialize Faro.
  • I tried upgrade to the latest 1.7.3 version but it has the same issue.

@codecapitano
Copy link
Collaborator

Ok thanks.

The issue happens during build right?

If yes, can you wipe node_modules and install and build again (i know not the coolest answer but I want to exclude that kind of issues)

@tiennguyen1293
Copy link
Author

the issue happens during runtime.

I ran rm -rf node_modules yarn.lock and re-install. And then re-started the App, but the issue still happens.

@codecapitano
Copy link
Collaborator

  • Does it happen on every browser?
  • Is there maybe something running which prevents the script to work? Like a content filter?
  • Maybe an issue in regards to content security policy?

@tiennguyen1293
Copy link
Author

it is happening to build runtime to run App on localhost. Maybe it is related to building library or compiling code?

@codecapitano
Copy link
Collaborator

Aaah at build runtime 👍

Maybe it is related to building library or compiling code?

Ok yeah this might be causing the issue.

What is your build tool of choice?

@tiennguyen1293
Copy link
Author

i'm using Webpack version 5

@tiennguyen1293
Copy link
Author

i found the root cause, it is related to webpack config.

I configured

resolve.mainFields: ['browser', 'main', 'module'],

I will close this issue

Thanks for you support

@codecapitano
Copy link
Collaborator

Great thank you for the update. 🙏

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

No branches or pull requests

2 participants