ghl-sentry
Version:
89 lines (88 loc) • 3.37 kB
JavaScript
import { ALLOWED_ENV, SENTRY_LS_KEY, getWhitelabellingConfig, logDebuggingInfo, } from "./common";
import { ORG_KEY, SPM_TS_DSN } from "./constants";
import { browserProfilingIntegration, browserTracingIntegration, init, metrics, moduleMetadataIntegration, } from "@sentry/vue";
import { filterEvents } from "./filters";
import { routeErrorsToFederatedDSN } from "./transporter";
import { sentryVitePlugin } from "@sentry/vite-plugin";
import { sentryWebpackPlugin } from "@sentry/webpack-plugin";
// end of imports
export const initializeSentry = (
// below type is how sentry has declared its init function internally
options, additionalOptions) => {
if (additionalOptions.debug) {
localStorage.setItem(SENTRY_LS_KEY, "true");
}
const allowedEnvs = additionalOptions?.ALLOWED_ENV || ALLOWED_ENV;
try {
if (allowedEnvs.includes(options.environment)) {
init({
dsn: SPM_TS_DSN,
environment: options.environment,
integrations: [
metrics.metricsAggregatorIntegration(),
browserTracingIntegration({
router: additionalOptions.router,
enableInp: true,
shouldCreateSpanForRequest: (url) => {
return (url.includes("leadconnectorhq.com") ||
url.includes("msgsndr.com"));
},
}),
browserProfilingIntegration(),
moduleMetadataIntegration(),
],
transport: routeErrorsToFederatedDSN,
beforeSend: filterEvents,
sampleRate: 1, // samples are picked randomly
tracesSampleRate: 0.1, // picked randomly, starting with bare minimum
logErrors: true,
trackComponents: true,
...getWhitelabellingConfig(options.environment),
...options,
});
logDebuggingInfo(`Error Tracking enabled in ${options.environment} mode`);
}
else {
logDebuggingInfo(`Error Tracking disabled in ${options.environment} mode`);
}
}
catch (e) {
logDebuggingInfo("Error Tracking initialized failed");
}
};
export const ghlSentryWebpackPlugin = (host = false, project, dsn, module) => {
if (host) {
return sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: ORG_KEY,
project: project || "spm-ts",
});
}
else if (project?.length && dsn?.length && module?.length) {
return sentryWebpackPlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: ORG_KEY,
project,
moduleMetadata: ({ release }) => ({
dsn,
module,
release,
}),
});
}
else {
return new Error("Please fix the Sentry Webpack Plugin config");
}
};
export const ghlSentryVitePlugin = (project) => {
if (project?.length) {
return sentryVitePlugin({
org: "gohighlevel",
project,
authToken: process.env.SENTRY_AUTH_TOKEN,
});
}
else {
return new Error("Please fix the Sentry Vite Plugin config");
}
};