зеркало из
1
0
Форкнуть 0
opensource-management-portal/lib/insights.ts

48 строки
1.5 KiB
TypeScript
Исходник Обычный вид История

2016-08-04 19:04:53 +03:00
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
'use strict';
import * as Debug from 'debug';
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' };
debug(typeof(eventNameOrProperties) === 'string' ? eventNameOrProperties : eventNameOrProperties.name);
};
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;