Skip to content

Commit

Permalink
Update sentry metadata (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaskempf57 authored Sep 3, 2024
1 parent d0e62e0 commit e3e2d62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
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

0 comments on commit e3e2d62

Please sign in to comment.