Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function wrapCustomTelemetryClient(
isTracingDisabled: boolean,
client: ApplicationInsights.TelemetryClient
): (
params: ITelemetryParams,
commonProperties?: Record
) => ApplicationInsights.TelemetryClient {
if (isTracingDisabled) {
// this won't disable manual calls to trackEvent / trackDependency
ApplicationInsights.Configuration.setAutoCollectConsole(false)
.setAutoCollectDependencies(false)
.setAutoCollectPerformance(false)
.setAutoCollectRequests(false)
.setInternalLogging(false)
// see https://stackoverflow.com/questions/49438235/application-insights-metric-in-aws-lambda/49441135#49441135
.setUseDiskRetryCaching(false);
}
return (params, commonProperties) => {
client.addTelemetryProcessor(env => {
// tslint:disable-next-line:no-object-mutation
env.tags = {
...env.tags,
[client.context.keys.operationId]: params.operationId,
[client.context.keys.operationParentId]: params.operationParentId,
[client.context.keys.userAccountId]: params.serviceId
};