SampledTelemetryHelper Class
Helper class that executes a specified code block and writes an @fluidframework/common-definitions#ITelemetryPerformanceEvent to a specified logger every time a specified number of executions is reached (or when the class is disposed). The duration
field in the telemetry event is the duration of the latest execution (sample) of the specified function. See the documentation of the includeAggregateMetrics
parameter for additional details that can be included.
Signature
export declare class SampledTelemetryHelper implements IDisposable
Implements: IDisposable
Constructors
Constructor | Description |
---|---|
(constructor)(eventBase, logger, sampleThreshold, includeAggregateMetrics, perBucketProperties) | Constructs a new instance of the SampledTelemetryHelper class |
Properties
Property | Type | Description |
---|---|---|
disposed | boolean |
Methods
Method | Return Type | Description |
---|---|---|
dispose(error) | void | |
measure(codeToMeasure, bucket) | T |
Constructor Details
(constructor)
Constructs a new instance of the SampledTelemetryHelper
class
Signature
constructor(eventBase: ITelemetryGenericEvent, logger: ITelemetryLogger, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryProperties>);
Parameters
Parameter | Modifiers | Type | Description |
---|---|---|---|
eventBase | ITelemetryGenericEvent | Custom properties to include in the telemetry performance event when it is written. | |
logger | ITelemetryLogger | The logger to use to write the telemetry performance event. | |
sampleThreshold | number | Telemetry performance events will be generated every time we hit this many executions of the code block. | |
includeAggregateMetrics | optional | boolean | If set to true , the telemetry performance event will include aggregated metrics (total duration, min duration, max duration) for all the executions in between generated events. |
perBucketProperties | optional | Map<string, ITelemetryProperties> | Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to properties which should be added to the telemetry event for that bucket. If a bucket being measured does not have an entry in this map, no additional properties will be added to its telemetry events. The following keys are reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be ignored. |
Property Details
disposed
Signature
disposed: boolean;
Type: boolean
Method Details
dispose
Signature
dispose(error?: Error | undefined): void;
Parameters
Parameter | Modifiers | Type | Description |
---|---|---|---|
error | optional | Error | undefined |
measure
Signature
measure<T>(codeToMeasure: () => T, bucket?: string): T;
Type Parameters
Parameter | Description |
---|---|
T |
Parameters
Parameter | Modifiers | Type | Description |
---|---|---|---|
codeToMeasure | () => T | The code to be executed and measured. | |
bucket | optional | string | A key to track executions of the code block separately. Each different value of this parameter has a separate set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a value. |
Returns
Whatever the passed-in code block returns.
Return type: T