Skip to content

Commit

Permalink
code refactored and ready is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Sep 22, 2021
1 parent eaae184 commit 803f0db
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 69 deletions.
77 changes: 9 additions & 68 deletions integrations/Sentry/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import get from "get-value";
import logger from "../../utils/logUtil";
import { SentryScriptLoader, convertObjectToArray } from "./utils";
import { SentryScriptLoader, sentryInit } from "./utils";
import { removeUndefinedAndNullValues } from "../utils/commonUtils";
import { getDefinedTraits, isObject } from "../../utils/utils";

Expand Down Expand Up @@ -64,77 +64,18 @@ class Sentry {
window.Sentry.setUser &&
window.Sentry.Integrations.RewriteFrames
) {
const formattedAllowUrls = convertObjectToArray(
const sentryConfig = sentryInit(
this.allowUrls,
"allowUrls"
);
const formattedDenyUrls = convertObjectToArray(this.denyUrls, "denyUrls");
const formattedIgnoreErrors = convertObjectToArray(
this.denyUrls,
this.ignoreErrors,
"ignoreErrors"
);
const formattedIncludePaths = convertObjectToArray(
this.includePathsArray,
"includePaths"
this.customVersionProperty,
this.release,
this.dsn,
this.debugMode,
this.environment,
this.serverName
);

const customRelease = this.customVersionProperty
? window[this.customVersionProperty]
: null;

const releaseValue =
customRelease || (this.release ? this.release : null);

const sentryConfig = {
dsn: this.dsn,
debug: this.debugMode,
environment: this.environment || null,
release: releaseValue,
serverName: this.serverName || null,
allowUrls: formattedAllowUrls,
denyUrls: formattedDenyUrls,
ignoreErrors: formattedIgnoreErrors,
};

let includePaths = [];

if (formattedIncludePaths.length > 0) {
includePaths = formattedIncludePaths.map(function (path) {
let regex;
try {
regex = new RegExp(path);
} catch (e) {
// ignored
}
return regex;
});
}

if (includePaths.length > 0) {
sentryConfig.integrations = [];
sentryConfig.integrations.push(
new window.Sentry.Integrations.RewriteFrames({
// eslint-disable-next-line object-shorthand
iteratee: function (frame) {
// eslint-disable-next-line consistent-return
includePaths.forEach((path) => {
try {
if (frame.filename.match(path)) {
// eslint-disable-next-line no-param-reassign
frame.in_app = true;
return frame;
}
} catch (e) {
// ignored
}
});
// eslint-disable-next-line no-param-reassign
frame.in_app = false;
return frame;
},
})
);
}
window.Sentry.init(sentryConfig);
return true;
}
Expand Down
85 changes: 84 additions & 1 deletion integrations/Sentry/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,87 @@ const SentryScriptLoader = (id, src, integrity) => {
e.parentNode.insertBefore(js, e);
};

export { SentryScriptLoader, convertObjectToArray };
const sentryInit = (
allowUrls,
denyUrls,
ignoreErrors,
includePathsArray,
customVersionProperty,
release,
DSN,
debugMode,
environment,
serverName
) => {
const formattedAllowUrls = convertObjectToArray(allowUrls, "allowUrls");
const formattedDenyUrls = convertObjectToArray(denyUrls, "denyUrls");
const formattedIgnoreErrors = convertObjectToArray(
ignoreErrors,
"ignoreErrors"
);
const formattedIncludePaths = convertObjectToArray(
includePathsArray,
"includePaths"
);

const customRelease = customVersionProperty
? window[customVersionProperty]
: null;

const releaseValue = customRelease || release || null;

const sentryConfig = {
dsn: DSN,
debug: debugMode,
environment: environment || null,
release: releaseValue,
serverName: serverName || null,
allowUrls: formattedAllowUrls,
denyUrls: formattedDenyUrls,
ignoreErrors: formattedIgnoreErrors,
};

let includePaths = [];

if (formattedIncludePaths.length > 0) {
// eslint-disable-next-line func-names
includePaths = formattedIncludePaths.map(function (path) {
let regex;
try {
regex = new RegExp(path);
} catch (e) {
// ignored
}
return regex;
});
}

if (includePaths.length > 0) {
sentryConfig.integrations = [];
sentryConfig.integrations.push(
new window.Sentry.Integrations.RewriteFrames({
// eslint-disable-next-line object-shorthand
iteratee: function (frame) {
// eslint-disable-next-line consistent-return
includePaths.forEach((path) => {
try {
if (frame.filename.match(path)) {
// eslint-disable-next-line no-param-reassign
frame.in_app = true;
return frame;
}
} catch (e) {
// ignored
}
});
// eslint-disable-next-line no-param-reassign
frame.in_app = false;
return frame;
},
})
);
}
return sentryConfig;
};

export { SentryScriptLoader, convertObjectToArray, sentryInit };

0 comments on commit 803f0db

Please sign in to comment.