Skip to content

Commit

Permalink
initial commit for rewriteFrames
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Sep 22, 2021
1 parent 8730d57 commit d46e288
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
47 changes: 41 additions & 6 deletions integrations/Sentry/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logger from "../../utils/logUtil";
import {SentryScriptLoader, identifierPayloadBuilder} from "./utils";
import {getDefinedTraits} from "../../utils/utils";
import {getDefinedTraits, isObject} from "../../utils/utils";

class Sentry {
constructor(config) {
Expand All @@ -11,7 +11,7 @@ class Sentry {
this.debugMode = config.debugMode;
this.environment = config.environment;
this.ignoreErrors = config.ignoreErrors;
this.includePaths = config.includePaths;
this.includePathsArray = config.includePaths;
this.logger = config.Logger;
this.allowUrls = config.allowUrls;
this.denyUrls = config.denyUrls;
Expand Down Expand Up @@ -39,21 +39,56 @@ class Sentry {
allowUrls:this.allowUrls,
denyUrls: this.denyUrls,
ignoreErrors: this.ignoreErrors,
includePaths: this.includePaths,
}
integrations: [],
};

let includePaths = [];

if (this.includePathsArray.length > 0) {
includePaths = this.includePathsArray.map(function(path) {
var regex;
try {
regex = new RegExp(path);
} catch (e) {

}
return regex;
});
}

if (includePaths.length > 0) {
config.integrations.push(
new window.Sentry.Integrations.RewriteFrames({
iteratee: function(frame) {
for (var i = 0; i < includePaths.length; i++) {
try {
if (frame.filename.match(includePaths[i])) {
frame.in_app = true;
return frame;
}
} catch (e) {

}
}
frame.in_app = false;
return frame;
}
})
);
}

}

// eslint-disable-next-line class-methods-use-this
isLoaded() {
logger.debug("===in Sentry isLoaded===");
return !!(window.Sentry && window.Sentry.setUser !== Array.prototype.push);
return !!(window.Sentry && isObject(window.Sentry) && window.Sentry.setUser);
}

// eslint-disable-next-line class-methods-use-this
isReady() {
logger.debug("===in Sentry isReady===");
return !!(window.Sentry && window.Sentry.setUser !== Array.prototype.push);
return !!(window.Sentry && isObject(window.Sentry) && window.Sentry.setUser);
}

identify(rudderElement) {
Expand Down
24 changes: 23 additions & 1 deletion integrations/Sentry/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import logger from "../../utils/logUtil";

const SentryRewriteFramesLoader = (id, src) => {
logger.debug(`In rewriteFrame loader === ${id}`);
const js = document.createElement("script");
js.src = src;
js.integrity = "sha384-WOm9k3kzVt1COFAB/zCXOFx4lDMtJh/2vmEizIwgog7OW0P/dPwl3s8f6MdwrD7q";
js.crossorigin = "anonymous"
js.async = true;
js.type = "text/javascript";
js.id = id;
const e = document.getElementsByTagName("script")[0];
logger.debug("==parent script==", e);
logger.debug("==adding script==", js);
e.parentNode.insertBefore(js, e);
}


const SentryScriptLoader = (id, src) => {
logger.debug(`in script loader=== ${id}`);
const js = document.createElement("script");
Expand All @@ -13,8 +29,14 @@ const SentryScriptLoader = (id, src) => {
logger.debug("==parent script==", e);
logger.debug("==adding script==", js);
e.parentNode.insertBefore(js, e);
SentryRewriteFramesLoader(
"Sentry",
`https://browser.sentry-cdn.com/6.12.0/rewriteframes.min.js`
);

};


const identifierPayloadBuilder = (userId, email, name, ip_address) => {
payload = {};
if (userId) {
Expand All @@ -32,4 +54,4 @@ const identifierPayloadBuilder = (userId, email, name, ip_address) => {
return payload;
};

export {SentryScriptLoader, identifierPayloadBuilder};
export {SentryScriptLoader, identifierPayloadBuilder, SentryRewriteFramesLoader};

0 comments on commit d46e288

Please sign in to comment.