getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.89k stars 1.56k forks source link

recordDroppedEvent is not a function #5451

Closed gre closed 2 years ago

gre commented 2 years ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/browser

SDK Version

7.6.0

Framework Version

@sentry/electron 3.0.7

Link to Sentry event

https://sentry.io/share/issue/25be96dd489041a4869bc487620e9d73/

Steps to Reproduce

Unfortunately we don't have a clear way to reproduce it, but it seems to happen randomly at the time we span.finish() when making custom transactions and spans for performance.

Random guess, but do you think it could happen if we create multiple Transaction in parallel?

Expected Result

no crash should happen.

Actual Result

some error are getting thrown on some .finish() cases.

Lms24 commented 2 years ago

Hi @gre and thanks for writing in!

It seems to me, you're using v3 of the electron SDK but v7 of the browser JS SDK. This isn't supposed to work as far as I can tell. For instance, recordDroppedEvent was introduced with v7 which is why I think you're getting conflicts here. Did you follow the Electron SDK installation instructions? Alternatively, you could try using the beta version of v4 of our Electron SDK which updates to v7 of the JS SDK.

Hope this helps!

gre commented 2 years ago

Hi @Lms24 and thanks for answering. Indeed our application depends on

dependencies:
@sentry/electron 3.0.7
@sentry/node 7.7.0
@sentry/tracing 7.7.0

