-
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.
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.
- Loading branch information
Showing
10 changed files
with
180 additions
and
30 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,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import ApplicationInsights = require("../../applicationinsights"); | ||
import {SeverityLevel} from "../../Declarations/Contracts"; | ||
|
||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {bunyan} from "diagnostic-channel-publishers"; | ||
|
||
// 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>) => { | ||
if (ApplicationInsights.client) { | ||
const AIlevel = bunyanToAILevelMap[event.data.level] | ||
ApplicationInsights.client.trackTrace(event.data.result, AIlevel) | ||
} | ||
}; | ||
|
||
export function enable(enabled: boolean) { | ||
if (enabled) { | ||
channel.subscribe<bunyan.IBunyanData>("bunyan", subscriber); | ||
} else { | ||
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,22 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import ApplicationInsights = require("../../applicationinsights"); | ||
import {SeverityLevel} from "../../Declarations/Contracts"; | ||
|
||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {console as consolePub} from "diagnostic-channel-publishers"; | ||
|
||
const subscriber = (event: IStandardEvent<consolePub.IConsoleData>) => { | ||
if (ApplicationInsights.client) { | ||
ApplicationInsights.client.trackTrace(event.data.message, event.data.stderr ? SeverityLevel.Warning : SeverityLevel.Information); | ||
} | ||
}; | ||
|
||
export function enable(enabled: boolean) { | ||
if (enabled) { | ||
channel.subscribe<consolePub.IConsoleData>("console", subscriber); | ||
} else { | ||
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,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import ApplicationInsights = require("../../applicationinsights"); | ||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {mongodb} from "diagnostic-channel-publishers"; | ||
|
||
export const subscriber = (event: IStandardEvent<mongodb.IMongoData>) => { | ||
if (ApplicationInsights.client) { | ||
const dbName = (event.data.startedData && event.data.startedData.databaseName) || "Unknown database"; | ||
ApplicationInsights.client | ||
.trackDependency( | ||
dbName, | ||
event.data.event.commandName, | ||
event.data.event.duration, | ||
event.data.succeeded, | ||
'mongodb'); | ||
|
||
if (!event.data.succeeded) { | ||
ApplicationInsights.client | ||
.trackException(new Error(event.data.event.failure)); | ||
} | ||
} | ||
}; | ||
|
||
export function enable(enabled: boolean) { | ||
if (enabled) { | ||
channel.subscribe<mongodb.IMongoData>("mongodb", subscriber); | ||
} else { | ||
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,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import ApplicationInsights = require("../../applicationinsights"); | ||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {mysql} from "diagnostic-channel-publishers"; | ||
|
||
export const subscriber = (event: IStandardEvent<mysql.IMysqlData>) => { | ||
if (ApplicationInsights.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}`; | ||
ApplicationInsights.client.trackDependency( | ||
dbName, | ||
sqlString, | ||
event.data.duration | 0, | ||
success, | ||
"mysql"); | ||
} | ||
}; | ||
|
||
export function enable(enabled: boolean) { | ||
if (enabled) { | ||
channel.subscribe<mysql.IMysqlData>("mysql", subscriber); | ||
} else { | ||
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,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for details. | ||
import ApplicationInsights = require("../../applicationinsights"); | ||
import {channel, IStandardEvent} from "diagnostic-channel"; | ||
|
||
import {redis} from "diagnostic-channel-publishers"; | ||
|
||
export const subscriber = (event: IStandardEvent<redis.IRedisData>) => { | ||
if (ApplicationInsights.client) { | ||
if (event.data.commandObj.command === "info") { | ||
// We don't want to report 'info', it's irrelevant | ||
return; | ||
} | ||
ApplicationInsights.client.trackDependency( | ||
event.data.address, | ||
event.data.commandObj.command, | ||
event.data.duration, | ||
!event.data.err, | ||
"redis" | ||
); | ||
} | ||
}; | ||
|
||
export function enable(enabled: boolean) { | ||
if (enabled) { | ||
channel.subscribe<redis.IRedisData>("redis", subscriber); | ||
} else { | ||
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