UNPKG

@itwin/core-telemetry

Version:
77 lines 2.77 kB
/*--------------------------------------------------------------------------------------------- * 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 */ import { BentleyError, Logger } from "@itwin/core-bentley"; import { TelemetryClientLoggerCategory } from "./TelemetryClientLoggerCategory"; /** Represents a particular occurrence of an event that can be tracked through various telemetry services * @internal */ export 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; } } /** @internal */ export 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) { Logger.logError(TelemetryClientLoggerCategory.Telemetry, `Failed to post telemetry via subclient`, () => 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); } } //# sourceMappingURL=TelemetryClient.js.map