we depends both on node and electron because we spawn a node process from our electron so we thought it was relevant to have "node" for it, as it's a regular node process (not an electron instance). but then maybe we need to figure out how to stick with the same "version" of JS SDK? is there a way to see the JS SDK under the hood? i'm trying to see why this happens because we still have different bundles and one bundle is supposed to strictly uses the relevant lib (e.g. electron bundle uses @sentry/electon and don't import @sentry/node) but i imagine something bad is happening in the library deduplication.

AbhiPrasad commented 2 years ago

@gre The versions being used are 6.19.2. You can see them here: https://github.com/getsentry/sentry-electron/blob/1daad98a0b158baeadb8a9a28fdf61f8cbf2a1d0/package.json#L60-L64

So you'll need @sentry/electron@3.0.7 and JS SDKs @ 6.19.2.

gre commented 2 years ago

@AbhiPrasad that makes a lot of sense! thanks for your support. I think we can close this ticket now 👍

BloxsmithDevelopment commented 2 years ago

I am also having this issue but for Next.JS. I think the same thing needs to be done with @sentry/nextjs that was done above for @sentry/electron.

I noticed however that this error only occurs when I implement Segment. Without segment it works final and does not produce this error.

My config: @sentry/nextjs: 7.8.0 @sentry/tracing: 7.8.0 @sentry/fullstory: 1.1.8 @segment/analytics-next: 1.41.1

Sentry issue: https://sentry.io/share/issue/176318dc0b9c4ff2b1312a23ff617675/

AbhiPrasad commented 2 years ago

To debug this, let's try checking for what versions exist of the sentry sdk. Mind running yarn why @sentry/hub and yarn why @sentry/core? If you're using npm, npm ls also works!

BloxsmithDevelopment commented 2 years ago

Everything is freshly installed since I started this implementation just the other day.

@sentry/hub:

Screen Shot 2022-07-29 at 2 30 49 PM

@sentry/core:

Screen Shot 2022-07-29 at 2 31 14 PM
AbhiPrasad commented 2 years ago

@BloxsmithDevelopment could you check what the SDK version is on the event? Perhaps the events are from a stale version that never got updated. It'll be at the bottom of your issue details page, and look something like so:

image
BloxsmithDevelopment commented 2 years ago

That could definitely be the issue...

Screen Shot 2022-07-29 at 2 41 06 PM
AbhiPrasad commented 2 years ago

It's probably than due to some folks who never refreshed the page, so were stuck on an old release of the app. I wouldn't worry too much about it in that case - but please reach out again if it continues to occur!

BloxsmithDevelopment commented 2 years ago

I think it could an issue with the @sentry/fullstory package as it's @sentry/browser dep is "@sentry/browser": ">=4.0.0".

It definitely is still a recurring issue. I discovered it when testing.

Just tested it again and it is still occuring.

AbhiPrasad commented 2 years ago

@sentry/fullstory sets a peer dependency, so it should be just relying on the versions from @sentry/nextjs, as per https://docs.npmjs.com/cli/v8/configuring-npm/package-json#peerdependencies. We can validate this by looking at the screenshot you posted above, the @sentry/browser dep seems to be fine.

Unfortunately, as this is user config on what versions they decide to install, we can't do much on our end to assist here. If you want to enforce this, I would recommend writing an automated test similar to what @gre did here to enforce that the versions are all lined up: https://github.com/LedgerHQ/ledger-live/pull/757/files#diff-21070a589565b91cfc0a453fd19fb4c820a965e655636494b6b6fe0628f57a86

BloxsmithDevelopment commented 2 years ago

It could also be the Vercel runtime environment. It is odd that the issue is never thrown in local development, even when running a build. It only occurs in a Vercel deployment.

I will continue to look into it. Thank you for your help!

BloxsmithDevelopment commented 2 years ago

I was able to fix my issue by downgrading to @sentry/nextjs: 6.19.2 and @sentry/tracing: 6.19.2 just like @gre did. There must be some issue with @sentry 7+ for next.js.

Thank you again!

breiko83 commented 1 year ago

Hello, I know this issue has been closed but I'm having the same on @sentry/nextjs 7.22.0. Any suggestions?

Unhandled Runtime Error
TypeError: client.recordDroppedEvent is not a function

Call Stack
IdleTransaction.finish
node_modules/@sentry/tracing/esm/transaction.js (144:0)
IdleTransaction.finish
node_modules/@sentry/tracing/esm/idletransaction.js (153:0)
eval
node_modules/@sentry/tracing/esm/idletransaction.js (211:0)
sentryWrapped
node_modules/@sentry/browser/esm/helpers.js (90:0)
breiko83 commented 1 year ago

Just a quick update. I temporarily removed tracesSampleRate: 1.0 from sentry config file and the error disappeared. I understand this will probably disable performance tracking but I can live without it. Just in case someone else have the same problem.

Lms24 commented 1 year ago

Hi @breiko83, can you double-check if all your @sentry/* packages in your node_modules are updated to the same version (7.22.0)?

The only thing I can think of here is a version mismatch, as we made a change to this method in #6289 recently. However, I don't entirely understand how adding an optional parameter would cause such an error.

jzolo22 commented 1 year ago

FWIW I was seeing the same error using @sentry/serverless v7.16.0. Downgraded to 6.19.7 per suggestions in the thread and no longer seeing the issue

yazonnile commented 1 year ago

Hey, guys. Same issue on my end. On dev server only.

"@sentry/react": "^7.16.0",
"@sentry/tracing": "^7.16.0",
Sentry.init({
    dsn: import.meta.env.VITE_SENTRY_DSN,
    integrations: [new BrowserTracing()],
    tracesSampleRate: 1.0,
    enabled: import.meta.env.PROD,
    release: import.meta.env.SENTRY_RELEASE,
});

File node_modules/@sentry/tracing/esm/transaction.js Line ~ 129

if (client) {
  client.recordDroppedEvent('sample_rate', 'transaction');
}

I see two different results on dev server and on local server. Local server doesn't have this issue. Dev server does have.

So what's the difference. I've added console.log(this._hub.getClient().__proto__.__proto__); before recordDroppedEvent call. To see instance which has to have this recordDroppedEvent method.

This is the list

captureEvent
captureException
captureMessage
captureSession
close
flush
getDsn
getIntegration
getIntegrationById - local only
getOptions
getTransport
recordDroppedEvent - local only <<<<<<<----------
sendEvent - local only
sendSession - local only
setupIntegrations
__init - local only
__init2 - local only
__init3 - local only
__init4 - local only
_applyClientOptions
_applyIntegrationsMetadata
_captureEvent
_clearOutcomes - local only
_getBackend - dev server only
_isClientDoneProcessing
_isEnabled
_normalizeEvent
_prepareEvent
_process
_processEvent
_sendEnvelope - local only
_sendEvent - dev server only
_sendSession - dev server only
_updateSessionFromEvent
constructor

How this can be fixed? Or at least catched properly :) Thx for help

yazonnile commented 1 year ago

@gre ^^^

Lms24 commented 1 year ago

@yazonnile hmm any chance that this might be a dependency caching problem? What's important to understand about our SDK packages is that they require additional @sentry/ dependencies, such as @sentry/core or @sentry/utils which are downloaded when you install for example @sentry/react.

My advice would be to 1. clear all build/dependency caches and 2. ensure that your yarn/npm lock file doesn't contain any @sentry/* dependency with a different version.

pedrocarnevale commented 1 year ago

Hello! I'm having the same problem using @sentry/browser: 7.47.0 and @sentry/nextjs: 7.47.0. After reading the comments here, I downgraded both to v6.19.2, and the "recordDroppedEvent is not a function" error disappeared. But, I upgraded back to v7.47.0 because I would lose some functionalities in v6.19.2 (eg. session replay is not available for v6).

The solution that fit best for me was to delete the tracesSampleRate in Sentry.init in sentry.client.config.js.

AbhiPrasad commented 1 year ago

@pedrocarnevale - if you remove tracesSampleRate you lose access to Sentry performance monitoring.

You should only need the @sentry/nextjs sentry package, you don't need to install anything else. Once you did that, could you try running npm why @sentry/core and npm why @sentry/nextjs to see if the versions mismatch?

All @sentry/X versions need to be the same!

pedrocarnevale commented 1 year ago

@AbhiPrasad I removed @sentry/browser and executed npm why @sentry/core and npm why @sentry/nextjs, and all @sentry/X versions are the same (7.47.0). The issue still only disappears without tracesSampleRate in sentry.client.config.js

AbhiPrasad commented 1 year ago

@pedrocarnevale are you able to provide a small reproduction? Are you using a custom client/transport? This would help because I'm not sure why replay works but performance monitoring doesn't (they both call recordDroppedEvent under the hood).

LeonardoMessias98 commented 11 months ago

Same problem here guys, I never had used Sentry before and I was trying to integrate with NextJs. I tried to remove tracesSampleRate but my Sentry stopped to register the logs, so I downgrade my Sentry libs versions to 6.19.7 and the error disappear. But unfortunately some of my Sentry requests is getting error 403 and I dont have any idea how to solve it.

AbhiPrasad commented 11 months ago

Hey @LeonardoMessias98 - a lot has changed since April re: the SDKs. Could you open a new GitHub issue and fill out the issue template? This will help us debug. Thanks!