-
Notifications
You must be signed in to change notification settings - Fork 138
/
initialization.ts
executable file
·42 lines (38 loc) · 1.72 KB
/
initialization.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
// Don't reference modules from these directly. Use only for types.
// This is to avoid requiring the actual module if the NO_DIAGNOSTIC_CHANNEL env is present
import * as DiagChannelPublishers from "diagnostic-channel-publishers";
import * as DiagChannel from "diagnostic-channel";
import { AsyncScopeManager } from "../AsyncHooksScopeManager";
export const IsInitialized = !process.env["APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"];
if (IsInitialized) {
const publishers: typeof DiagChannelPublishers = require("diagnostic-channel-publishers");
const individualOptOuts = process.env["APPLICATION_INSIGHTS_NO_PATCH_MODULES"] || "";
const unpatchedModules = individualOptOuts.split(",");
const modules: {[key: string] : any} = {
bunyan: publishers.bunyan,
console: publishers.console,
mongodb: publishers.mongodb,
mongodbCore: publishers.mongodbCore,
mysql: publishers.mysql,
redis: publishers.redis,
pg: publishers.pg,
pgPool: publishers.pgPool,
winston: publishers.winston,
azuresdk: publishers.azuresdk
};
for (const mod in modules) {
if (unpatchedModules.indexOf(mod) === -1) {
modules[mod].enable();
}
}
}
export function registerContextPreservation(cb: (cb: Function) => Function) {
if (!IsInitialized) {
return;
}
const diagChannel = (require("diagnostic-channel") as typeof DiagChannel);
diagChannel.channel.addContextPreservation(cb);
diagChannel.channel.spanContextPropagator = AsyncScopeManager;
}