Add second App Insights instance (#609)

This commit is contained in:
Steve Faulkner
2021-04-05 18:03:17 -05:00
committed by GitHub
parent 250faa5206
commit ba3f4829fa
7 changed files with 200 additions and 93 deletions

View File

@@ -3,7 +3,7 @@ import { configContext } from "../../ConfigContext";
import { MessageTypes } from "../../Contracts/ExplorerContracts";
import { SelfServeMessageTypes } from "../../Contracts/SelfServeContracts";
import { userContext } from "../../UserContext";
import { appInsights } from "../appInsights";
import { startTrackEvent, stopTrackEvent, trackEvent } from "../appInsights";
import { Action, ActionModifiers } from "./TelemetryConstants";
// Right now, the ExplorerContracts has MessageTypes as a numeric enum (TelemetryInfo = 0) while the SelfServeContracts
@@ -27,7 +27,7 @@ export function trace(
},
});
appInsights.trackEvent({ name: Action[action] }, decorateData(data, actionModifier));
trackEvent({ name: Action[action] }, decorateData(data, actionModifier));
}
export function traceStart(
@@ -46,7 +46,7 @@ export function traceStart(
},
});
appInsights.startTrackEvent(Action[action]);
startTrackEvent(Action[action]);
return timestamp;
}
@@ -66,7 +66,7 @@ export function traceSuccess(
},
});
appInsights.stopTrackEvent(Action[action], decorateData(data, ActionModifiers.Success));
stopTrackEvent(Action[action], decorateData(data, ActionModifiers.Success));
}
export function traceFailure(
@@ -85,7 +85,7 @@ export function traceFailure(
},
});
appInsights.stopTrackEvent(Action[action], decorateData(data, ActionModifiers.Failed));
stopTrackEvent(Action[action], decorateData(data, ActionModifiers.Failed));
}
export function traceCancel(
@@ -104,7 +104,7 @@ export function traceCancel(
},
});
appInsights.stopTrackEvent(Action[action], decorateData(data, ActionModifiers.Cancel));
stopTrackEvent(Action[action], decorateData(data, ActionModifiers.Cancel));
}
export function traceOpen(
@@ -124,7 +124,7 @@ export function traceOpen(
},
});
appInsights.startTrackEvent(Action[action]);
startTrackEvent(Action[action]);
return validTimestamp;
}
@@ -145,7 +145,7 @@ export function traceMark(
},
});
appInsights.startTrackEvent(Action[action]);
startTrackEvent(Action[action]);
return validTimestamp;
}

View File

@@ -1,5 +1,8 @@
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
// TODO: Remove this after 06/01/21.
// This points to an old app insights instance that is difficult to access
// For now we are sending data to two instances of app insights
const appInsights = new ApplicationInsights({
config: {
instrumentationKey: "fa645d97-6237-4656-9559-0ee0cb55ee49",
@@ -7,7 +10,38 @@ const appInsights = new ApplicationInsights({
disableCorrelationHeaders: true,
},
});
appInsights.loadAppInsights();
appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
export { appInsights };
const appInsights2 = new ApplicationInsights({
config: {
instrumentationKey: "023d2c39-8f86-468e-bb8f-bcaebd9025c7",
disableFetchTracking: false,
disableCorrelationHeaders: true,
},
});
appInsights.loadAppInsights();
appInsights.trackPageView();
appInsights2.loadAppInsights();
appInsights2.trackPageView();
const trackEvent: typeof appInsights.trackEvent = (...args) => {
appInsights.trackEvent(...args);
appInsights2.trackEvent(...args);
};
const startTrackEvent: typeof appInsights.startTrackEvent = (...args) => {
appInsights.startTrackEvent(...args);
appInsights2.startTrackEvent(...args);
};
const stopTrackEvent: typeof appInsights.stopTrackEvent = (...args) => {
appInsights.stopTrackEvent(...args);
appInsights2.stopTrackEvent(...args);
};
const trackTrace: typeof appInsights.trackTrace = (...args) => {
appInsights.trackTrace(...args);
appInsights2.trackTrace(...args);
};
export { trackEvent, startTrackEvent, stopTrackEvent, trackTrace };