Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Add Sentry to javascript browser code (#266)
Browse files Browse the repository at this point in the history
* Add Sentry to javascript browser code

* Add runtime tag to be able to filter in Sentry GUI

* Add runtime tag to elixir sentry

* Add environment tag on sentry js

* Add sentry env vars to runtime
  • Loading branch information
klaus993 authored Sep 26, 2023
1 parent 57dce98 commit 0ae7183
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ansible/playbooks/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
enable_gateway_data: "{{ lookup('ansible.builtin.env', 'ENABLE_GATEWAY_DATA') }}"
newrelic_key: "{{ lookup('ansible.builtin.env', 'NEWRELIC_KEY') }}"
newrelic_app_name: "{{ lookup('ansible.builtin.env', 'NEWRELIC_APP_NAME') }}"
sentry_env: "{{ lookup('ansible.builtin.env', 'SENTRY_ENV') }}"
sentry_dsn: "{{ lookup('ansible.builtin.env', 'SENTRY_DSN') }}"
enable_listener: "true"
enable_updater: "true"
enable_fetcher: "true"
Expand Down
2 changes: 2 additions & 0 deletions ansible/playbooks/templates/.env.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ENABLE_LISTENER={{ enable_listener }}
ENABLE_GATEWAY_DATA={{ enable_gateway_data }}
NEWRELIC_KEY={{ newrelic_key }}
NEWRELIC_APP_NAME={{ newrelic_app_name }}
SENTRY_DSN={{ sentry_dsn }}
SENTRY_ENV={{ sentry_env }}
ENABLE_FETCHER={{ enable_fetcher }}
ENABLE_LISTENER={{ enable_listener }}
ENABLE_UPDATER={{ enable_updater }}
25 changes: 25 additions & 0 deletions assets/js/sentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as Sentry from "@sentry/browser";

Sentry.init({
dsn: process.env.SENTRY_DSN,

environment: process.env.SENTRY_ENV,

integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,

// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ["localhost", /^https:\/\/(.*)madaraexplorer\.com/],

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});

Sentry.setTag("runtime", "javascript");
Sentry.setTag("environment", process.env.SENTRY_ENV);
145 changes: 145 additions & 0 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"esbuild-plugin-wasm": "1.0.0"
},
"dependencies": {
"@sentry/browser": "^7.71.0",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_view": "file:../deps/phoenix_live_view",
Expand Down
3 changes: 2 additions & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ config :sentry,
enable_source_code_context: true,
root_source_code_path: File.cwd!(),
tags: %{
env: System.get_env("SENTRY_ENV")
env: System.get_env("SENTRY_ENV"),
runtime: "elixir"
},
included_environments: [
if(System.get_env("SENTRY_ENV") == "production", do: :production, else: :testing)
Expand Down

0 comments on commit 0ae7183

Please sign in to comment.