getsentry / sentry-javascript

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

Uncaught TypeError: t.spanContext is not a function in CDN import #14009

Open rodolfoBee opened 6 days ago

rodolfoBee commented 6 days ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

8.34.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

User provided code example but i was unable to reproduce with it on my own setup. There is a public server and the steps to reproduce are available on this internal ticket (contains a login and cant be shared publicly)

Expected Result

No errors from the SDK.

Actual Result

Uncaught TypeError: t.spanContext is not a function in the console. By inspecting the code, it is coming from this line: https://github.com/getsentry/sentry-javascript/blob/develop/packages/core/src/utils/spanUtils.ts#L175

Image

mydea commented 5 days ago

Hmm, i am not quite sure why, but it seems that for whatever reason, on this page Array.from(set) is not behaving as expected. I would guess that something somewhere is incorrectly monkey patching something...

Normally, this code should work:

const set = new Set();
set.add('aa');
set.add('bb');

const array = Array.from(set);
// --> ['aa', 'bb']

However, if I rund this code on the linked site, the output is:

// --> [Set(2)]

So Array.from() is not correctly identifiying the set as iterable. The only reason I can think of for this is some polyfill or monkey patch that is not quite correct. The behavior we rely on is correct, though (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) so that has to be some problem on the site specifically, I feel...