remove hardcoded dsn urls

pass them as env vars
This commit is contained in:
pierre
2023-07-20 18:19:44 +02:00
parent 415fe4605c
commit b79f774c48
5 changed files with 40 additions and 34 deletions
+1
View File
@@ -3532,6 +3532,7 @@ dependencies = [
"anyhow",
"bip39",
"dirs 4.0.0",
"dotenv",
"eyre",
"fern",
"fix-path-env",
+1
View File
@@ -46,6 +46,7 @@ yaml-rust = "0.4"
toml = "0.7"
sentry = { version = "0.31.5", features = [ "anyhow" ] }
sentry-log = "0.31.5"
dotenv = "0.15.0"
nym-client-core = { path = "../../../common/client-core" }
nym-api-requests = { path = "../../../nym-api/nym-api-requests" }
@@ -1,3 +1,15 @@
use std::env;
const SENTRY_DSN_RUST: &str = "SENTRY_DSN_RUST";
const SENTRY_DSN_JS: &str = "SENTRY_DSN_JS";
fn main() {
// set these env vars at compile time
if let Ok(dsn) = env::var(SENTRY_DSN_RUST) {
println!("cargo:rustc-env={}={}", SENTRY_DSN_RUST, dsn);
}
if let Ok(dsn) = env::var(SENTRY_DSN_JS) {
println!("cargo:rustc-env={}={}", SENTRY_DSN_JS, dsn);
}
tauri_build::build();
}
+16 -32
View File
@@ -3,6 +3,8 @@
windows_subsystem = "windows"
)]
use dotenv::dotenv;
use std::env;
use std::sync::Arc;
use nym_config::defaults::setup_env;
@@ -20,16 +22,14 @@ mod events;
mod logging;
mod menu;
mod models;
mod monitoring;
mod operations;
mod state;
mod tasks;
mod window;
// TODO DSN shouldn't be hardcoded
const SENTRY_DSN: &str =
"https://68a2c55113ed47aaa30b9899039b0799@o967446.ingest.sentry.io/4505483113594880";
fn main() {
dotenv().ok();
setup_env(None);
println!("Starting up...");
@@ -46,37 +46,21 @@ fn main() {
});
let monitoring = user_data.monitoring.unwrap_or(false);
let _guard = sentry::init((
SENTRY_DSN,
sentry::ClientOptions {
release: sentry::release_name!(),
sample_rate: 1.0, // TODO lower this in prod
traces_sample_rate: 1.0,
..Default::default() // TODO add data scrubbing
// see https://docs.sentry.io/platforms/rust/data-management/sensitive-data/
},
));
sentry::configure_scope(|scope| {
scope.set_user(Some(sentry::User {
id: Some("nym".into()),
..Default::default()
}));
});
let mut _sentry_guard;
if monitoring {
println!("Sentry reporting and monitoring is enabled");
} else {
println!("Monitoring is disabled, dropping sentry guard");
drop(_guard)
}
match monitoring::init() {
Ok(guard) => {
println!("Monitoring and error reporting enabled");
let user_data = UserData::read().unwrap_or_else(|e| {
println!("{}", e);
println!("Fallback to default");
UserData::default()
});
// we must keep the sentry guard in scope during app lifetime
_sentry_guard = guard;
}
Err(e) => {
println!("Unable to init monitoring: {e}");
}
}
}
let context = tauri::generate_context!();
tauri::Builder::default()
+10 -2
View File
@@ -1,17 +1,25 @@
import React from 'react';
import { createRoutesFromChildren, matchRoutes, useLocation, useNavigationType } from 'react-router-dom';
import { invoke } from '@tauri-apps/api';
import * as Sentry from '@sentry/react';
import { CaptureConsole } from '@sentry/integrations';
import { getVersion } from '@tauri-apps/api/app';
const SENTRY_DSN = 'https://625e2658da4945a7a253f3ee04413a31@o967446.ingest.sentry.io/4505306292289536';
const SENTRY_DSN = 'SENTRY_DSN_JS';
async function initSentry() {
console.log('⚠ performance monitoring and error reporting enabled');
console.log('initializing sentry');
const dsn = await invoke<string | undefined>('get_env', { variable: SENTRY_DSN });
if (!dsn) {
console.warn(`unable to initialize sentry, ${SENTRY_DSN} env var not set`);
return;
}
Sentry.init({
dsn: SENTRY_DSN,
dsn,
integrations: [
new Sentry.BrowserTracing({
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled