Skip to content

Commit 0206e9f

Browse files
steverydzCopilot
andauthored
chore: Migrate from raven-js to sentry browser (#5370)
* chore: Migrate from raven-js to sentry browser * Update templates/blog/article.html Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update templates/blog/index.html Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: Use correct values for Sentry config --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5f8d298 commit 0206e9f

17 files changed

Lines changed: 217 additions & 176 deletions

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
"test-js-all": "yarn run lint-js && yarn run test-js",
1111
"test-python": "yarn run lint-python && FLASK_DEBUG=0 python3 -m unittest discover tests",
1212
"test-python-job": "SECRET_KEY=insecure_secret_key coverage run --source=. -m unittest discover tests",
13-
"build": "yarn run copy-3rd-party-js && vite build",
14-
"copy-3rd-party-js": "mkdir -p static/js/modules && cp node_modules/raven-js/dist/raven.min.js static/js/modules",
13+
"build": "yarn run vite build",
1514
"serve": "./entrypoint 0.0.0.0:${PORT}",
16-
"start": "concurrently --raw 'yarn run copy-3rd-party-js' 'yarn run watch' 'yarn run serve'",
15+
"start": "concurrently --raw 'yarn run watch' 'yarn run serve'",
1716
"watch": "vite",
1817
"clean": "rm -rf node_modules yarn-error.log css static/js/dist static/js/modules static/css *.log *.sqlite _site/ build/ .jekyll-metadata .bundle cache.tmp",
1918
"percy": "node_modules/.bin/percy snapshot snapshots.yml"
@@ -33,8 +32,8 @@
3332
"@dnd-kit/core": "6.3.1",
3433
"@dnd-kit/sortable": "8.0.0",
3534
"@dnd-kit/utilities": "3.2.2",
35+
"@sentry/browser": "10.12.0",
3636
"@sentry/react": "7.120.2",
37-
"@sentry/tracing": "7.114.0",
3837
"@testing-library/dom": "10.4.0",
3938
"@testing-library/jest-dom": "6.6.3",
4039
"@testing-library/react": "16.2.0",
@@ -67,7 +66,6 @@
6766
"prettier": "3.4.2",
6867
"prop-types": "15.8.1",
6968
"randomstring": "1.3.0",
70-
"raven-js": "3.27.2",
7169
"react": "19.1.0",
7270
"react-dnd": "16.0.1",
7371
"react-dnd-html5-backend": "16.0.1",

static/js/base/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import "./navigation";
22
import "./ga";
33
import "./contactForm";
4+
import "./sentry";

static/js/base/sentry.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as Sentry from "@sentry/browser";
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
allowUrls: ["staging.snapcraft.io/static/js", "snapcraft.io/static/js/"],
7+
denyUrls: [
8+
"staging.snapcraft.io/static/js/modules",
9+
"snapcraft.io/static/js/modules",
10+
],
11+
dsn: window.SENTRY_DSN,
12+
environment: window.ENVIRONMENT,
13+
ignoreErrors: ["AbortError"],
14+
release: window.COMMIT_ID,
15+
});

static/js/global.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ declare interface Window {
2727
SENTRY_DSN: string;
2828
CSRF_TOKEN: string;
2929
API_URL: string;
30+
Sentry: Record<string, unknown>;
31+
COMMIT_ID: string;
32+
ENVIRONMENT: string;
3033
}
3134

3235
declare module "@canonical/cookie-policy";

static/js/publisher/brand-store.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { createRoot } from "react-dom/client";
22
import { QueryClient, QueryClientProvider } from "react-query";
33
import * as Sentry from "@sentry/react";
4-
import { BrowserTracing } from "@sentry/browser";
54
import BrandStoreRoot from "./routes/brand-store-root";
65
import { Provider as JotaiProvider } from "jotai";
76

87
Sentry.init({
98
dsn: window.SENTRY_DSN,
10-
integrations: [new BrowserTracing()],
9+
integrations: [Sentry.browserTracingIntegration()],
1110
tracesSampleRate: 1.0,
1211
});
1312

templates/_base-layout.html

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@
2727
{{ vite_dev_tools() }}
2828
{% endif %}
2929

30-
{% block scripts_modules %}{% endblock %}
31-
<script src="{{ static_url('js/modules/raven.min.js') }}" defer></script>
32-
<script>
33-
window.addEventListener("DOMContentLoaded", function() {
34-
Raven.config('{{ SENTRY_DSN }}', {
35-
whitelistUrls: ['staging.snapcraft.io/static/js', 'snapcraft.io/static/js/'],
36-
ignoreUrls: ['staging.snapcraft.io/static/js/modules', 'snapcraft.io/static/js/modules'],
37-
ignoreErrors: ['AbortError'],
38-
release: '{{ COMMIT_ID }}',
39-
environment: '{{ ENVIRONMENT }}'
40-
}).install();
41-
});
42-
</script>
43-
4430
{{ vite_import('static/js/base/base.ts') }}
4531
{% block scripts_includes %}{% endblock %}
4632
<script src="https://assets.ubuntu.com/v1/703e23c9-lazysizes+noscript+native-loading.5.1.2.min.js" defer></script>
@@ -100,6 +86,12 @@
10086

10187
{% block scripts %}{% endblock %}
10288

89+
<script>
90+
window.COMMIT_ID = "{{ COMMIT_ID }}";
91+
window.ENVIRONMENT = "{{ ENVIRONMENT }}";
92+
window.SENTRY_DSN = "{{ SENTRY_DSN }}";
93+
</script>
94+
10395
<script type="application/ld+json">
10496
{
10597
"@context": "http://schema.org/",

templates/about/publish.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,17 @@ <h3 class="p-heading--5">Trave CI, Circle CI and GitHub Actions are all supporte
198198
{% block scripts %}
199199
<script>
200200
window.addEventListener("DOMContentLoaded", function () {
201-
Raven.context(function () {
201+
try {
202202
snapcraft.about.initFSFLanguageSelect(document.querySelector('.js-fsf-language-select'));
203+
} catch(e) {
204+
Sentry.captureException(e);
205+
}
206+
207+
try {
203208
snapcraft.about.initExpandableArea();
204-
});
209+
} catch(e) {
210+
Sentry.captureException(e);
211+
}
205212
});
206213
</script>
207214
{% endblock %}

templates/blog/article.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,19 @@ <h5>
116116
{% block scripts %}
117117
<script>
118118
window.addEventListener("DOMContentLoaded", function() {
119-
Raven.context(function () {
119+
try {
120120
{% if is_in_series %}
121121
snapcraft.blog.seriesPosts('[data-js="blog-series"]', '#blog-series-item-template');
122122
{% endif %}
123+
} catch(e) {
124+
Sentry.captureException(e);
125+
}
123126

127+
try {
124128
snapcraft.public.blog.newsletter();
125-
});
129+
} catch(e) {
130+
Sentry.captureException(e);
131+
}
126132
});
127133
</script>
128134
{% endblock %}

templates/blog/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,23 @@ <h5 class="p-notification__title">Success</h5>
150150
{% block scripts %}
151151
<script>
152152
window.addEventListener("DOMContentLoaded", function() {
153-
Raven.context(function () {
153+
try {
154154
{% if categories %}
155155
var filter = document.getElementById('filter');
156156
var filterForm = document.querySelector('[data-js="filterForm"]');
157157
filter.addEventListener('change', function(e) {
158158
filterForm.submit();
159159
});
160160
{% endif %}
161+
} catch(e) {
162+
Sentry.captureException(e);
163+
}
161164

165+
try {
162166
snapcraft.public.blog.newsletter();
163-
});
167+
} catch(e) {
168+
Sentry.captureException(e);
169+
}
164170
});
165171
</script>
166172
{% endblock %}

templates/docs/document.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h4 class="p-table-of-contents__header">On this page</h4>
163163
{% block scripts %}
164164
<script>
165165
window.addEventListener("DOMContentLoaded", function() {
166-
Raven.context(function() {
166+
try {
167167
// Based on Vanilla side navigation example
168168
// Should be moved out from the template as part of a given project JS bundle
169169

@@ -326,7 +326,9 @@ <h4 class="p-table-of-contents__header">On this page</h4>
326326
});
327327
});
328328
})();
329-
});
329+
} catch(e) {
330+
Sentry.captureException(e);
331+
}
330332
});
331333
</script>
332334
{% endblock %}

0 commit comments

Comments
 (0)