@itwin/core-telemetry
Version:
iTwin.js Telemetry Client
82 lines • 3.04 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Telemetry
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TelemetryManager = exports.TelemetryEvent = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const TelemetryClientLoggerCategory_1 = require("./TelemetryClientLoggerCategory");
/** Represents a particular occurrence of an event that can be tracked through various telemetry services
* @internal
*/
class TelemetryEvent {
constructor(
/** Human-readable name for the event being tracked */
eventName,
/**
* Optional Guid that can be used to more accurately identify the telemetry event.
* This field is required when posting a telemetry event as feature usage to ULAS.
*/
eventId,
/** iModel parent iTwin id */
iTwinId, iModelId, changeSetId, time,
/** Custom properties */
additionalProperties = {}) {
this.eventName = eventName;
this.eventId = eventId;
this.iTwinId = iTwinId;
this.iModelId = iModelId;
this.changeSetId = changeSetId;
this.time = time;
this.additionalProperties = additionalProperties;
}
/**
* Returns all properties as a new object
*/
getProperties() {
const properties = {
eventName: this.eventName,
eventId: this.eventId,
iTwinId: this.iTwinId,
iModelId: this.iModelId,
changeSetId: this.changeSetId,
time: this.time,
additionalProperties: this.additionalProperties,
};
return properties;
}
}
exports.TelemetryEvent = TelemetryEvent;
/** @internal */
class TelemetryManager {
constructor(...clients) {
this._clients = new Set(clients);
}
async postTelemetry(requestContext, telemetryEvent) {
const postPerClient = async (subClient) => {
try {
await subClient.postTelemetry(requestContext, telemetryEvent);
}
catch (err) {
core_bentley_1.Logger.logError(TelemetryClientLoggerCategory_1.TelemetryClientLoggerCategory.Telemetry, `Failed to post telemetry via subclient`, () => core_bentley_1.BentleyError.getErrorProps(err));
}
};
const subClientPromises = [];
for (const subClient of this._clients) {
subClientPromises.push(postPerClient(subClient));
}
await Promise.all(subClientPromises);
}
addClient(client) {
this._clients.add(client);
}
hasClient(client) {
return this._clients.has(client);
}
}
exports.TelemetryManager = TelemetryManager;
//# sourceMappingURL=TelemetryClient.js.map