Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* global Sentry */
  2.  
  3. /* In eigenem Scope um den Rest nicht zu "beladen". */
  4. var VERSION = "5.1.0";
  5.  
  6. /* Füge Script via JS hinzu und wenn erfolgreich führte Funktion aus */
  7. var loadJS = (url, wennFertigFunction, ort) => {
  8.     const scriptTag              = document.createElement("script");
  9.     scriptTag.src                = url;
  10.     scriptTag.onload             = wennFertigFunction;
  11.     scriptTag.onreadystatechange = wennFertigFunction;
  12.  
  13.     ort.appendChild(scriptTag);
  14. };
  15.  
  16. /* Läd Sentry nur für nicht-dev-server */
  17. var getSentryOptions = () => {
  18.     const getCookie = (key = null) => {
  19.         const cookies = document.cookie.split(/[;] */).reduce((prev, curr) => {
  20.             const [name, value] = curr.split('=');
  21.             prev[name]          = value;
  22.             return prev;
  23.         }, {});
  24.  
  25.         if (key) return cookies[key] || null;
  26.         return cookies;
  27.     };
  28.  
  29.     if (getCookie('sentryLaden') !== '1') {
  30.         return {dsn: ''};
  31.     }
  32.  
  33.     return {dsn: 'https://eecc2b20b08440d9a1aa1754e79e9780@s2000-sentry.mpibpc.mpg.de/4'};
  34. };
  35.  
  36. /* Initialisiere Sentry und Konfiguriere standartwerte */
  37. var initSentry = () => {
  38.     if(typeof Sentry !== 'undefined') return;
  39.     if(window.hasOwnProperty('Sentry')) return;
  40.  
  41.     Sentry.init(getSentryOptions());
  42.  
  43.     const userData = {
  44.         id:    localStorage.getItem("systemName") || "unbekannt",
  45.         name:  localStorage.getItem("fullname") || "unbekannt",
  46.         email: localStorage.getItem("email") || "unbekannt",
  47.         rolle: localStorage.getItem("rolle") || "unbekannt",
  48.     };
  49.  
  50.     Sentry.configureScope(scope => {
  51.         scope.setUser(userData);
  52.         scope.setTag("hostname", location.hostname);
  53.         scope.setTag("dbname", localStorage.getItem("dbname") || "unbekannt");
  54.         scope.setTag("rolle", localStorage.getItem("rolle") || "unbekannt");
  55.     });
  56. };
  57.  
  58. var catPos          = location.href.indexOf("/cat/");
  59. var urlStringBisCat = location.href.slice(0, catPos + 4);
  60. var sentryBundle    = `${urlStringBisCat}/lib/modules/sentry-bundle-${VERSION}.min.js`;
  61. loadJS(sentryBundle, initSentry, document.head);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement