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

Update sentry metadata #498

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- always show authorization_request_url if present (even on open API) [#481](https://github.com/datagouv/udata-front/pull/481)
- Show organization type [#472](https://github.com/datagouv/udata-front/pull/472)
- show permalink for community resources [#486](https://github.com/datagouv/udata-front/pull/486)
- update sentry configuration [#498](https://github.com/datagouv/udata-front/pull/498)

## 5.1.2 (2024-08-01)

Expand Down
8 changes: 7 additions & 1 deletion udata_front/theme/gouvfr/assets/js/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,25 @@ const sentryEl = document.querySelector("meta[name=sentry]");
type SentryConfiguration = {
dsn: string | undefined;
release: string | undefined;
tags: Record<string, Primitive>
tags: Record<string, Primitive>;
environment: string;
sampleRate: number;
}

export const sentry: SentryConfiguration = {
dsn: undefined,
release: undefined,
tags: {},
environment: "",
sampleRate: 0,
};

if (sentryEl instanceof HTMLElement) {
sentry.dsn = sentryEl.getAttribute("content") || undefined;
sentry.release = sentryEl.dataset.release || undefined;
sentry.tags = JSON.parse(decodeURIComponent(sentryEl.dataset.tags || "{}"));
sentry.environment = sentryEl.dataset.environment || "";
sentry.sampleRate = parseFloat(sentryEl.dataset.sampleRate ?? "0");
}

/**
Expand Down
2 changes: 2 additions & 0 deletions udata_front/theme/gouvfr/assets/js/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function InitSentry(app: App) {
Sentry.init({
app,
dsn: sentry.dsn,
environment: sentry.environment,
integrations: [new Integrations.BrowserTracing()],
sampleRate: sentry.sampleRate,
release: sentry.release,
ignoreErrors: [
'Auth required',
Expand Down
8 changes: 5 additions & 3 deletions udata_front/theme/gouvfr/templates/macros/metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@
<meta name="terms-url" content="{{ url_for('gouvfr.show_page', slug='legal/cgu') }}" />
{{ i18n_alternate_links() }}
{% if config.SENTRY_PUBLIC_DSN %}
<meta name="sentry" content="{{config.SENTRY_PUBLIC_DSN}}"
data-release="{{config.SENTRY_RELEASE}}"
data-tags="{{config.SENTRY_TAGS|default({})|tojson|urlencode}}"
<meta name="sentry" content="{{ config.SENTRY_PUBLIC_DSN }}"
data-release="{{ _('udata-front@{version}').format(version=package_version('udata-front')) }}"
data-tags="{{ config.SENTRY_TAGS|default({})|tojson|urlencode }}"
data-environment="{{ config.SITE_ID }}"
data-sample-rate="{{ config.SENTRY_SAMPLE_RATE }}"
/>
{% endif %}
{% if config.DATA_SEARCH_FEEDBACK_FORM_URL %}
Expand Down