PerformanceClient class
Constructors
| Performance |
Creates an instance of PerformanceClient, an abstract class containing core performance telemetry logic. |
Methods
| add |
Saves extra information to be emitted when the measurements are flushed |
| add |
Registers a callback function to receive performance events. |
| add |
Adds queue measurement time to QueueMeasurements array for given correlation ID. |
| calculate |
Calculates the difference between current time and time when function was queued. Note: It is possible to have 0 as the queue time if the current time and the queued time was the same. |
| discard |
Removes measurements and aux data for a given correlation id. |
| emit |
Emits events to all registered callbacks. |
| end |
Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes, as consumers should instead use the function returned by startMeasurement. Adds a new field named as "[event name]DurationMs" for sub-measurements, completes and emits an event otherwise. |
| generate |
Generates and returns a unique id, typically a guid. |
| get |
Gets map of pre-queue times by correlation Id |
| increment |
Increment counters to be emitted when the measurements are flushed |
| remove |
Removes a callback registered with addPerformanceCallback. |
| set |
Sets pre-queue time by correlation Id |
| start |
Starts measuring performance for a given operation. Returns a function that should be used to end the measurement. |
| start |
Starts and returns an platform-specific implementation of IPerformanceMeasurement. Note: this function can be changed to abstract at the next major version bump. |
Constructor Details
PerformanceClient(string, string, Logger, string, string, ApplicationTelemetry, Set<string>, Map<string, string>)
Creates an instance of PerformanceClient, an abstract class containing core performance telemetry logic.
new PerformanceClient(clientId: string, authority: string, logger: Logger, libraryName: string, libraryVersion: string, applicationTelemetry: ApplicationTelemetry, intFields?: Set<string>, abbreviations?: Map<string, string>)
Parameters
- clientId
-
string
Client ID of the application
- authority
-
string
Authority used by the application
- logger
- Logger
Logger used by the application
- libraryName
-
string
Name of the library
- libraryVersion
-
string
Version of the library
- applicationTelemetry
- ApplicationTelemetry
application name and version
- intFields
-
Set<string>
integer fields to be truncated
- abbreviations
-
Map<string, string>
event name abbreviations
Method Details
addFields({[key: string]: {} | undefined}, string)
Saves extra information to be emitted when the measurements are flushed
function addFields(fields: {[key: string]: {} | undefined}, correlationId: string)
Parameters
- fields
-
{[key: string]: {} | undefined}
- correlationId
-
string
addPerformanceCallback(PerformanceCallbackFunction)
Registers a callback function to receive performance events.
function addPerformanceCallback(callback: PerformanceCallbackFunction): string
Parameters
- callback
- PerformanceCallbackFunction
Returns
string
addQueueMeasurement(string, string, number, boolean)
Adds queue measurement time to QueueMeasurements array for given correlation ID.
function addQueueMeasurement(eventName: string, correlationId?: string, queueTime?: number, manuallyCompleted?: boolean)
Parameters
- eventName
-
string
- correlationId
-
string
- queueTime
-
number
- manuallyCompleted
-
boolean
indicator for manually completed queue measurements
calculateQueuedTime(number, number)
Calculates the difference between current time and time when function was queued. Note: It is possible to have 0 as the queue time if the current time and the queued time was the same.
function calculateQueuedTime(preQueueTime: number, currentTime: number): number
Parameters
- preQueueTime
-
number
- currentTime
-
number
Returns
number
discardMeasurements(string)
Removes measurements and aux data for a given correlation id.
function discardMeasurements(correlationId: string)
Parameters
- correlationId
-
string
emitEvents(PerformanceEvent[], string)
Emits events to all registered callbacks.
function emitEvents(events: PerformanceEvent[], correlationId?: string)
Parameters
- events
- correlationId
-
string
endMeasurement(PerformanceEvent, unknown, AccountInfo)
Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes, as consumers should instead use the function returned by startMeasurement. Adds a new field named as "[event name]DurationMs" for sub-measurements, completes and emits an event otherwise.
function endMeasurement(event: PerformanceEvent, error?: unknown, account?: AccountInfo): null | PerformanceEvent
Parameters
- event
- PerformanceEvent
- error
-
unknown
- account
- AccountInfo
Returns
null | PerformanceEvent
generateId()
Generates and returns a unique id, typically a guid.
function generateId(): string
Returns
string
getPreQueueTime(string, string)
Gets map of pre-queue times by correlation Id
function getPreQueueTime(eventName: string, correlationId: string): number | void
Parameters
- eventName
-
string
- correlationId
-
string
Returns
number | void
incrementFields({[key: string]: number | undefined}, string)
Increment counters to be emitted when the measurements are flushed
function incrementFields(fields: {[key: string]: number | undefined}, correlationId: string)
Parameters
- fields
-
{[key: string]: number | undefined}
{string[]}
- correlationId
-
string
{string} correlation identifier
removePerformanceCallback(string)
Removes a callback registered with addPerformanceCallback.
function removePerformanceCallback(callbackId: string): boolean
Parameters
- callbackId
-
string
Returns
boolean
setPreQueueTime(PerformanceEvents, string)
Sets pre-queue time by correlation Id
function setPreQueueTime(eventName: PerformanceEvents, correlationId?: string)
Parameters
- eventName
- PerformanceEvents
- correlationId
-
string
startMeasurement(string, string)
Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
function startMeasurement(measureName: string, correlationId?: string): InProgressPerformanceEvent
Parameters
- measureName
-
string
- correlationId
-
string
Returns
startPerformanceMeasurement(string, string)
Warning
This API is now deprecated.
This method will be removed in the next major version
Starts and returns an platform-specific implementation of IPerformanceMeasurement. Note: this function can be changed to abstract at the next major version bump.
function startPerformanceMeasurement(measureName: string, correlationId: string): IPerformanceMeasurement
Parameters
- measureName
-
string
- correlationId
-
string