0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

refactor(console): safely init app insights (#3549)

This commit is contained in:
Gao Sun 2023-03-20 21:05:52 +08:00 committed by GitHub
parent 42bb0a9fab
commit 384df30e04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,22 +10,32 @@ let reactPlugin: Optional<ReactPlugin>;
let appInsights: Optional<ApplicationInsights>;
const initAppInsights = () => {
const connectionString = process.env.APPLICATIONINSIGHTS_CONNECTION_STRING;
// The string needs to be normalized since it may contain '"'
const connectionString = process.env.APPLICATIONINSIGHTS_CONNECTION_STRING?.replace(
/^"?(.*)"?$/g,
'$1'
);
if (!isCloud || !connectionString) {
return;
}
// https://github.com/microsoft/applicationinsights-react-js#readme
reactPlugin = new ReactPlugin();
appInsights = new ApplicationInsights({
config: {
connectionString,
enableAutoRouteTracking: true,
extensions: [reactPlugin],
},
});
appInsights.loadAppInsights();
try {
// https://github.com/microsoft/applicationinsights-react-js#readme
reactPlugin = new ReactPlugin();
appInsights = new ApplicationInsights({
config: {
connectionString,
enableAutoRouteTracking: true,
extensions: [reactPlugin],
},
});
appInsights.loadAppInsights();
} catch (error: unknown) {
console.error('Unable to init ApplicationInsights:');
console.error(error);
}
};
/* eslint-enable @silverhand/fp/no-mutation, @silverhand/fp/no-let */