-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding diagnostic-channel By using diagnostic-channel and diagnostic-channel-publishers, we can support context tracking through third-party libraries as well as getting additional telemetry for those dependencies. * Fixing cyclical reference and supporting multiple AI clients in diagnostic-channel subscribers * Updating readme with diagnostic-channel information
- Loading branch information
1 parent
98e10d6
commit 68f24bb
Showing
11 changed files
with
226 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import Client = require("../../Library/Client"); | ||
import {SeverityLevel} from "../../Declarations/Contracts"; | ||
|
||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {bunyan} from "diagnostic-channel-publishers"; | ||
|
||
let clients: Client[] = []; | ||
|
||
// Mapping from bunyan levels defined at /~https://github.com/trentm/node-bunyan/blob/master/lib/bunyan.js#L256 | ||
const bunyanToAILevelMap = {}; | ||
bunyanToAILevelMap[10] = SeverityLevel.Verbose; | ||
bunyanToAILevelMap[20] = SeverityLevel.Verbose; | ||
bunyanToAILevelMap[30] = SeverityLevel.Information; | ||
bunyanToAILevelMap[40] = SeverityLevel.Warning; | ||
bunyanToAILevelMap[50] = SeverityLevel.Error; | ||
bunyanToAILevelMap[60] = SeverityLevel.Critical; | ||
|
||
const subscriber = (event: IStandardEvent<bunyan.IBunyanData>) => { | ||
clients.forEach((client) => { | ||
const AIlevel = bunyanToAILevelMap[event.data.level]; | ||
client.trackTrace(event.data.result, AIlevel); | ||
}); | ||
}; | ||
|
||
export function enable(enabled: boolean, client: Client) { | ||
if (enabled) { | ||
if (clients.length === 0) { | ||
channel.subscribe<bunyan.IBunyanData>("bunyan", subscriber); | ||
}; | ||
clients.push(client); | ||
} else { | ||
clients = clients.filter((c) => c != client); | ||
if (clients.length === 0) { | ||
channel.unsubscribe("bunyan", subscriber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import Client = require("../../Library/Client"); | ||
import {SeverityLevel} from "../../Declarations/Contracts"; | ||
|
||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {console as consolePub} from "diagnostic-channel-publishers"; | ||
|
||
let clients: Client[] = []; | ||
|
||
const subscriber = (event: IStandardEvent<consolePub.IConsoleData>) => { | ||
clients.forEach((client) => { | ||
client.trackTrace(event.data.message, event.data.stderr ? SeverityLevel.Warning : SeverityLevel.Information); | ||
}); | ||
}; | ||
|
||
export function enable(enabled: boolean, client: Client) { | ||
if (enabled) { | ||
if (clients.length === 0) { | ||
channel.subscribe<consolePub.IConsoleData>("console", subscriber); | ||
}; | ||
clients.push(client); | ||
} else { | ||
clients = clients.filter((c) => c != client); | ||
if (clients.length === 0) { | ||
channel.unsubscribe("console", subscriber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
|
||
import {enable} from "diagnostic-channel-publishers"; | ||
|
||
if (!process.env["APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"]) { | ||
enable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import Client = require("../../Library/Client"); | ||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {mongodb} from "diagnostic-channel-publishers"; | ||
|
||
let clients: Client[] = []; | ||
|
||
export const subscriber = (event: IStandardEvent<mongodb.IMongoData>) => { | ||
clients.forEach((client) => { | ||
const dbName = (event.data.startedData && event.data.startedData.databaseName) || "Unknown database"; | ||
client.trackDependency( | ||
dbName, | ||
event.data.event.commandName, | ||
event.data.event.duration, | ||
event.data.succeeded, | ||
'mongodb'); | ||
|
||
if (!event.data.succeeded) { | ||
client.trackException(new Error(event.data.event.failure)); | ||
} | ||
}); | ||
}; | ||
|
||
export function enable(enabled: boolean, client: Client) { | ||
if (enabled) { | ||
if (clients.length === 0) { | ||
channel.subscribe<mongodb.IMongoData>("mongodb", subscriber); | ||
}; | ||
clients.push(client); | ||
} else { | ||
clients = clients.filter((c) => c != client); | ||
if (clients.length === 0) { | ||
channel.unsubscribe("mongodb", subscriber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import Client = require("../../Library/Client"); | ||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {mysql} from "diagnostic-channel-publishers"; | ||
|
||
let clients: Client[] = []; | ||
|
||
export const subscriber = (event: IStandardEvent<mysql.IMysqlData>) => { | ||
clients.forEach((client) => { | ||
const queryObj = event.data.query || {}; | ||
const sqlString = queryObj.sql || "Unknown query"; | ||
const success = !event.data.err; | ||
|
||
const connection = queryObj._connection || {}; | ||
const connectionConfig = connection.config || {}; | ||
const dbName = connectionConfig.socketPath ? connectionConfig.socketPath : `${connectionConfig.host || "localhost"}:${connectionConfig.port}`; | ||
client.trackDependency( | ||
dbName, | ||
sqlString, | ||
event.data.duration | 0, | ||
success, | ||
"mysql"); | ||
}); | ||
}; | ||
|
||
export function enable(enabled: boolean, client: Client) { | ||
if (enabled) { | ||
if (clients.length === 0) { | ||
channel.subscribe<mysql.IMysqlData>("mysql", subscriber); | ||
}; | ||
clients.push(client); | ||
} else { | ||
clients = clients.filter((c) => c != client); | ||
if (clients.length === 0) { | ||
channel.unsubscribe("mysql", subscriber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import Client = require("../../Library/Client"); | ||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {redis} from "diagnostic-channel-publishers"; | ||
|
||
let clients: Client[] = []; | ||
|
||
export const subscriber = (event: IStandardEvent<redis.IRedisData>) => { | ||
clients.forEach((client) => { | ||
if (event.data.commandObj.command === "info") { | ||
// We don't want to report 'info', it's irrelevant | ||
return; | ||
} | ||
client.trackDependency( | ||
event.data.address, | ||
event.data.commandObj.command, | ||
event.data.duration, | ||
!event.data.err, | ||
"redis" | ||
); | ||
}); | ||
}; | ||
|
||
export function enable(enabled: boolean, client: Client) { | ||
if (enabled) { | ||
if (clients.length === 0) { | ||
channel.subscribe<redis.IRedisData>("redis", subscriber); | ||
}; | ||
clients.push(client); | ||
} else { | ||
clients = clients.filter((c) => c != client); | ||
if (clients.length === 0) { | ||
channel.unsubscribe("redis", subscriber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters