diff --git a/integrations/Sentry/browser.js b/integrations/Sentry/browser.js index 3645e02ba1..b091b3edff 100644 --- a/integrations/Sentry/browser.js +++ b/integrations/Sentry/browser.js @@ -1,14 +1,12 @@ +/* eslint-disable object-shorthand */ /* eslint-disable func-names */ /* eslint-disable class-methods-use-this */ /* eslint-disable no-unused-expressions */ import get from "get-value"; import logger from "../../utils/logUtil"; -import { - SentryScriptLoader, - identifierPayloadBuilder, - convertObjectToArray, -} from "./utils"; +import { SentryScriptLoader, convertObjectToArray } from "./utils"; +import { removeUndefinedAndNullValues } from "../utils/commonUtils"; import { getDefinedTraits, isObject } from "../../utils/utils"; class Sentry { @@ -35,7 +33,8 @@ class Sentry { } SentryScriptLoader( "Sentry", - `https://browser.sentry-cdn.com/6.12.0/bundle.min.js` + `https://browser.sentry-cdn.com/6.12.0/bundle.min.js`, + `sha384-S3qfdh3AsT1UN84WIYNuOX9vVOoFg3nB17Jp5/pTFGDBGBt+dtz7MGAV845efkZr` ); const formattedAllowUrls = convertObjectToArray(this.allowUrls); @@ -73,14 +72,14 @@ class Sentry { } if (includePaths.length > 0) { - this.integrations.push( + window.Sentry.integrations.push( new window.Sentry.Integrations.RewriteFrames({ // eslint-disable-next-line object-shorthand iteratee: function (frame) { // eslint-disable-next-line consistent-return - includePaths.forEach((i) => { + includePaths.forEach((path) => { try { - if (frame.filename.match(includePaths[i])) { + if (frame.filename.match(path)) { // eslint-disable-next-line no-param-reassign frame.in_app = true; return frame; @@ -127,20 +126,17 @@ class Sentry { get(rudderElement.message, "traits.ip_address") || get(rudderElement.message, "context.traits.ip_address"); - const userIdentifierPayload = identifierPayloadBuilder( - userId, - email, - name, - ipAddress - ); const finalPayload = { - ...userIdentifierPayload, + id: userId, + email: email, + username: name, + ip_address: ipAddress, ...traits, }; if (this.logger) { window.Sentry.setTag("logger", logger); } - window.Sentry.setUser(finalPayload); + window.Sentry.setUser(removeUndefinedAndNullValues(finalPayload)); } } export default Sentry; diff --git a/integrations/Sentry/utils.js b/integrations/Sentry/utils.js index b43c34372f..796dceaf34 100644 --- a/integrations/Sentry/utils.js +++ b/integrations/Sentry/utils.js @@ -1,36 +1,14 @@ import logger from "../../utils/logUtil"; const convertObjectToArray = (objectInput) => { - const list = []; - objectInput.forEach(function (objectItem) { - const x = objectItem.eventCustomProperties; - list.push(x); - }); - return list; + return objectInput.map((objectItem) => objectItem.eventCustomProperties); }; -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) => { +const SentryScriptLoader = (id, src, integrity) => { logger.debug(`in script loader=== ${id}`); const js = document.createElement("script"); js.src = src; - js.integrity = - "sha384-S3qfdh3AsT1UN84WIYNuOX9vVOoFg3nB17Jp5/pTFGDBGBt+dtz7MGAV845efkZr"; + js.integrity = integrity; js.crossorigin = "anonymous"; js.async = true; js.type = "text/javascript"; @@ -39,32 +17,11 @@ const SentryScriptLoader = (id, src) => { logger.debug("==parent script==", e); logger.debug("==adding script==", js); e.parentNode.insertBefore(js, e); - SentryRewriteFramesLoader( + SentryScriptLoader( "Sentry", - `https://browser.sentry-cdn.com/6.12.0/rewriteframes.min.js` + `https://browser.sentry-cdn.com/6.12.0/rewriteframes.min.js`, + `sha384-WOm9k3kzVt1COFAB/zCXOFx4lDMtJh/2vmEizIwgog7OW0P/dPwl3s8f6MdwrD7q` ); }; -const identifierPayloadBuilder = (userId, email, name, ipAddress) => { - const userIdentifierPayload = {}; - if (userId) { - userIdentifierPayload.id = userId; - } - if (email) { - userIdentifierPayload.email = email; - } - if (name) { - userIdentifierPayload.username = name; - } - if (ipAddress) { - userIdentifierPayload.ip_address = ipAddress; - } - return userIdentifierPayload; -}; - -export { - SentryScriptLoader, - identifierPayloadBuilder, - SentryRewriteFramesLoader, - convertObjectToArray, -}; +export { SentryScriptLoader, convertObjectToArray };