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:
parent
42bb0a9fab
commit
384df30e04
1 changed files with 21 additions and 11 deletions
|
@ -10,22 +10,32 @@ let reactPlugin: Optional<ReactPlugin>;
|
||||||
let appInsights: Optional<ApplicationInsights>;
|
let appInsights: Optional<ApplicationInsights>;
|
||||||
|
|
||||||
const initAppInsights = () => {
|
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) {
|
if (!isCloud || !connectionString) {
|
||||||
return;
|
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 */
|
/* eslint-enable @silverhand/fp/no-mutation, @silverhand/fp/no-let */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue