Skip to content

Commit ed22b45

Browse files
Revert "feat: Add base config for JS loader with performance/replay (#46447)"
This reverts commit bb7604e. Co-authored-by: AbhiPrasad <[email protected]>
1 parent 1a5b9cc commit ed22b45

File tree

4 files changed

+28
-108
lines changed

4 files changed

+28
-108
lines changed

src/sentry/templates/sentry/js-sdk-loader.js.tmpl

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,11 @@
6767
_newScriptTag.crossOrigin = 'anonymous';
6868

6969
// Once our SDK is loaded
70-
_newScriptTag.addEventListener('load', function () {
70+
_newScriptTag.addEventListener('load', function() {
7171
try {
72-
// Restore onerror/onunhandledrejection handlers - only if not mutated in the meanwhile
73-
if (_window[_onerror] && _window[_onerror].__SENTRY_LOADER__) {
74-
_window[_onerror] = _oldOnerror;
75-
}
76-
if (_window[_onunhandledrejection] && _window[_onunhandledrejection].__SENTRY_LOADER__) {
77-
_window[_onunhandledrejection] = _oldOnunhandledrejection;
78-
}
72+
// Restore onerror/onunhandledrejection handlers
73+
_window[_onerror] = _oldOnerror;
74+
_window[_onunhandledrejection] = _oldOnunhandledrejection;
7975

8076
// Add loader as SDK source
8177
_window.SENTRY_SDK_SOURCE = 'loader';
@@ -84,19 +80,6 @@
8480

8581
var oldInit = SDK.init;
8682

87-
var integrations = [];
88-
if (_config.tracesSampleRate) {
89-
integrations.push(new Sentry.BrowserTracing());
90-
}
91-
92-
if (_config.replaysSessionSampleRate || _config.replaysOnErrorSampleRate) {
93-
integrations.push(new Sentry.Replay());
94-
}
95-
96-
if (integrations.length) {
97-
_config.integrations = integrations;
98-
}
99-
10083
// Configure it using provided DSN and config object
10184
SDK.init = function(options) {
10285
var target = _config;
@@ -117,27 +100,23 @@
117100
_currentScriptTag.parentNode.insertBefore(_newScriptTag, _currentScriptTag);
118101
}
119102

120-
function sdkIsLoaded() {
121-
var __sentry = _window['__SENTRY__'];
122-
// If there is a global __SENTRY__ that means that in any of the callbacks init() was already invoked
123-
return !!(!(typeof __sentry === 'undefined') && __sentry.hub && __sentry.hub.getClient());
124-
}
125-
126103
function sdkLoaded(callbacks, SDK) {
127104
try {
105+
var data = queue.data;
106+
128107
// We have to make sure to call all callbacks first
129108
for (var i = 0; i < callbacks.length; i++) {
130109
if (typeof callbacks[i] === 'function') {
131110
callbacks[i]();
132111
}
133112
}
134113

135-
var data = queue.data;
136-
137-
var initAlreadyCalled = sdkIsLoaded();
138-
139-
// Call init first, if provided
140-
data.sort((a, b) => a.f === 'init' ? -1 : 0);
114+
var initAlreadyCalled = false;
115+
var __sentry = _window['__SENTRY__'];
116+
// If there is a global __SENTRY__ that means that in any of the callbacks init() was already invoked
117+
if (!(typeof __sentry === 'undefined') && __sentry.hub && __sentry.hub.getClient()) {
118+
initAlreadyCalled = true;
119+
}
141120

142121
// We want to replay all calls to Sentry and also make sure that `init` is called if it wasn't already
143122
// We replay all calls to `Sentry.*` now
@@ -197,6 +176,7 @@
197176
}
198177
};
199178

179+
200180
[
201181
'init',
202182
'addBreadcrumb',
@@ -215,15 +195,14 @@
215195
// Store reference to the old `onerror` handler and override it with our own function
216196
// that will just push exceptions to the queue and call through old handler if we found one
217197
var _oldOnerror = _window[_onerror];
218-
_window[_onerror] = function() {
198+
_window[_onerror] = function(message, source, lineno, colno, exception) {
219199
// Use keys as "data type" to save some characters"
220200
queue({
221201
e: [].slice.call(arguments)
222202
});
223203

224204
if (_oldOnerror) _oldOnerror.apply(_window, arguments);
225205
};
226-
_window[_onerror].__SENTRY_LOADER__ = true;
227206

228207
// Do the same store/queue/call operations for `onunhandledrejection` event
229208
var _oldOnunhandledrejection = _window[_onunhandledrejection];
@@ -233,7 +212,6 @@
233212
});
234213
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments);
235214
};
236-
_window[_onunhandledrejection].__SENTRY_LOADER__ = true;
237215

238216
if (!lazy) {
239217
setTimeout(function () {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load sentry_helpers %}(function(b,z,D,f,g,l,E,F,m,n){function p(a){("e"in a||"p"in a||a.f&&-1<a.f.indexOf("capture")||a.f&&-1<a.f.indexOf("showReportDialog"))&&q&&v(t);p.data.push(a)}function v(a){if(!A){A=!0;var h=z.scripts[0],c=z.createElement(D);c.src=F;c.crossOrigin="anonymous";c.addEventListener("load",function(){try{b[f]&&b[f].g&&(b[f]=w);b[g]&&b[g].g&&(b[g]=x);b.m="loader";var d=b[l],u=d.h,k=[];m.C&&k.push(new Sentry.j);(m.B||m.A)&&k.push(new Sentry.l);k.length&&(m.u=k);d.h=function(e){for(var r in e)Object.prototype.hasOwnProperty.call(e,
2-
r)&&(m[r]=e[r]);u(m)};G(a,d)}catch(e){console.error(e)}});h.parentNode.insertBefore(c,h)}}function H(){var a=b.__SENTRY__;return!("undefined"===typeof a||!a.i||!a.i.s())}function G(a,h){try{for(var c=0;c<a.length;c++)if("function"===typeof a[c])a[c]();var d=p.data,u=H();d.sort(function(y){return"init"===y.f?-1:0});var k=!1;for(c=0;c<d.length;c++)if(d[c].f){k=!0;var e=d[c];!1===u&&"init"!==e.f&&h.h();u=!0;h[e.f].apply(h,e.a)}!1===u&&!1===k&&h.h();var r=b[f],B=b[g];for(c=0;c<d.length;c++)"e"in d[c]&&
3-
r?r.apply(b,d[c].e):"p"in d[c]&&B&&B.apply(b,[d[c].p])}catch(y){console.error(y)}}var q=n,C=!1;for(n=0;n<document.scripts.length;n++)if(-1<document.scripts[n].src.indexOf(E)){q&&"no"===document.scripts[n].getAttribute("data-lazy")&&(q=!1);break}var A=!1,t=[];p.data=[];b[l]=b[l]||{};b[l].v=function(a){t.push(a);q&&!C||v(t)};b[l].o=function(){C=!0;q&&setTimeout(function(){v(t)})};"init addBreadcrumb captureMessage captureException captureEvent configureScope withScope showReportDialog".split(" ").forEach(function(a){b[l][a]=
4-
function(){p({f:a,a:arguments})}});var w=b[f];b[f]=function(){p({e:[].slice.call(arguments)});w&&w.apply(b,arguments)};b[f].g=!0;var x=b[g];b[g]=function(a){p({p:"reason"in a?a.reason:"detail"in a&&"reason"in a.detail?a.detail.reason:a});x&&x.apply(b,arguments)};b[g].g=!0;q||setTimeout(function(){v(t)})})(window,document,"script","onerror","onunhandledrejection","Sentry","{{ publicKey|safe }}","{{ jsSdkUrl|safe }}",{{ config|to_json|safe }},{{ isLazy|safe|lower }});
1+
{% load sentry_helpers %}(function(c,w,C,q,r,k,D,E,x,l){function t(a){if(!y){y=!0;var f=w.scripts[0],d=w.createElement(C);d.src=E;d.crossOrigin="anonymous";d.addEventListener("load",function(){try{c[q]=u;c[r]=v;c.SENTRY_SDK_SOURCE="loader";var b=c[k],g=b.init;b.init=function(e){for(var h in e)Object.prototype.hasOwnProperty.call(e,h)&&(x[h]=e[h]);g(x)};F(a,b)}catch(e){console.error(e)}});f.parentNode.insertBefore(d,f)}}function F(a,f){try{for(var d=m.data,b=0;b<a.length;b++)if("function"===typeof a[b])a[b]();
2+
var g=!1,e=c.__SENTRY__;"undefined"!==typeof e&&e.hub&&e.hub.getClient()&&(g=!0);e=!1;for(b=0;b<d.length;b++)if(d[b].f){e=!0;var h=d[b];!1===g&&"init"!==h.f&&f.init();g=!0;f[h.f].apply(f,h.a)}!1===g&&!1===e&&f.init();var z=c[q],A=c[r];for(b=0;b<d.length;b++)"e"in d[b]&&z?z.apply(c,d[b].e):"p"in d[b]&&A&&A.apply(c,[d[b].p])}catch(G){console.error(G)}}var n=l,B=!1;for(l=0;l<document.scripts.length;l++)if(-1<document.scripts[l].src.indexOf(D)){n&&"no"===document.scripts[l].getAttribute("data-lazy")&&
3+
(n=!1);break}var y=!1,p=[],m=function(a){("e"in a||"p"in a||a.f&&-1<a.f.indexOf("capture")||a.f&&-1<a.f.indexOf("showReportDialog"))&&n&&t(p);m.data.push(a)};m.data=[];c[k]=c[k]||{};c[k].onLoad=function(a){p.push(a);n&&!B||t(p)};c[k].forceLoad=function(){B=!0;n&&setTimeout(function(){t(p)})};"init addBreadcrumb captureMessage captureException captureEvent configureScope withScope showReportDialog".split(" ").forEach(function(a){c[k][a]=function(){m({f:a,a:arguments})}});var u=c[q];c[q]=function(a,
4+
f,d,b,g){m({e:[].slice.call(arguments)});u&&u.apply(c,arguments)};var v=c[r];c[r]=function(a){m({p:"reason"in a?a.reason:"detail"in a&&"reason"in a.detail?a.detail.reason:a});v&&v.apply(c,arguments)};n||setTimeout(function(){t(p)})})(window,document,"script","onerror","onunhandledrejection","Sentry","{{ publicKey|safe }}","{{ jsSdkUrl|safe }}",{{ config|to_json|safe }},{{ isLazy|safe|lower }});

src/sentry/web/frontend/js_sdk_loader.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020

2121
class SdkConfig(TypedDict):
2222
dsn: str
23-
tracesSampleRate: Optional[float]
24-
replaysSessionSampleRate: Optional[float]
25-
replaysOnErrorSampleRate: Optional[float]
26-
debug: Optional[bool]
2723

2824

2925
class LoaderContext(TypedDict):
@@ -42,28 +38,24 @@ class JavaScriptSdkLoader(BaseView):
4238
def determine_active_organization(self, request: Request, organization_slug=None) -> None:
4339
pass
4440

45-
def _get_bundle_kind_modifier(
46-
self, key: ProjectKey, sdk_version: str
47-
) -> Tuple[str, bool, bool, bool, bool]:
41+
def _get_bundle_kind_modifier(self, key: ProjectKey, sdk_version: str) -> Tuple[str, bool]:
4842
"""Returns a string that is used to modify the bundle name"""
4943

5044
is_v7_sdk = sdk_version >= Version("7.0.0")
5145

5246
is_lazy = True
5347
bundle_kind_modifier = ""
54-
has_replay = get_dynamic_sdk_loader_option(key, DynamicSdkLoaderOption.HAS_REPLAY)
55-
has_performance = get_dynamic_sdk_loader_option(key, DynamicSdkLoaderOption.HAS_PERFORMANCE)
56-
has_debug = get_dynamic_sdk_loader_option(key, DynamicSdkLoaderOption.HAS_DEBUG)
5748

5849
# The order in which these modifiers are added is important, as the
5950
# bundle name is built up from left to right.
6051
# https://docs.sentry.io/platforms/javascript/install/cdn/
6152

62-
# We depend on fixes in the tracing bundle that are only available in v7
63-
if is_v7_sdk and has_performance:
53+
if get_dynamic_sdk_loader_option(key, DynamicSdkLoaderOption.HAS_PERFORMANCE):
6454
bundle_kind_modifier += ".tracing"
6555
is_lazy = False
6656

57+
has_replay = get_dynamic_sdk_loader_option(key, DynamicSdkLoaderOption.HAS_REPLAY)
58+
6759
# If the project does not have a v7 sdk set, we cannot load the replay bundle.
6860
if is_v7_sdk and has_replay:
6961
bundle_kind_modifier += ".replay"
@@ -77,10 +69,10 @@ def _get_bundle_kind_modifier(
7769
if is_v7_sdk and not has_replay:
7870
bundle_kind_modifier += ".es5"
7971

80-
if has_debug:
72+
if get_dynamic_sdk_loader_option(key, DynamicSdkLoaderOption.HAS_DEBUG):
8173
bundle_kind_modifier += ".debug"
8274

83-
return bundle_kind_modifier, is_lazy, has_performance, has_replay, has_debug
75+
return bundle_kind_modifier, is_lazy
8476

8577
def _get_context(
8678
self, key: Optional[ProjectKey]
@@ -97,13 +89,7 @@ def _get_context(
9789

9890
sdk_version = get_browser_sdk_version(key)
9991

100-
(
101-
bundle_kind_modifier,
102-
is_lazy,
103-
has_performance,
104-
has_replay,
105-
has_debug,
106-
) = self._get_bundle_kind_modifier(key, sdk_version)
92+
bundle_kind_modifier, is_lazy = self._get_bundle_kind_modifier(key, sdk_version)
10793

10894
js_sdk_loader_default_sdk_url_template_slot_count = (
10995
settings.JS_SDK_LOADER_DEFAULT_SDK_URL.count("%s")
@@ -122,21 +108,9 @@ def _get_context(
122108
except TypeError:
123109
sdk_url = "" # It fails if it cannot inject the version in the string
124110

125-
config: SdkConfig = {"dsn": key.dsn_public}
126-
127-
if has_debug:
128-
config["debug"] = True
129-
130-
if has_performance:
131-
config["tracesSampleRate"] = 1
132-
133-
if has_replay:
134-
config["replaysSessionSampleRate"] = 0.1
135-
config["replaysOnErrorSampleRate"] = 1
136-
137111
return (
138112
{
139-
"config": config,
113+
"config": {"dsn": key.dsn_public},
140114
"jsSdkUrl": sdk_url,
141115
"publicKey": key.public_key,
142116
"isLazy": is_lazy,

tests/sentry/web/frontend/test_js_sdk_loader.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from sentry.loader.dynamic_sdk_options import DynamicSdkLoaderOption
1010
from sentry.testutils import TestCase
11-
from sentry.utils import json
1211

1312

1413
class JavaScriptSdkLoaderTest(TestCase):
@@ -114,17 +113,14 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
114113
settings.JS_SDK_LOADER_DEFAULT_SDK_URL = "https://browser.sentry-cdn.com/%s/bundle%s.min.js"
115114
settings.JS_SDK_LOADER_SDK_VERSION = "7.32.0"
116115

117-
dsn = self.projectkey.get_dsn(public=True)
118-
119-
for data, expected_bundle, expected_options in [
116+
for data, expected in [
120117
(
121118
{
122119
"dynamicSdkLoaderOptions": {
123120
DynamicSdkLoaderOption.HAS_PERFORMANCE.value: True,
124121
}
125122
},
126123
b"/7.37.0/bundle.tracing.es5.min.js",
127-
{"dsn": dsn, "tracesSampleRate": 1},
128124
),
129125
(
130126
{
@@ -133,7 +129,6 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
133129
}
134130
},
135131
b"/7.37.0/bundle.es5.debug.min.js",
136-
{"dsn": dsn, "debug": True},
137132
),
138133
(
139134
{
@@ -142,7 +137,6 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
142137
}
143138
},
144139
b"/7.37.0/bundle.replay.min.js",
145-
{"dsn": dsn, "replaysSessionSampleRate": 0.1, "replaysOnErrorSampleRate": 1},
146140
),
147141
(
148142
{
@@ -152,12 +146,6 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
152146
}
153147
},
154148
b"/7.37.0/bundle.tracing.replay.min.js",
155-
{
156-
"dsn": dsn,
157-
"tracesSampleRate": 1,
158-
"replaysSessionSampleRate": 0.1,
159-
"replaysOnErrorSampleRate": 1,
160-
},
161149
),
162150
(
163151
{
@@ -167,12 +155,6 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
167155
}
168156
},
169157
b"/7.37.0/bundle.replay.debug.min.js",
170-
{
171-
"dsn": dsn,
172-
"replaysSessionSampleRate": 0.1,
173-
"replaysOnErrorSampleRate": 1,
174-
"debug": True,
175-
},
176158
),
177159
(
178160
{
@@ -182,7 +164,6 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
182164
}
183165
},
184166
b"/7.37.0/bundle.tracing.es5.debug.min.js",
185-
{"dsn": dsn, "tracesSampleRate": 1, "debug": True},
186167
),
187168
(
188169
{
@@ -193,27 +174,14 @@ def test_bundle_kind_modifiers(self, load_version_from_file, get_selected_browse
193174
}
194175
},
195176
b"/7.37.0/bundle.tracing.replay.debug.min.js",
196-
{
197-
"dsn": dsn,
198-
"tracesSampleRate": 1,
199-
"replaysSessionSampleRate": 0.1,
200-
"replaysOnErrorSampleRate": 1,
201-
"debug": True,
202-
},
203177
),
204178
]:
205179
self.projectkey.data = data
206180
self.projectkey.save()
207181
resp = self.client.get(self.path)
208182
assert resp.status_code == 200
209183
self.assertTemplateUsed(resp, "sentry/js-sdk-loader.js.tmpl")
210-
assert expected_bundle in resp.content
211-
212-
for key in expected_options:
213-
# Convert to e.g. "option_name": 0.1
214-
single_option = {key: expected_options[key]}
215-
assert bytes(json.dumps(single_option)[1:-1], "utf-8") in resp.content
216-
184+
assert expected in resp.content
217185
self.projectkey.data = {}
218186
self.projectkey.save()
219187

0 commit comments

Comments
 (0)