2016-08-04 19:04:53 +03:00
|
|
|
//
|
2019-10-03 04:41:16 +03:00
|
|
|
// Copyright (c) Microsoft.
|
2016-08-04 19:04:53 +03:00
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
//
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2019-08-07 02:53:50 +03:00
|
|
|
import Debug from 'debug';
|
2019-04-06 00:45:34 +03:00
|
|
|
const debug = Debug('appinsights');
|
2016-08-04 19:04:53 +03:00
|
|
|
|
2018-05-02 20:28:35 +03:00
|
|
|
// This file was originally designed to wrap the pre-1.0.0 version of applicationinsights,
|
|
|
|
// and so is less important today.
|
|
|
|
|
2016-08-04 19:04:53 +03:00
|
|
|
function createWrappedClient(propertiesToInsert, client) {
|
2018-05-02 20:28:35 +03:00
|
|
|
const c = client || {};
|
2016-08-04 19:04:53 +03:00
|
|
|
if (client) {
|
2018-05-02 20:28:35 +03:00
|
|
|
client.commonProperties = propertiesToInsert;
|
2016-08-04 19:04:53 +03:00
|
|
|
} else {
|
|
|
|
c.trackEvent = consoleHandler;
|
|
|
|
c.trackException = consoleHandler;
|
|
|
|
c.trackMetric = consoleMetric;
|
|
|
|
c.trackTrace = consoleHandler;
|
2018-05-02 20:28:35 +03:00
|
|
|
c.trackDependency = consoleHandler;
|
|
|
|
c.flush = (options) => {
|
|
|
|
options = options || {};
|
|
|
|
if (options.callback) {
|
|
|
|
return options.callback();
|
|
|
|
}
|
|
|
|
};
|
2016-08-04 19:04:53 +03:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2018-05-02 20:28:35 +03:00
|
|
|
const consoleHandler = (eventNameOrProperties) => {
|
|
|
|
eventNameOrProperties = eventNameOrProperties || { name: 'Unknown event, may be from pre-v1.0.0 applicationinsights' };
|
2019-08-07 02:53:50 +03:00
|
|
|
let props = '';
|
|
|
|
if (eventNameOrProperties && eventNameOrProperties.properties) {
|
|
|
|
props = ' ';
|
|
|
|
for (let [key, value] of Object.entries(eventNameOrProperties.properties)) {
|
|
|
|
props += `${key}=${value} `;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug((typeof(eventNameOrProperties) === 'string' ? eventNameOrProperties : eventNameOrProperties.name) + props);
|
2017-05-31 20:07:13 +03:00
|
|
|
};
|
2018-05-02 20:28:35 +03:00
|
|
|
const consoleMetric = (eventNameOrProperties) => {
|
|
|
|
if (typeof(eventNameOrProperties) === 'string') {
|
|
|
|
debug(`Legacy applicationinsights Metric ${eventNameOrProperties} was not recorded`);
|
|
|
|
} else {
|
|
|
|
eventNameOrProperties = eventNameOrProperties || { name: 'UnknownMetric', value: 0 };
|
|
|
|
debug(`Metric(${eventNameOrProperties.name}: ${eventNameOrProperties.value}`);
|
2016-08-04 19:04:53 +03:00
|
|
|
}
|
2018-05-02 20:28:35 +03:00
|
|
|
};
|
2016-08-04 19:04:53 +03:00
|
|
|
|
|
|
|
module.exports = createWrappedClient;
|