@glimpse/glimpse-common
Advanced tools
Comparing version 0.21.5 to 0.22.11
{ | ||
"name": "@glimpse/glimpse-common", | ||
"version": "0.21.5", | ||
"version": "0.22.11", | ||
"license": "See license in license.md", | ||
@@ -34,6 +34,8 @@ "main": "./release/src/index.js", | ||
"dependencies": { | ||
"applicationinsights": "^0.15.18", | ||
"applicationinsights": "^0.19.0", | ||
"chalk": "^1.1.3", | ||
"config-chain": "^1.1.10", | ||
"node-uuid": "^1.4.7", | ||
"semver": "^5.3.0" | ||
"getmac": "^1.2.1", | ||
"semver": "^5.3.0", | ||
"uuid": "^2.0.2" | ||
}, | ||
@@ -43,5 +45,6 @@ "devDependencies": { | ||
"@types/chai": "^3.4.34", | ||
"@types/chalk": "^0.4.31", | ||
"@types/es6-promise": "0.0.32", | ||
"@types/mocha": "^2.2.33", | ||
"@types/node": "0.0.2", | ||
"@types/node": "^7.0.8", | ||
"@types/semver": "^5.3.30", | ||
@@ -52,3 +55,2 @@ "@types/uuid": "^2.0.29", | ||
"chai-json-schema": "^1.2.0", | ||
"getmac": "^1.2.1", | ||
"gulp": "^3.9.0", | ||
@@ -64,3 +66,3 @@ "gulp-babel": "^6.1.1", | ||
"tslint": "^3.15.1", | ||
"typescript": "^2.0.10", | ||
"typescript": "^2.4.1", | ||
"typings": "^1.0.4" | ||
@@ -67,0 +69,0 @@ }, |
@@ -5,11 +5,2 @@ /** | ||
export declare function getSlugForErrorCode(errorCode: ErrorCode): string; | ||
/** | ||
* Get's a fully qualified URL for the given slug. Currently, this returns the location | ||
* on the Home repo's README, but will be modified once the main website is live for the | ||
* new version of Glimpse | ||
* | ||
* @parameter {string} slug - The slug to get the URL for, e.g. "package--version-support" | ||
* @return {string} The fully qualified URL for the slug | ||
*/ | ||
export declare function getUrlForErrorCode(errorCode: ErrorCode): string; | ||
export declare enum ErrorCode { | ||
@@ -22,3 +13,2 @@ GlimpseAgentErrorBase = 1000, | ||
NewerUnsupportedPackageRequired = 1005, | ||
HttpClientError = 1006, | ||
HttpServerError = 1007, | ||
@@ -25,0 +15,0 @@ StackHelperUnsupportedSourceMapUri = 1008, |
@@ -7,3 +7,2 @@ import { ErrorCode } from './ErrorCodes'; | ||
export declare function createUnsupportedPackageRequiredError(packageName: string, requiredVersion: string, supportedRange: string): IGlimpseError; | ||
export declare function createHttpClientError(err: Error | string): IGlimpseError; | ||
export declare function createHttpServerError(err: Error | string): IGlimpseError; | ||
@@ -10,0 +9,0 @@ export declare function createHttpServerEarlyRequestTerminationError(requestUrl: string): IGlimpseError; |
@@ -16,2 +16,3 @@ import { ErrorCode } from './ErrorCodes'; | ||
message: string; | ||
url?: string; | ||
} |
@@ -13,6 +13,7 @@ export { ConfigSettings } from './configuration/ConfigSettings'; | ||
export { CompositeErrorReportingService } from './errors/CompositeErrorReportingService'; | ||
export { ErrorCode, getSlugForErrorCode, getUrlForErrorCode } from './errors/ErrorCodes'; | ||
export { createNoContextError, createPackageRequiredBeforeInitError, createUnexpectedContextError, createUnsupportedPackageRequiredError, createHttpClientError, createHttpServerError, createAuthorizationInvocationFailedError, createStackHelperUnsupportedSourceMapUriError, createStackHelperUnsupportedStackFrameFormat, createHttpServerEarlyRequestTerminationError, createAsyncTrackError, createAsyncTrackWarning, createVersionCheckError } from './errors/Errors'; | ||
export { ErrorCode, getSlugForErrorCode } from './errors/ErrorCodes'; | ||
export { createNoContextError, createPackageRequiredBeforeInitError, createUnexpectedContextError, createUnsupportedPackageRequiredError, createHttpServerError, createAuthorizationInvocationFailedError, createStackHelperUnsupportedSourceMapUriError, createStackHelperUnsupportedStackFrameFormat, createHttpServerEarlyRequestTerminationError, createAsyncTrackError, createAsyncTrackWarning, createVersionCheckError } from './errors/Errors'; | ||
export { printBannerGreeting } from './logging/Banner'; | ||
export { FileHelper } from './common/FileHelper'; | ||
export { IPackageHelper, PackageHelper } from './common/PackageHelper'; | ||
export { NodeVersionHelper } from './common/NodeVersionHelper'; |
@@ -26,3 +26,3 @@ import { IConfigSettings } from './../configuration/IConfigSettings'; | ||
*/ | ||
export declare function getTelemetryAppInstanceData(configSettings: IConfigSettings): ITelemetryAppInstanceData; | ||
export declare function getTelemetryAppInstanceData(configSettings: IConfigSettings, cb: (appInstanceData: ITelemetryAppInstanceData) => void): void; | ||
export declare class AppInstanceDataHelpers { | ||
@@ -35,7 +35,13 @@ /** | ||
*/ | ||
static computeMachineId(salt: string): string; | ||
static computeMachineId(salt: string, cb: (machineId: string) => void): void; | ||
/** | ||
* Retrieve a mac address for the current node | ||
* Retrieve a mac address for the current node. | ||
* | ||
* Node 8.0 & 8.1 introduced a bug on *nix where the mac addresses | ||
* returned by os.networkInterfaces() were incorrect. | ||
* | ||
* In order to keep machine IDs the same, we'll change to | ||
* use getmac library, which has been consistent. | ||
*/ | ||
static getMacAddress(): string; | ||
static getMacAddress(cb: (string) => void): void; | ||
} |
@@ -89,7 +89,7 @@ "use strict"; | ||
}; | ||
PackageHelper._instance = new PackageHelper(); | ||
return PackageHelper; | ||
}()); | ||
PackageHelper._instance = new PackageHelper(); | ||
exports.PackageHelper = PackageHelper; | ||
//# sourceMappingURL=../../../maps/src/common/PackageHelper.js.map |
@@ -160,7 +160,7 @@ 'use strict'; | ||
}; | ||
ConfigSettings.EVENT_VALUE_CHANGED = 'changed'; | ||
return ConfigSettings; | ||
}(events.EventEmitter)); | ||
ConfigSettings.EVENT_VALUE_CHANGED = 'changed'; | ||
exports.ConfigSettings = ConfigSettings; | ||
//# sourceMappingURL=../../../maps/src/configuration/ConfigSettings.js.map |
@@ -10,20 +10,2 @@ 'use strict'; | ||
exports.getSlugForErrorCode = getSlugForErrorCode; | ||
/** | ||
* Get's a fully qualified URL for the given slug. Currently, this returns the location | ||
* on the Home repo's README, but will be modified once the main website is live for the | ||
* new version of Glimpse | ||
* | ||
* @parameter {string} slug - The slug to get the URL for, e.g. "package--version-support" | ||
* @return {string} The fully qualified URL for the slug | ||
*/ | ||
function getUrlForErrorCode(errorCode) { | ||
switch (errorCode) { | ||
case ErrorCode.NewerUnsupportedPackageRequired: | ||
case ErrorCode.OlderUnsupportedPackageRequired: | ||
return 'https://github.com/Glimpse/Home#package--version-support'; | ||
default: | ||
return 'https://github.com/Glimpse/Home'; | ||
} | ||
} | ||
exports.getUrlForErrorCode = getUrlForErrorCode; | ||
var ErrorCode; | ||
@@ -38,3 +20,2 @@ (function (ErrorCode) { | ||
ErrorCode[ErrorCode["NewerUnsupportedPackageRequired"] = 1005] = "NewerUnsupportedPackageRequired"; | ||
ErrorCode[ErrorCode["HttpClientError"] = 1006] = "HttpClientError"; | ||
ErrorCode[ErrorCode["HttpServerError"] = 1007] = "HttpServerError"; | ||
@@ -41,0 +22,0 @@ ErrorCode[ErrorCode["StackHelperUnsupportedSourceMapUri"] = 1008] = "StackHelperUnsupportedSourceMapUri"; |
@@ -1,6 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk = require("chalk"); | ||
var semver_1 = require("semver"); | ||
var ErrorCodes_1 = require("./ErrorCodes"); | ||
var IGlimpseError_1 = require("./IGlimpseError"); | ||
var semver_1 = require("semver"); | ||
function createNoContextError() { | ||
@@ -20,3 +21,3 @@ return { | ||
errorCode: ErrorCodes_1.ErrorCode.UnexpectedContextValue, | ||
message: 'Glimpse unexpected context value at location %s. Expecting context ID %s. Actual context ID is %s' | ||
message: 'Glimpse unexpected context value at location %s. Expecting context ID %s. Actual context ID is %s' | ||
}; | ||
@@ -30,3 +31,4 @@ } | ||
errorCode: ErrorCodes_1.ErrorCode.PackageRequiredBeforeInit, | ||
message: "The package '" + packageName + "' was imported before Glimpse was initialized. Glimpse may not capture data related to that package." | ||
message: "The package " + chalk.red(packageName) + " was imported before Glimpse was initialized. Glimpse may not capture data related to that package.", | ||
url: 'https://aka.ms/glimpse-init' | ||
}; | ||
@@ -36,2 +38,3 @@ } | ||
function createUnsupportedPackageRequiredError(packageName, requiredVersion, supportedRange) { | ||
var url = 'https://aka.ms/glimpse-unsupported-package-version'; | ||
// We check if an older version than we support was required, or a newer one, | ||
@@ -44,3 +47,4 @@ // and set the severity and error code appropriately | ||
errorCode: ErrorCodes_1.ErrorCode.NewerUnsupportedPackageRequired, | ||
message: "Glimpse does not support version " + requiredVersion + " of " + packageName + " yet. You can get rich insights into " + packageName + " by downgrading to a supported version, as covered at " + ErrorCodes_1.getUrlForErrorCode(ErrorCodes_1.ErrorCode.NewerUnsupportedPackageRequired) + "." | ||
message: "Glimpse does not support version " + chalk.red(requiredVersion) + " of " + chalk.red(packageName) + " yet. You can get rich insights into " + packageName + " by downgrading to a supported version.", | ||
url: url | ||
}; | ||
@@ -53,15 +57,7 @@ } | ||
errorCode: ErrorCodes_1.ErrorCode.OlderUnsupportedPackageRequired, | ||
message: "Glimpse does not support version " + requiredVersion + " of " + packageName + ". You can get rich insights into " + packageName + " by upgrading to a supported version, as covered at " + ErrorCodes_1.getUrlForErrorCode(ErrorCodes_1.ErrorCode.OlderUnsupportedPackageRequired) + "." | ||
message: "Glimpse does not support version " + chalk.yellow(requiredVersion) + " of " + chalk.yellow(packageName) + ". You can get rich insights into " + packageName + " by upgrading to a supported version.", | ||
url: url | ||
}; | ||
} | ||
exports.createUnsupportedPackageRequiredError = createUnsupportedPackageRequiredError; | ||
function createHttpClientError(err) { | ||
return { | ||
severity: IGlimpseError_1.GlimpseErrorSeverity.Warning, | ||
errorClass: IGlimpseError_1.GlimpseErrorClass.User, | ||
errorCode: ErrorCodes_1.ErrorCode.HttpClientError, | ||
message: "A client HTTP request has errored, which will prevent this request from showing up in the Glimpse UI: " + err | ||
}; | ||
} | ||
exports.createHttpClientError = createHttpClientError; | ||
function createHttpServerError(err) { | ||
@@ -81,3 +77,3 @@ return { | ||
errorCode: ErrorCodes_1.ErrorCode.HttpServerEarlyRequestTerminationError, | ||
message: "A server HTTP response for request URL " + requestUrl + " was ended before the request was completed, which may prevent body information from showing up in the Glimpse UI" | ||
message: "A server HTTP response for request URL " + requestUrl + " was ended before the request was completed, which may prevent body information from showing up in the Glimpse UI." | ||
}; | ||
@@ -100,3 +96,3 @@ } | ||
errorCode: ErrorCodes_1.ErrorCode.StackHelperUnsupportedSourceMapUri, | ||
message: "Unsupported source map URI format found: " + uri | ||
message: "Unsupported source map URI format found: " + uri | ||
}; | ||
@@ -110,3 +106,3 @@ } | ||
errorCode: ErrorCodes_1.ErrorCode.StackHelperUnsupportedStackFrameFormat, | ||
message: "Unsupported stack frame format found: " + stackFrame | ||
message: "Unsupported stack frame format found: " + stackFrame | ||
}; | ||
@@ -113,0 +109,0 @@ } |
@@ -1,5 +0,17 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk = require("chalk"); | ||
var util = require("util"); | ||
var IGlimpseError_1 = require("./IGlimpseError"); | ||
var ErrorCodes_1 = require("./ErrorCodes"); | ||
function chalkBySeverity(severity, message) { | ||
switch (severity) { | ||
case IGlimpseError_1.GlimpseErrorSeverity.Error: | ||
return chalk.red(message); | ||
case IGlimpseError_1.GlimpseErrorSeverity.Warning: | ||
return chalk.yellow(message); | ||
default: | ||
return message; | ||
} | ||
} | ||
var LoggingErrorReportingService = (function () { | ||
@@ -13,3 +25,7 @@ function LoggingErrorReportingService() { | ||
} | ||
console.error.apply(console, ["Glimpse (" + IGlimpseError_1.GlimpseErrorSeverity[error.severity] + " " + ErrorCodes_1.getSlugForErrorCode(error.errorCode) + "): " + error.message].concat(params)); | ||
var header = chalkBySeverity(error.severity, "Glimpse: " + IGlimpseError_1.GlimpseErrorSeverity[error.severity].toLocaleUpperCase() + " (" + ErrorCodes_1.getSlugForErrorCode(error.errorCode) + "):"); | ||
var message = util.format.apply(util, [error.message].concat(params)); | ||
// NOTE: VS Code will not recognize chalk-ed URLs, so we don't use it for our error links. | ||
var url = error.url ? " (See " + error.url + ")" : ''; | ||
console.error(header + " " + message + url); | ||
}; | ||
@@ -16,0 +32,0 @@ return LoggingErrorReportingService; |
@@ -1,3 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk = require("chalk"); | ||
var util = require("util"); | ||
@@ -30,3 +31,4 @@ var IGlimpseError_1 = require("./IGlimpseError"); | ||
errorSlug: ErrorCodes_1.getSlugForErrorCode(error.errorCode), | ||
message: util.format.apply(util, [error.message].concat(params)) | ||
// NOTE: Messages may be chalk-formatted so we strip that before being reported. | ||
message: chalk.stripColor(util.format.apply(util, [error.message].concat(params))) | ||
}; | ||
@@ -33,0 +35,0 @@ this.telemetryService.sendEvent(TelemetryEvents_1.TelemetryEvents.ERROR, properties, measurements); |
@@ -30,3 +30,2 @@ "use strict"; | ||
exports.getSlugForErrorCode = ErrorCodes_1.getSlugForErrorCode; | ||
exports.getUrlForErrorCode = ErrorCodes_1.getUrlForErrorCode; | ||
var Errors_1 = require("./errors/Errors"); | ||
@@ -37,3 +36,2 @@ exports.createNoContextError = Errors_1.createNoContextError; | ||
exports.createUnsupportedPackageRequiredError = Errors_1.createUnsupportedPackageRequiredError; | ||
exports.createHttpClientError = Errors_1.createHttpClientError; | ||
exports.createHttpServerError = Errors_1.createHttpServerError; | ||
@@ -55,3 +53,5 @@ exports.createAuthorizationInvocationFailedError = Errors_1.createAuthorizationInvocationFailedError; | ||
exports.PackageHelper = PackageHelper_1.PackageHelper; | ||
var NodeVersionHelper_1 = require("./common/NodeVersionHelper"); | ||
exports.NodeVersionHelper = NodeVersionHelper_1.NodeVersionHelper; | ||
//# sourceMappingURL=../../maps/src/index.js.map |
@@ -6,2 +6,4 @@ "use strict"; | ||
var PackageHelper_1 = require("../common/PackageHelper"); | ||
// tslint:disable-next-line:no-var-requires | ||
var getmac = require('getmac'); | ||
/** | ||
@@ -14,18 +16,25 @@ * singletone instance per app | ||
*/ | ||
function getTelemetryAppInstanceData(configSettings) { | ||
function getTelemetryAppInstanceData(configSettings, cb) { | ||
if (!telemetryAppInstanceData) { | ||
var glimpseVersion = PackageHelper_1.PackageHelper.instance.getPackageVersion(PackageHelper_1.PackageHelper.instance.findGlimpseCommonPackageJsonPath()); | ||
var appName = PackageHelper_1.PackageHelper.instance.getPackageName(PackageHelper_1.PackageHelper.instance.findAppPackageJsonPath()); | ||
telemetryAppInstanceData = { | ||
glimpseVersion: glimpseVersion, | ||
appName: appName, | ||
machineId: AppInstanceDataHelpers.computeMachineId(configSettings.get('telemetry.identity.salt', undefined)), | ||
operatingSystemPlatform: os.platform(), | ||
operatingSystemRelease: os.release(), | ||
operatingSystemType: os.type(), | ||
runtimeVersion: process.version, | ||
runtimeName: 'NodeJS' | ||
}; | ||
var glimpseVersion_1 = PackageHelper_1.PackageHelper.instance.getPackageVersion(PackageHelper_1.PackageHelper.instance.findGlimpseCommonPackageJsonPath()); | ||
var appName_1 = PackageHelper_1.PackageHelper.instance.getPackageName(PackageHelper_1.PackageHelper.instance.findAppPackageJsonPath()); | ||
AppInstanceDataHelpers.computeMachineId(configSettings.get('telemetry.identity.salt', undefined), function (machineId) { | ||
telemetryAppInstanceData = { | ||
glimpseVersion: glimpseVersion_1, | ||
appName: appName_1, | ||
machineId: machineId, | ||
operatingSystemPlatform: os.platform(), | ||
operatingSystemRelease: os.release(), | ||
operatingSystemType: os.type(), | ||
runtimeVersion: process.version, | ||
runtimeName: 'NodeJS' | ||
}; | ||
cb(telemetryAppInstanceData); | ||
}); | ||
} | ||
return telemetryAppInstanceData; | ||
else { | ||
process.nextTick(function () { | ||
cb(telemetryAppInstanceData); | ||
}); | ||
} | ||
} | ||
@@ -42,36 +51,27 @@ exports.getTelemetryAppInstanceData = getTelemetryAppInstanceData; | ||
*/ | ||
AppInstanceDataHelpers.computeMachineId = function (salt) { | ||
var macAddress = AppInstanceDataHelpers.getMacAddress(); | ||
var data = macAddress; | ||
if (salt && salt.length > 0) { | ||
data = "salt: " + salt + ", macAddress: " + macAddress; | ||
} | ||
var machineId = crypto.createHash('sha256') | ||
.update(data, 'utf8') | ||
.digest('hex'); | ||
return machineId; | ||
AppInstanceDataHelpers.computeMachineId = function (salt, cb) { | ||
AppInstanceDataHelpers.getMacAddress(function (macAddress) { | ||
var data = macAddress; | ||
if (salt && salt.length > 0) { | ||
data = "salt: " + salt + ", macAddress: " + macAddress; | ||
} | ||
var machineId = crypto.createHash('sha256') | ||
.update(data, 'utf8') | ||
.digest('hex'); | ||
cb(machineId); | ||
}); | ||
}; | ||
/** | ||
* Retrieve a mac address for the current node | ||
* Retrieve a mac address for the current node. | ||
* | ||
* Node 8.0 & 8.1 introduced a bug on *nix where the mac addresses | ||
* returned by os.networkInterfaces() were incorrect. | ||
* | ||
* In order to keep machine IDs the same, we'll change to | ||
* use getmac library, which has been consistent. | ||
*/ | ||
AppInstanceDataHelpers.getMacAddress = function () { | ||
var networkInterfaces = os.networkInterfaces(); | ||
// if more than one mac address, just pick the first one that is not internal | ||
var interfaceNames = Object.keys(networkInterfaces); | ||
for (var i = 0; i < interfaceNames.length; i++) { | ||
var name_1 = interfaceNames[i]; | ||
var iface = networkInterfaces[name_1]; | ||
for (var j = 0; j < iface.length; j++) { | ||
var entry = iface[j]; | ||
if (!entry.internal) { | ||
var addr = entry.mac; | ||
if (os.platform() === 'win32') { | ||
// maintain consistency with what getmac library returns | ||
addr = addr.replace(/:/g, '-').toUpperCase(); | ||
} | ||
return addr; | ||
} | ||
} | ||
} | ||
return '00-00-00-00-00-00'; | ||
AppInstanceDataHelpers.getMacAddress = function (cb) { | ||
getmac.getMac(function (err, macAddress) { | ||
cb(macAddress); | ||
}); | ||
}; | ||
@@ -78,0 +78,0 @@ return AppInstanceDataHelpers; |
@@ -6,15 +6,15 @@ "use strict"; | ||
} | ||
TelemetryEvents.NODE_AGENT_REQUIRED = 'NodeAgentRequired'; | ||
TelemetryEvents.NODE_AGENT_PRE_INIT = 'NodeAgentPreInit'; | ||
TelemetryEvents.NODE_AGENT_INIT = 'NodeAgentInit'; | ||
TelemetryEvents.NODE_SERVER_REQUIRED = 'NodeServerRequired'; | ||
TelemetryEvents.NODE_SERVER_PRE_INIT = 'NodeServerPreInit'; | ||
TelemetryEvents.NODE_SERVER_INIT = 'NodeServerInit'; | ||
TelemetryEvents.NODE_SERVER_HUD_RESOURCE_ACCESSED = 'NodeServerHudResourceAccessed'; | ||
TelemetryEvents.ERROR = 'Error'; | ||
TelemetryEvents.DEPENDENCIES = 'Dependencies'; | ||
return TelemetryEvents; | ||
}()); | ||
TelemetryEvents.NODE_AGENT_REQUIRED = 'NodeAgentRequired'; | ||
TelemetryEvents.NODE_AGENT_PRE_INIT = 'NodeAgentPreInit'; | ||
TelemetryEvents.NODE_AGENT_INIT = 'NodeAgentInit'; | ||
TelemetryEvents.NODE_SERVER_REQUIRED = 'NodeServerRequired'; | ||
TelemetryEvents.NODE_SERVER_PRE_INIT = 'NodeServerPreInit'; | ||
TelemetryEvents.NODE_SERVER_INIT = 'NodeServerInit'; | ||
TelemetryEvents.NODE_SERVER_HUD_RESOURCE_ACCESSED = 'NodeServerHudResourceAccessed'; | ||
TelemetryEvents.ERROR = 'Error'; | ||
TelemetryEvents.DEPENDENCIES = 'Dependencies'; | ||
exports.TelemetryEvents = TelemetryEvents; | ||
//# sourceMappingURL=../../../maps/src/telemetry/TelemetryEvents.js.map |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var uuid = require("uuid"); | ||
/* tslint:disable:no-var-requires */ | ||
var appInsights = require('applicationinsights'); | ||
var AppInsights = require("applicationinsights"); | ||
/** indicates which of the various glimpse components is sending the event */ | ||
@@ -31,3 +30,3 @@ var GlimpseComponentType; | ||
if (this.isTelemetryEnabled) { | ||
appInsights.setup('00000000-0000-0000-0000-000000000000') | ||
AppInsights.setup('00000000-0000-0000-0000-000000000000') | ||
.setAutoCollectConsole(false) | ||
@@ -37,4 +36,5 @@ .setAutoCollectExceptions(false) | ||
.setAutoCollectRequests(false); | ||
var client = appInsights.getClient(telemetryConfig.instrumentationKey); | ||
client.context.tags[client.context.keys.deviceMachineName] = ''; //prevent App Insights from reporting machine name | ||
var client = AppInsights.getClient(telemetryConfig.instrumentationKey); | ||
AppInsights.disableConsoleLogging(); // prevent AI from writing errors/warnings to the console, e.g. when disconnected from network | ||
client.context.tags[client.context.keys.deviceId] = ''; //prevent AI from reporting machine name | ||
client.config.endpointUrl = telemetryConfig.uri; | ||
@@ -41,0 +41,0 @@ this.aiClient = client; |
@@ -10,20 +10,2 @@ 'use strict'; | ||
/** | ||
* Get's a fully qualified URL for the given slug. Currently, this returns the location | ||
* on the Home repo's README, but will be modified once the main website is live for the | ||
* new version of Glimpse | ||
* | ||
* @parameter {string} slug - The slug to get the URL for, e.g. "package--version-support" | ||
* @return {string} The fully qualified URL for the slug | ||
*/ | ||
export function getUrlForErrorCode(errorCode: ErrorCode): string { | ||
switch (errorCode) { | ||
case ErrorCode.NewerUnsupportedPackageRequired: | ||
case ErrorCode.OlderUnsupportedPackageRequired: | ||
return 'https://github.com/Glimpse/Home#package--version-support'; | ||
default: | ||
return 'https://github.com/Glimpse/Home'; | ||
} | ||
} | ||
export enum ErrorCode { | ||
@@ -37,3 +19,2 @@ // Agent Errors | ||
NewerUnsupportedPackageRequired = 1005, | ||
HttpClientError = 1006, | ||
HttpServerError = 1007, | ||
@@ -40,0 +21,0 @@ StackHelperUnsupportedSourceMapUri = 1008, |
@@ -1,6 +0,6 @@ | ||
'use strict'; | ||
import * as chalk from 'chalk'; | ||
import { outside } from 'semver'; | ||
import { ErrorCode, getUrlForErrorCode } from './ErrorCodes'; | ||
import { ErrorCode } from './ErrorCodes'; | ||
import { IGlimpseError, GlimpseErrorClass, GlimpseErrorSeverity } from './IGlimpseError'; | ||
import { outside } from 'semver'; | ||
@@ -21,3 +21,3 @@ export function createNoContextError(): IGlimpseError { | ||
errorCode: ErrorCode.UnexpectedContextValue, | ||
message: 'Glimpse unexpected context value at location %s. Expecting context ID %s. Actual context ID is %s' | ||
message: 'Glimpse unexpected context value at location %s. Expecting context ID %s. Actual context ID is %s' | ||
}; | ||
@@ -31,3 +31,4 @@ } | ||
errorCode: ErrorCode.PackageRequiredBeforeInit, | ||
message: `The package '${packageName}' was imported before Glimpse was initialized. Glimpse may not capture data related to that package.` | ||
message: `The package ${chalk.red(packageName)} was imported before Glimpse was initialized. Glimpse may not capture data related to that package.`, | ||
url: 'https://aka.ms/glimpse-init' | ||
}; | ||
@@ -37,2 +38,3 @@ } | ||
export function createUnsupportedPackageRequiredError(packageName: string, requiredVersion: string, supportedRange: string): IGlimpseError { | ||
const url = 'https://aka.ms/glimpse-unsupported-package-version'; | ||
@@ -46,3 +48,4 @@ // We check if an older version than we support was required, or a newer one, | ||
errorCode: ErrorCode.NewerUnsupportedPackageRequired, | ||
message: `Glimpse does not support version ${requiredVersion} of ${packageName} yet. You can get rich insights into ${packageName} by downgrading to a supported version, as covered at ${getUrlForErrorCode(ErrorCode.NewerUnsupportedPackageRequired)}.` | ||
message: `Glimpse does not support version ${chalk.red(requiredVersion)} of ${chalk.red(packageName)} yet. You can get rich insights into ${packageName} by downgrading to a supported version.`, | ||
url | ||
}; | ||
@@ -55,15 +58,7 @@ } | ||
errorCode: ErrorCode.OlderUnsupportedPackageRequired, | ||
message: `Glimpse does not support version ${requiredVersion} of ${packageName}. You can get rich insights into ${packageName} by upgrading to a supported version, as covered at ${getUrlForErrorCode(ErrorCode.OlderUnsupportedPackageRequired)}.` | ||
message: `Glimpse does not support version ${chalk.yellow(requiredVersion)} of ${chalk.yellow(packageName)}. You can get rich insights into ${packageName} by upgrading to a supported version.`, | ||
url | ||
}; | ||
} | ||
export function createHttpClientError(err: Error | string): IGlimpseError { | ||
return { | ||
severity: GlimpseErrorSeverity.Warning, | ||
errorClass: GlimpseErrorClass.User, | ||
errorCode: ErrorCode.HttpClientError, | ||
message: `A client HTTP request has errored, which will prevent this request from showing up in the Glimpse UI: ${err}` | ||
}; | ||
} | ||
export function createHttpServerError(err: Error | string): IGlimpseError { | ||
@@ -83,3 +78,3 @@ return { | ||
errorCode: ErrorCode.HttpServerEarlyRequestTerminationError, | ||
message: `A server HTTP response for request URL ${requestUrl} was ended before the request was completed, which may prevent body information from showing up in the Glimpse UI` | ||
message: `A server HTTP response for request URL ${requestUrl} was ended before the request was completed, which may prevent body information from showing up in the Glimpse UI.` | ||
}; | ||
@@ -102,3 +97,3 @@ } | ||
errorCode: ErrorCode.StackHelperUnsupportedSourceMapUri, | ||
message: `Unsupported source map URI format found: ${uri}` | ||
message: `Unsupported source map URI format found: ${uri}` | ||
}; | ||
@@ -112,3 +107,3 @@ } | ||
errorCode: ErrorCode.StackHelperUnsupportedStackFrameFormat, | ||
message: `Unsupported stack frame format found: ${stackFrame}` | ||
message: `Unsupported stack frame format found: ${stackFrame}` | ||
}; | ||
@@ -115,0 +110,0 @@ } |
@@ -21,2 +21,3 @@ 'use strict'; | ||
message: string; | ||
url?: string; | ||
} |
@@ -1,2 +0,3 @@ | ||
'use strict'; | ||
import * as chalk from 'chalk'; | ||
import * as util from 'util'; | ||
@@ -7,6 +8,23 @@ import { IErrorReportingService } from './IErrorReportingService'; | ||
function chalkBySeverity(severity: GlimpseErrorSeverity, message: string): string { | ||
switch (severity) { | ||
case GlimpseErrorSeverity.Error: | ||
return chalk.red(message); | ||
case GlimpseErrorSeverity.Warning: | ||
return chalk.yellow(message); | ||
default: | ||
return message; | ||
} | ||
} | ||
export class LoggingErrorReportingService implements IErrorReportingService { | ||
public reportError(error: IGlimpseError, ...params): void { | ||
console.error(`Glimpse (${GlimpseErrorSeverity[error.severity]} ${getSlugForErrorCode(error.errorCode)}): ${error.message}`, ...params); | ||
const header = chalkBySeverity(error.severity, `Glimpse: ${GlimpseErrorSeverity[error.severity].toLocaleUpperCase()} (${getSlugForErrorCode(error.errorCode)}):`); | ||
const message = util.format(error.message, ...params); | ||
// NOTE: VS Code will not recognize chalk-ed URLs, so we don't use it for our error links. | ||
const url = error.url ? ` (See ${error.url})` : ''; | ||
console.error(`${header} ${message}${url}`); | ||
} | ||
} |
@@ -0,5 +1,4 @@ | ||
import * as chalk from 'chalk'; | ||
import * as util from 'util'; | ||
'use strict'; | ||
import * as util from 'util'; | ||
import { IErrorReportingService } from './IErrorReportingService'; | ||
@@ -37,3 +36,4 @@ import { IGlimpseError, GlimpseErrorClass, GlimpseErrorSeverity } from './IGlimpseError'; | ||
errorSlug: getSlugForErrorCode(error.errorCode), | ||
message: util.format(error.message, ...params) | ||
// NOTE: Messages may be chalk-formatted so we strip that before being reported. | ||
message: chalk.stripColor(util.format(error.message, ...params)) | ||
}; | ||
@@ -40,0 +40,0 @@ |
@@ -19,3 +19,3 @@ | ||
export { CompositeErrorReportingService } from './errors/CompositeErrorReportingService'; | ||
export { ErrorCode, getSlugForErrorCode, getUrlForErrorCode } from './errors/ErrorCodes'; | ||
export { ErrorCode, getSlugForErrorCode } from './errors/ErrorCodes'; | ||
export { | ||
@@ -26,3 +26,2 @@ createNoContextError, | ||
createUnsupportedPackageRequiredError, | ||
createHttpClientError, | ||
createHttpServerError, | ||
@@ -44,1 +43,2 @@ createAuthorizationInvocationFailedError, | ||
export { IPackageHelper, PackageHelper } from './common/PackageHelper'; | ||
export { NodeVersionHelper } from './common/NodeVersionHelper'; |
@@ -7,2 +7,5 @@ import crypto = require('crypto'); | ||
// tslint:disable-next-line:no-var-requires | ||
const getmac = require('getmac'); | ||
/** | ||
@@ -46,3 +49,3 @@ * Shape of telemetry config resource returned from the server. | ||
*/ | ||
export function getTelemetryAppInstanceData(configSettings: IConfigSettings) { | ||
export function getTelemetryAppInstanceData(configSettings: IConfigSettings, cb: (appInstanceData: ITelemetryAppInstanceData) => void) { | ||
if (!telemetryAppInstanceData) { | ||
@@ -52,19 +55,26 @@ const glimpseVersion = PackageHelper.instance.getPackageVersion(PackageHelper.instance.findGlimpseCommonPackageJsonPath()); | ||
telemetryAppInstanceData = { | ||
glimpseVersion, | ||
appName, | ||
machineId: AppInstanceDataHelpers.computeMachineId(configSettings.get('telemetry.identity.salt', undefined)), | ||
operatingSystemPlatform: os.platform(), | ||
operatingSystemRelease: os.release(), | ||
operatingSystemType: os.type(), | ||
runtimeVersion: process.version, | ||
runtimeName: 'NodeJS' | ||
}; | ||
AppInstanceDataHelpers.computeMachineId( | ||
configSettings.get('telemetry.identity.salt', undefined), | ||
machineId => { | ||
telemetryAppInstanceData = { | ||
glimpseVersion, | ||
appName, | ||
machineId: machineId, | ||
operatingSystemPlatform: os.platform(), | ||
operatingSystemRelease: os.release(), | ||
operatingSystemType: os.type(), | ||
runtimeVersion: process.version, | ||
runtimeName: 'NodeJS' | ||
}; | ||
cb(telemetryAppInstanceData); | ||
} | ||
); | ||
} else { | ||
process.nextTick(() => { | ||
cb(telemetryAppInstanceData); | ||
}); | ||
} | ||
return telemetryAppInstanceData; | ||
} | ||
export class AppInstanceDataHelpers { | ||
/** | ||
@@ -76,40 +86,29 @@ * compute machine ID for this node | ||
*/ | ||
public static computeMachineId(salt: string) { | ||
const macAddress = AppInstanceDataHelpers.getMacAddress(); | ||
let data = macAddress; | ||
if (salt && salt.length > 0) { | ||
data = `salt: ${salt}, macAddress: ${macAddress}`; | ||
} | ||
const machineId = crypto.createHash('sha256') | ||
.update(data, 'utf8') | ||
.digest('hex'); | ||
return machineId; | ||
public static computeMachineId(salt: string, cb: (machineId: string) => void) { | ||
AppInstanceDataHelpers.getMacAddress(macAddress => { | ||
let data = macAddress; | ||
if (salt && salt.length > 0) { | ||
data = `salt: ${salt}, macAddress: ${macAddress}`; | ||
} | ||
const machineId = crypto.createHash('sha256') | ||
.update(data, 'utf8') | ||
.digest('hex'); | ||
cb(machineId); | ||
}); | ||
} | ||
/** | ||
* Retrieve a mac address for the current node | ||
* Retrieve a mac address for the current node. | ||
* | ||
* Node 8.0 & 8.1 introduced a bug on *nix where the mac addresses | ||
* returned by os.networkInterfaces() were incorrect. | ||
* | ||
* In order to keep machine IDs the same, we'll change to | ||
* use getmac library, which has been consistent. | ||
*/ | ||
public static getMacAddress() { | ||
const networkInterfaces = os.networkInterfaces(); | ||
// if more than one mac address, just pick the first one that is not internal | ||
const interfaceNames = Object.keys(networkInterfaces); | ||
for (let i = 0; i < interfaceNames.length; i++) { | ||
const name = interfaceNames[i]; | ||
const iface = networkInterfaces[name]; | ||
for (let j = 0; j < iface.length; j++) { | ||
const entry = iface[j]; | ||
if (!entry.internal) { | ||
let addr = entry.mac; | ||
if (os.platform() === 'win32') { | ||
// maintain consistency with what getmac library returns | ||
addr = addr.replace(/:/g, '-').toUpperCase(); | ||
} | ||
return addr; | ||
} | ||
} | ||
} | ||
return '00-00-00-00-00-00'; | ||
public static getMacAddress(cb: (string) => void) { | ||
getmac.getMac(function(err, macAddress) { | ||
cb(macAddress); | ||
}); | ||
} | ||
} |
@@ -7,5 +7,3 @@ | ||
/* tslint:disable:no-var-requires */ | ||
const appInsights = require('applicationinsights'); | ||
/* tslint:enable:no-var-requires */ | ||
import AppInsights = require('applicationinsights'); | ||
@@ -65,7 +63,7 @@ /** | ||
// telemetry configuration details retrieved from the glimpse server. This is populated asynchronously, so there's logic to | ||
// telemetry configuration details retrieved from the glimpse server. This is populated asynchronously, so there's logic to | ||
// account for events sent before & after telemetryConfig is available. | ||
private telemetryConfig: ITelemetryConfig; | ||
private aiClient: typeof appInsights.client; | ||
private aiClient: typeof AppInsights.client; | ||
@@ -83,3 +81,3 @@ // telemetry enabled defaults to true, value will be reset when we receive the telemetryConfig. | ||
if (this.isTelemetryEnabled) { | ||
appInsights.setup('00000000-0000-0000-0000-000000000000') | ||
AppInsights.setup('00000000-0000-0000-0000-000000000000') | ||
.setAutoCollectConsole(false) | ||
@@ -90,4 +88,5 @@ .setAutoCollectExceptions(false) | ||
const client = appInsights.getClient(telemetryConfig.instrumentationKey); | ||
client.context.tags[client.context.keys.deviceMachineName] = ''; //prevent App Insights from reporting machine name | ||
const client = AppInsights.getClient(telemetryConfig.instrumentationKey); | ||
AppInsights.disableConsoleLogging(); // prevent AI from writing errors/warnings to the console, e.g. when disconnected from network | ||
client.context.tags[client.context.keys.deviceId] = ''; //prevent AI from reporting machine name | ||
client.config.endpointUrl = telemetryConfig.uri; | ||
@@ -94,0 +93,0 @@ this.aiClient = client; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
153103
92
2324
6
+ Addedchalk@^1.1.3
+ Addedgetmac@^1.2.1
+ Addeduuid@^2.0.2
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedapplicationinsights@0.19.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedeachr@3.3.0(transitive)
+ Addededitions@2.3.1(transitive)
+ Addederrlop@2.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextract-opts@3.4.0(transitive)
+ Addedgetmac@1.5.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtypechecker@4.11.0(transitive)
+ Addeduuid@2.0.3(transitive)
+ Addedzone.js@0.7.6(transitive)
- Removednode-uuid@^1.4.7
- Removedapplicationinsights@0.15.19(transitive)
- Removednode-uuid@1.4.8(transitive)
Updatedapplicationinsights@^0.19.0