Skip to main content
Version: v1

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

ConstructorDescription
(constructor)(eventBase, logger, sampleThreshold, includeAggregateMetrics, perBucketProperties)Constructs a new instance of the SampledTelemetryHelper class

Properties

PropertyTypeDescription
disposedboolean

Methods

MethodReturn TypeDescription
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

ParameterModifiersTypeDescription
eventBaseITelemetryGenericEventCustom properties to include in the telemetry performance event when it is written.
loggerITelemetryLoggerThe logger to use to write the telemetry performance event.
sampleThresholdnumberTelemetry performance events will be generated every time we hit this many executions of the code block.
includeAggregateMetricsoptionalbooleanIf 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.
perBucketPropertiesoptionalMap<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

ParameterModifiersTypeDescription
erroroptionalError | undefined

measure

Signature

measure<T>(codeToMeasure: () => T, bucket?: string): T;
Type Parameters
ParameterDescription
T

Parameters

ParameterModifiersTypeDescription
codeToMeasure() => TThe code to be executed and measured.
bucketoptionalstringA 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