@fluidframework/telemetry-utils
Advanced tools
Comparing version 2.0.0-dev-rc.5.0.0.272251 to 2.0.0-dev-rc.5.0.0.272889
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"extends": "../../../common/build/build-common/api-extractor-base.esm.primary.json" | ||
"extends": "../../../common/build/build-common/api-extractor-base.esm.current.json" | ||
} |
@@ -12,8 +12,8 @@ /*! | ||
export { eventNamespaceSeparator, createChildLogger, createMultiSinkLogger, formatTick, type IPerformanceEventMarkers, type ITelemetryLoggerPropertyBag, type ITelemetryLoggerPropertyBags, type MultiSinkLoggerProperties, numberFromString, PerformanceEvent, TaggedLoggerAdapter, tagData, tagCodeArtifacts, TelemetryDataTag, type TelemetryEventPropertyTypes, } from "./logger.js"; | ||
export { MockLogger } from "./mockLogger.js"; | ||
export { createMockLoggerExt, type IMockLoggerExt, MockLogger } from "./mockLogger.js"; | ||
export { ThresholdCounter } from "./thresholdCounter.js"; | ||
export { SampledTelemetryHelper } from "./sampledTelemetryHelper.js"; | ||
export { createSampledLogger, type IEventSampler, type ISampledTelemetryLogger } from "./utils.js"; | ||
export { createSampledLogger, type IEventSampler, type ISampledTelemetryLogger, measure, } from "./utils.js"; | ||
export type { TelemetryEventPropertyTypeExt, ITelemetryEventExt, ITelemetryGenericEventExt, ITelemetryErrorEventExt, ITelemetryPerformanceEventExt, ITelemetryLoggerExt, ITaggedTelemetryPropertyTypeExt, ITelemetryPropertiesExt, TelemetryEventCategory, } from "./telemetryTypes.js"; | ||
export { type IMeasuredCodeResult, TelemetryEventBatcher } from "./telemetryEventBatcher.js"; | ||
export { TelemetryEventBatcher } from "./telemetryEventBatcher.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TelemetryEventBatcher = exports.createSampledLogger = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.TelemetryDataTag = exports.tagCodeArtifacts = exports.tagData = exports.TaggedLoggerAdapter = exports.PerformanceEvent = exports.numberFromString = exports.formatTick = exports.createMultiSinkLogger = exports.createChildLogger = exports.eventNamespaceSeparator = exports.isFluidError = exports.hasErrorInstanceId = exports.safeRaiseEvent = exports.raiseConnectedEvent = exports.disconnectedEventName = exports.connectedEventName = exports.EventEmitterWithErrorHandling = exports.wrapErrorAndLog = exports.wrapError = exports.overwriteStack = exports.normalizeError = exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.isTaggedTelemetryPropertyValue = exports.isILoggingError = exports.isExternalError = exports.getCircularReplacer = exports.generateStack = exports.generateErrorWithStack = exports.extractLogSafeErrorProperties = exports.validatePrecondition = exports.UsageError = exports.GenericError = exports.extractSafePropertiesFromMessage = exports.DataProcessingError = exports.DataCorruptionError = exports.wrapConfigProviderWithDefaults = exports.loggerToMonitoringContext = exports.mixinMonitoringContext = exports.sessionStorageConfigProvider = exports.createChildMonitoringContext = void 0; | ||
exports.TelemetryEventBatcher = exports.measure = exports.createSampledLogger = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.createMockLoggerExt = exports.TelemetryDataTag = exports.tagCodeArtifacts = exports.tagData = exports.TaggedLoggerAdapter = exports.PerformanceEvent = exports.numberFromString = exports.formatTick = exports.createMultiSinkLogger = exports.createChildLogger = exports.eventNamespaceSeparator = exports.isFluidError = exports.hasErrorInstanceId = exports.safeRaiseEvent = exports.raiseConnectedEvent = exports.disconnectedEventName = exports.connectedEventName = exports.EventEmitterWithErrorHandling = exports.wrapErrorAndLog = exports.wrapError = exports.overwriteStack = exports.normalizeError = exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.isTaggedTelemetryPropertyValue = exports.isILoggingError = exports.isExternalError = exports.getCircularReplacer = exports.generateStack = exports.generateErrorWithStack = exports.extractLogSafeErrorProperties = exports.validatePrecondition = exports.UsageError = exports.GenericError = exports.extractSafePropertiesFromMessage = exports.DataProcessingError = exports.DataCorruptionError = exports.wrapConfigProviderWithDefaults = exports.loggerToMonitoringContext = exports.mixinMonitoringContext = exports.sessionStorageConfigProvider = exports.createChildMonitoringContext = void 0; | ||
var config_js_1 = require("./config.js"); | ||
@@ -58,2 +58,3 @@ Object.defineProperty(exports, "createChildMonitoringContext", { enumerable: true, get: function () { return config_js_1.createChildMonitoringContext; } }); | ||
var mockLogger_js_1 = require("./mockLogger.js"); | ||
Object.defineProperty(exports, "createMockLoggerExt", { enumerable: true, get: function () { return mockLogger_js_1.createMockLoggerExt; } }); | ||
Object.defineProperty(exports, "MockLogger", { enumerable: true, get: function () { return mockLogger_js_1.MockLogger; } }); | ||
@@ -66,4 +67,5 @@ var thresholdCounter_js_1 = require("./thresholdCounter.js"); | ||
Object.defineProperty(exports, "createSampledLogger", { enumerable: true, get: function () { return utils_js_1.createSampledLogger; } }); | ||
Object.defineProperty(exports, "measure", { enumerable: true, get: function () { return utils_js_1.measure; } }); | ||
var telemetryEventBatcher_js_1 = require("./telemetryEventBatcher.js"); | ||
Object.defineProperty(exports, "TelemetryEventBatcher", { enumerable: true, get: function () { return telemetryEventBatcher_js_1.TelemetryEventBatcher; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ /*! | ||
import { type ITelemetryBaseEvent, type ITelemetryBaseLogger, LogLevel } from "@fluidframework/core-interfaces"; | ||
import type { ITelemetryLoggerExt } from "./telemetryTypes.js"; | ||
import type { ITelemetryEventExt, ITelemetryLoggerExt } from "./telemetryTypes.js"; | ||
/** | ||
@@ -79,2 +79,21 @@ * Mock {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} implementation. | ||
} | ||
/** | ||
* Mock {@link ITelemetryLoggerExt} implementation. | ||
* | ||
* @remarks Can be created via {@link createMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export interface IMockLoggerExt extends ITelemetryLoggerExt { | ||
/** | ||
* Gets the events that have been logged so far. | ||
*/ | ||
events(): readonly ITelemetryEventExt[]; | ||
} | ||
/** | ||
* Creates an {@link IMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export declare function createMockLoggerExt(minLogLevel?: LogLevel): IMockLoggerExt; | ||
//# sourceMappingURL=mockLogger.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MockLogger = void 0; | ||
exports.createMockLoggerExt = exports.MockLogger = void 0; | ||
const core_interfaces_1 = require("@fluidframework/core-interfaces"); | ||
@@ -187,2 +187,16 @@ const internal_1 = require("@fluidframework/core-utils/internal"); | ||
} | ||
/** | ||
* Creates an {@link IMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
function createMockLoggerExt(minLogLevel) { | ||
const mockLogger = new MockLogger(minLogLevel); | ||
const childLogger = (0, logger_js_1.createChildLogger)({ logger: mockLogger }); | ||
Object.assign(childLogger, { | ||
events: () => mockLogger.events.map((e) => e), | ||
}); | ||
return childLogger; | ||
} | ||
exports.createMockLoggerExt = createMockLoggerExt; | ||
//# sourceMappingURL=mockLogger.js.map |
@@ -7,17 +7,6 @@ /*! | ||
/** | ||
* Expected type of the custom data passed into the logger. | ||
* @internal | ||
*/ | ||
export interface IMeasuredCodeResult<TKey extends string> { | ||
/** | ||
* Optional properties to log custom data. The set of properties must be the same for all calls to the `measure` function. | ||
*/ | ||
telemetryProperties?: { | ||
readonly [key in TKey]: number; | ||
}; | ||
} | ||
/** | ||
* Telemetry class that measures the execution time of a given piece of code and accumulates user defined telemetry metrics, to finally log an event through the {@link TelemetryEventBatcher.logger | logger} provided to this class when the number of calls to the {@link TelemetryEventBatcher.measure | measure} function reaches the specified by {@link TelemetryEventBatcher.threshold | threshold}. | ||
* Telemetry class that accumulates measurements which are eventually logged in a telemetry event through the provided | ||
* {@link TelemetryEventBatcher.logger | logger} when the number of calls to the function reaches the specified {@link TelemetryEventBatcher.threshold | threshold}. | ||
* | ||
* @remarks It is expected to be used for a single event type. If the set of `telemetryProperties` is different for different events, a separate `TelemetryEventBatcher` should be created for each event type. | ||
* @remarks It is expected to be used for a single event type. If different properties should be logged at different times, a separate `TelemetryEventBatcher` should be created with separate `TMetrics` type. | ||
* @typeparam TMetrics - The set of keys that should be logged. | ||
@@ -43,6 +32,2 @@ * E.g., `keyof Foo` for logging properties `bar` and `baz` from `type Foo = { bar: number, baz: number }`. | ||
/** | ||
* Stores the accumulated duration of the code passed into the logger. | ||
*/ | ||
private accumulatedDuration; | ||
/** | ||
* Stores the sum of the custom data passed into the logger. | ||
@@ -73,10 +58,2 @@ */ | ||
/** | ||
* Executes the specified code, keeping statistics of its execution time and the telemetry properties it returns, and when the {@link TelemetryEventBatcher.threshold} is reached it logs a performance event which includes the maxes and averages. | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @param customData - Custom data to be logged. | ||
* | ||
* @returns Whatever the passed-in code block returns. | ||
*/ | ||
measure<T extends IMeasuredCodeResult<TMetrics>>(codeToMeasure: () => T): T; | ||
/** | ||
* Accumulates the custom data and sends it to the logger every {@link TelemetryEventBatcher.threshold} calls. | ||
@@ -87,5 +64,5 @@ * | ||
*/ | ||
private accumulateAndLog; | ||
accumulateAndLog(customData: Record<TMetrics, number>): void; | ||
private sendData; | ||
} | ||
//# sourceMappingURL=telemetryEventBatcher.d.ts.map |
@@ -8,8 +8,8 @@ "use strict"; | ||
exports.TelemetryEventBatcher = void 0; | ||
const client_utils_1 = require("@fluid-internal/client-utils"); | ||
const mathTools_js_1 = require("./mathTools.js"); | ||
/** | ||
* Telemetry class that measures the execution time of a given piece of code and accumulates user defined telemetry metrics, to finally log an event through the {@link TelemetryEventBatcher.logger | logger} provided to this class when the number of calls to the {@link TelemetryEventBatcher.measure | measure} function reaches the specified by {@link TelemetryEventBatcher.threshold | threshold}. | ||
* Telemetry class that accumulates measurements which are eventually logged in a telemetry event through the provided | ||
* {@link TelemetryEventBatcher.logger | logger} when the number of calls to the function reaches the specified {@link TelemetryEventBatcher.threshold | threshold}. | ||
* | ||
* @remarks It is expected to be used for a single event type. If the set of `telemetryProperties` is different for different events, a separate `TelemetryEventBatcher` should be created for each event type. | ||
* @remarks It is expected to be used for a single event type. If different properties should be logged at different times, a separate `TelemetryEventBatcher` should be created with separate `TMetrics` type. | ||
* @typeparam TMetrics - The set of keys that should be logged. | ||
@@ -39,6 +39,2 @@ * E.g., `keyof Foo` for logging properties `bar` and `baz` from `type Foo = { bar: number, baz: number }`. | ||
/** | ||
* Stores the accumulated duration of the code passed into the logger. | ||
*/ | ||
this.accumulatedDuration = 0; | ||
/** | ||
* Stores the sum of the custom data passed into the logger. | ||
@@ -57,19 +53,2 @@ */ | ||
/** | ||
* Executes the specified code, keeping statistics of its execution time and the telemetry properties it returns, and when the {@link TelemetryEventBatcher.threshold} is reached it logs a performance event which includes the maxes and averages. | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @param customData - Custom data to be logged. | ||
* | ||
* @returns Whatever the passed-in code block returns. | ||
*/ | ||
measure(codeToMeasure) { | ||
const start = client_utils_1.performance.now(); | ||
const returnValue = codeToMeasure(); | ||
const duration = client_utils_1.performance.now() - start; | ||
this.accumulatedDuration += duration; | ||
if (returnValue.telemetryProperties) { | ||
this.accumulateAndLog(returnValue.telemetryProperties); | ||
} | ||
return returnValue; | ||
} | ||
/** | ||
* Accumulates the custom data and sends it to the logger every {@link TelemetryEventBatcher.threshold} calls. | ||
@@ -94,9 +73,8 @@ * | ||
}; | ||
telemetryEvent.duration = this.accumulatedDuration /= this.counter; | ||
for (const key of Object.keys(this.dataSums)) { | ||
if (this.dataSums[key] !== undefined) { | ||
telemetryEvent[`avg${key}`] = (0, mathTools_js_1.roundToDecimalPlaces)(this.dataSums[key] / this.counter, 6); | ||
telemetryEvent[`avg_${key}`] = (0, mathTools_js_1.roundToDecimalPlaces)(this.dataSums[key] / this.counter, 6); | ||
} | ||
if (this.dataMaxes[key] !== undefined) { | ||
telemetryEvent[`max${key}`] = this.dataMaxes[key]; | ||
telemetryEvent[`max_${key}`] = this.dataMaxes[key]; | ||
} | ||
@@ -107,3 +85,2 @@ } | ||
this.counter = 0; | ||
this.accumulatedDuration = 0; | ||
this.dataSums = {}; | ||
@@ -110,0 +87,0 @@ this.dataMaxes = {}; |
@@ -50,2 +50,14 @@ /*! | ||
export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler, skipLoggingWhenSamplingIsDisabled?: boolean): ISampledTelemetryLogger; | ||
/** | ||
* Runs the specified function and returns an object with the time it took to run as well as any output from it. | ||
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}. | ||
* | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @returns The total duration of the code execution and whatever the passed-in code block returns. | ||
* @internal | ||
*/ | ||
export declare function measure<T>(codeToMeasure: () => T): { | ||
duration: number; | ||
output: T; | ||
}; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSampledLogger = void 0; | ||
exports.measure = exports.createSampledLogger = void 0; | ||
const config_js_1 = require("./config.js"); | ||
@@ -71,2 +71,17 @@ /** | ||
exports.createSampledLogger = createSampledLogger; | ||
/** | ||
* Runs the specified function and returns an object with the time it took to run as well as any output from it. | ||
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}. | ||
* | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @returns The total duration of the code execution and whatever the passed-in code block returns. | ||
* @internal | ||
*/ | ||
function measure(codeToMeasure) { | ||
const start = performance.now(); | ||
const output = codeToMeasure(); | ||
const duration = performance.now() - start; | ||
return { duration, output }; | ||
} | ||
exports.measure = measure; | ||
//# sourceMappingURL=utils.js.map |
@@ -12,8 +12,8 @@ /*! | ||
export { eventNamespaceSeparator, createChildLogger, createMultiSinkLogger, formatTick, type IPerformanceEventMarkers, type ITelemetryLoggerPropertyBag, type ITelemetryLoggerPropertyBags, type MultiSinkLoggerProperties, numberFromString, PerformanceEvent, TaggedLoggerAdapter, tagData, tagCodeArtifacts, TelemetryDataTag, type TelemetryEventPropertyTypes, } from "./logger.js"; | ||
export { MockLogger } from "./mockLogger.js"; | ||
export { createMockLoggerExt, type IMockLoggerExt, MockLogger } from "./mockLogger.js"; | ||
export { ThresholdCounter } from "./thresholdCounter.js"; | ||
export { SampledTelemetryHelper } from "./sampledTelemetryHelper.js"; | ||
export { createSampledLogger, type IEventSampler, type ISampledTelemetryLogger } from "./utils.js"; | ||
export { createSampledLogger, type IEventSampler, type ISampledTelemetryLogger, measure, } from "./utils.js"; | ||
export type { TelemetryEventPropertyTypeExt, ITelemetryEventExt, ITelemetryGenericEventExt, ITelemetryErrorEventExt, ITelemetryPerformanceEventExt, ITelemetryLoggerExt, ITaggedTelemetryPropertyTypeExt, ITelemetryPropertiesExt, TelemetryEventCategory, } from "./telemetryTypes.js"; | ||
export { type IMeasuredCodeResult, TelemetryEventBatcher } from "./telemetryEventBatcher.js"; | ||
export { TelemetryEventBatcher } from "./telemetryEventBatcher.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,7 +12,7 @@ /*! | ||
export { eventNamespaceSeparator, createChildLogger, createMultiSinkLogger, formatTick, numberFromString, PerformanceEvent, TaggedLoggerAdapter, tagData, tagCodeArtifacts, TelemetryDataTag, } from "./logger.js"; | ||
export { MockLogger } from "./mockLogger.js"; | ||
export { createMockLoggerExt, MockLogger } from "./mockLogger.js"; | ||
export { ThresholdCounter } from "./thresholdCounter.js"; | ||
export { SampledTelemetryHelper } from "./sampledTelemetryHelper.js"; | ||
export { createSampledLogger } from "./utils.js"; | ||
export { createSampledLogger, measure, } from "./utils.js"; | ||
export { TelemetryEventBatcher } from "./telemetryEventBatcher.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ /*! | ||
import { type ITelemetryBaseEvent, type ITelemetryBaseLogger, LogLevel } from "@fluidframework/core-interfaces"; | ||
import type { ITelemetryLoggerExt } from "./telemetryTypes.js"; | ||
import type { ITelemetryEventExt, ITelemetryLoggerExt } from "./telemetryTypes.js"; | ||
/** | ||
@@ -79,2 +79,21 @@ * Mock {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} implementation. | ||
} | ||
/** | ||
* Mock {@link ITelemetryLoggerExt} implementation. | ||
* | ||
* @remarks Can be created via {@link createMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export interface IMockLoggerExt extends ITelemetryLoggerExt { | ||
/** | ||
* Gets the events that have been logged so far. | ||
*/ | ||
events(): readonly ITelemetryEventExt[]; | ||
} | ||
/** | ||
* Creates an {@link IMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export declare function createMockLoggerExt(minLogLevel?: LogLevel): IMockLoggerExt; | ||
//# sourceMappingURL=mockLogger.d.ts.map |
@@ -182,2 +182,15 @@ /*! | ||
} | ||
/** | ||
* Creates an {@link IMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export function createMockLoggerExt(minLogLevel) { | ||
const mockLogger = new MockLogger(minLogLevel); | ||
const childLogger = createChildLogger({ logger: mockLogger }); | ||
Object.assign(childLogger, { | ||
events: () => mockLogger.events.map((e) => e), | ||
}); | ||
return childLogger; | ||
} | ||
//# sourceMappingURL=mockLogger.js.map |
@@ -7,17 +7,6 @@ /*! | ||
/** | ||
* Expected type of the custom data passed into the logger. | ||
* @internal | ||
*/ | ||
export interface IMeasuredCodeResult<TKey extends string> { | ||
/** | ||
* Optional properties to log custom data. The set of properties must be the same for all calls to the `measure` function. | ||
*/ | ||
telemetryProperties?: { | ||
readonly [key in TKey]: number; | ||
}; | ||
} | ||
/** | ||
* Telemetry class that measures the execution time of a given piece of code and accumulates user defined telemetry metrics, to finally log an event through the {@link TelemetryEventBatcher.logger | logger} provided to this class when the number of calls to the {@link TelemetryEventBatcher.measure | measure} function reaches the specified by {@link TelemetryEventBatcher.threshold | threshold}. | ||
* Telemetry class that accumulates measurements which are eventually logged in a telemetry event through the provided | ||
* {@link TelemetryEventBatcher.logger | logger} when the number of calls to the function reaches the specified {@link TelemetryEventBatcher.threshold | threshold}. | ||
* | ||
* @remarks It is expected to be used for a single event type. If the set of `telemetryProperties` is different for different events, a separate `TelemetryEventBatcher` should be created for each event type. | ||
* @remarks It is expected to be used for a single event type. If different properties should be logged at different times, a separate `TelemetryEventBatcher` should be created with separate `TMetrics` type. | ||
* @typeparam TMetrics - The set of keys that should be logged. | ||
@@ -43,6 +32,2 @@ * E.g., `keyof Foo` for logging properties `bar` and `baz` from `type Foo = { bar: number, baz: number }`. | ||
/** | ||
* Stores the accumulated duration of the code passed into the logger. | ||
*/ | ||
private accumulatedDuration; | ||
/** | ||
* Stores the sum of the custom data passed into the logger. | ||
@@ -73,10 +58,2 @@ */ | ||
/** | ||
* Executes the specified code, keeping statistics of its execution time and the telemetry properties it returns, and when the {@link TelemetryEventBatcher.threshold} is reached it logs a performance event which includes the maxes and averages. | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @param customData - Custom data to be logged. | ||
* | ||
* @returns Whatever the passed-in code block returns. | ||
*/ | ||
measure<T extends IMeasuredCodeResult<TMetrics>>(codeToMeasure: () => T): T; | ||
/** | ||
* Accumulates the custom data and sends it to the logger every {@link TelemetryEventBatcher.threshold} calls. | ||
@@ -87,5 +64,5 @@ * | ||
*/ | ||
private accumulateAndLog; | ||
accumulateAndLog(customData: Record<TMetrics, number>): void; | ||
private sendData; | ||
} | ||
//# sourceMappingURL=telemetryEventBatcher.d.ts.map |
@@ -5,8 +5,8 @@ /*! | ||
*/ | ||
import { performance } from "@fluid-internal/client-utils"; | ||
import { roundToDecimalPlaces } from "./mathTools.js"; | ||
/** | ||
* Telemetry class that measures the execution time of a given piece of code and accumulates user defined telemetry metrics, to finally log an event through the {@link TelemetryEventBatcher.logger | logger} provided to this class when the number of calls to the {@link TelemetryEventBatcher.measure | measure} function reaches the specified by {@link TelemetryEventBatcher.threshold | threshold}. | ||
* Telemetry class that accumulates measurements which are eventually logged in a telemetry event through the provided | ||
* {@link TelemetryEventBatcher.logger | logger} when the number of calls to the function reaches the specified {@link TelemetryEventBatcher.threshold | threshold}. | ||
* | ||
* @remarks It is expected to be used for a single event type. If the set of `telemetryProperties` is different for different events, a separate `TelemetryEventBatcher` should be created for each event type. | ||
* @remarks It is expected to be used for a single event type. If different properties should be logged at different times, a separate `TelemetryEventBatcher` should be created with separate `TMetrics` type. | ||
* @typeparam TMetrics - The set of keys that should be logged. | ||
@@ -36,6 +36,2 @@ * E.g., `keyof Foo` for logging properties `bar` and `baz` from `type Foo = { bar: number, baz: number }`. | ||
/** | ||
* Stores the accumulated duration of the code passed into the logger. | ||
*/ | ||
this.accumulatedDuration = 0; | ||
/** | ||
* Stores the sum of the custom data passed into the logger. | ||
@@ -54,19 +50,2 @@ */ | ||
/** | ||
* Executes the specified code, keeping statistics of its execution time and the telemetry properties it returns, and when the {@link TelemetryEventBatcher.threshold} is reached it logs a performance event which includes the maxes and averages. | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @param customData - Custom data to be logged. | ||
* | ||
* @returns Whatever the passed-in code block returns. | ||
*/ | ||
measure(codeToMeasure) { | ||
const start = performance.now(); | ||
const returnValue = codeToMeasure(); | ||
const duration = performance.now() - start; | ||
this.accumulatedDuration += duration; | ||
if (returnValue.telemetryProperties) { | ||
this.accumulateAndLog(returnValue.telemetryProperties); | ||
} | ||
return returnValue; | ||
} | ||
/** | ||
* Accumulates the custom data and sends it to the logger every {@link TelemetryEventBatcher.threshold} calls. | ||
@@ -91,9 +70,8 @@ * | ||
}; | ||
telemetryEvent.duration = this.accumulatedDuration /= this.counter; | ||
for (const key of Object.keys(this.dataSums)) { | ||
if (this.dataSums[key] !== undefined) { | ||
telemetryEvent[`avg${key}`] = roundToDecimalPlaces(this.dataSums[key] / this.counter, 6); | ||
telemetryEvent[`avg_${key}`] = roundToDecimalPlaces(this.dataSums[key] / this.counter, 6); | ||
} | ||
if (this.dataMaxes[key] !== undefined) { | ||
telemetryEvent[`max${key}`] = this.dataMaxes[key]; | ||
telemetryEvent[`max_${key}`] = this.dataMaxes[key]; | ||
} | ||
@@ -104,3 +82,2 @@ } | ||
this.counter = 0; | ||
this.accumulatedDuration = 0; | ||
this.dataSums = {}; | ||
@@ -107,0 +84,0 @@ this.dataMaxes = {}; |
@@ -50,2 +50,14 @@ /*! | ||
export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler, skipLoggingWhenSamplingIsDisabled?: boolean): ISampledTelemetryLogger; | ||
/** | ||
* Runs the specified function and returns an object with the time it took to run as well as any output from it. | ||
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}. | ||
* | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @returns The total duration of the code execution and whatever the passed-in code block returns. | ||
* @internal | ||
*/ | ||
export declare function measure<T>(codeToMeasure: () => T): { | ||
duration: number; | ||
output: T; | ||
}; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -66,2 +66,16 @@ /*! | ||
} | ||
/** | ||
* Runs the specified function and returns an object with the time it took to run as well as any output from it. | ||
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}. | ||
* | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @returns The total duration of the code execution and whatever the passed-in code block returns. | ||
* @internal | ||
*/ | ||
export function measure(codeToMeasure) { | ||
const start = performance.now(); | ||
const output = codeToMeasure(); | ||
const duration = performance.now() - start; | ||
return { duration, output }; | ||
} | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@fluidframework/telemetry-utils", | ||
"version": "2.0.0-dev-rc.5.0.0.272251", | ||
"version": "2.0.0-dev-rc.5.0.0.272889", | ||
"description": "Collection of telemetry relates utilities for Fluid", | ||
@@ -70,6 +70,6 @@ "homepage": "https://fluidframework.com", | ||
"dependencies": { | ||
"@fluid-internal/client-utils": "2.0.0-dev-rc.5.0.0.272251", | ||
"@fluidframework/core-interfaces": "2.0.0-dev-rc.5.0.0.272251", | ||
"@fluidframework/core-utils": "2.0.0-dev-rc.5.0.0.272251", | ||
"@fluidframework/driver-definitions": "2.0.0-dev-rc.5.0.0.272251", | ||
"@fluid-internal/client-utils": "2.0.0-dev-rc.5.0.0.272889", | ||
"@fluidframework/core-interfaces": "2.0.0-dev-rc.5.0.0.272889", | ||
"@fluidframework/core-utils": "2.0.0-dev-rc.5.0.0.272889", | ||
"@fluidframework/driver-definitions": "2.0.0-dev-rc.5.0.0.272889", | ||
"debug": "^4.3.4", | ||
@@ -81,3 +81,3 @@ "uuid": "^9.0.0" | ||
"@biomejs/biome": "^1.7.3", | ||
"@fluid-internal/mocha-test-setup": "2.0.0-dev-rc.5.0.0.272251", | ||
"@fluid-internal/mocha-test-setup": "2.0.0-dev-rc.5.0.0.272889", | ||
"@fluid-tools/build-cli": "^0.39.0", | ||
@@ -140,3 +140,3 @@ "@fluidframework/build-common": "^2.0.3", | ||
"check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json", | ||
"check:format": "npm run check:prettier", | ||
"check:format": "npm run check:biome", | ||
"check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore", | ||
@@ -147,3 +147,3 @@ "ci:build:docs": "api-extractor run", | ||
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout", | ||
"format": "npm run format:prettier", | ||
"format": "npm run format:biome", | ||
"format:biome": "biome check . --formatter-enabled=true --apply", | ||
@@ -150,0 +150,0 @@ "format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore", |
@@ -282,5 +282,5 @@ /*! | ||
*/ | ||
export function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>( | ||
obj: L, | ||
): obj is L & MonitoringContext<L> { | ||
export function loggerIsMonitoringContext< | ||
L extends ITelemetryBaseLogger = ITelemetryLoggerExt, | ||
>(obj: L): obj is L & MonitoringContext<L> { | ||
const maybeConfig = obj as Partial<MonitoringContext<L>> | undefined; | ||
@@ -295,5 +295,5 @@ return isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined; | ||
*/ | ||
export function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>( | ||
logger: L, | ||
): MonitoringContext<L> { | ||
export function loggerToMonitoringContext< | ||
L extends ITelemetryBaseLogger = ITelemetryLoggerExt, | ||
>(logger: L): MonitoringContext<L> { | ||
if (loggerIsMonitoringContext<L>(logger)) { | ||
@@ -300,0 +300,0 @@ return logger; |
@@ -165,3 +165,3 @@ /*! | ||
// errorRunningExternalCode: 1, | ||
}; | ||
}; | ||
@@ -230,3 +230,6 @@ fluidError.addTelemetryProperties({ | ||
): T { | ||
const { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */); | ||
const { message, stack } = extractLogSafeErrorProperties( | ||
innerError, | ||
false /* sanitizeStack */, | ||
); | ||
@@ -233,0 +236,0 @@ const newError = newErrorFn(message); |
@@ -64,6 +64,11 @@ /*! | ||
} from "./logger.js"; | ||
export { MockLogger } from "./mockLogger.js"; | ||
export { createMockLoggerExt, type IMockLoggerExt, MockLogger } from "./mockLogger.js"; | ||
export { ThresholdCounter } from "./thresholdCounter.js"; | ||
export { SampledTelemetryHelper } from "./sampledTelemetryHelper.js"; | ||
export { createSampledLogger, type IEventSampler, type ISampledTelemetryLogger } from "./utils.js"; | ||
export { | ||
createSampledLogger, | ||
type IEventSampler, | ||
type ISampledTelemetryLogger, | ||
measure, | ||
} from "./utils.js"; | ||
export type { | ||
@@ -80,2 +85,2 @@ TelemetryEventPropertyTypeExt, | ||
} from "./telemetryTypes.js"; | ||
export { type IMeasuredCodeResult, TelemetryEventBatcher } from "./telemetryEventBatcher.js"; | ||
export { TelemetryEventBatcher } from "./telemetryEventBatcher.js"; |
@@ -277,6 +277,5 @@ /*! | ||
private extendProperties<T extends ITelemetryLoggerPropertyBag = ITelemetryLoggerPropertyBag>( | ||
toExtend: T, | ||
includeErrorProps: boolean, | ||
): T { | ||
private extendProperties< | ||
T extends ITelemetryLoggerPropertyBag = ITelemetryLoggerPropertyBag, | ||
>(toExtend: T, includeErrorProps: boolean): T { | ||
const eventLike: ITelemetryLoggerPropertyBag = toExtend; | ||
@@ -426,4 +425,4 @@ if (this.properties) { | ||
: namespace === undefined | ||
? baseLogger.namespace | ||
: `${baseLogger.namespace}${TelemetryLogger.eventNamespaceSeparator}${namespace}`; | ||
? baseLogger.namespace | ||
: `${baseLogger.namespace}${TelemetryLogger.eventNamespaceSeparator}${namespace}`; | ||
@@ -861,3 +860,3 @@ const child = new ChildLogger( | ||
tag: x.tag, | ||
} | ||
} | ||
: convertToBasePropertyTypeUntagged(x); | ||
@@ -927,7 +926,7 @@ } | ||
tag: T; | ||
} | ||
} | ||
: { | ||
value: Exclude<V[P], undefined>; | ||
tag: T; | ||
}) | ||
}) | ||
| (V[P] extends undefined ? undefined : never); | ||
@@ -990,8 +989,8 @@ } => | ||
tag: TelemetryDataTag.CodeArtifact; | ||
} | ||
} | ||
: { | ||
value: Exclude<T[P], undefined>; | ||
tag: TelemetryDataTag.CodeArtifact; | ||
}) | ||
}) | ||
| (T[P] extends undefined ? undefined : never); | ||
} => tagData<TelemetryDataTag.CodeArtifact, T>(TelemetryDataTag.CodeArtifact, values); |
@@ -14,3 +14,7 @@ /*! | ||
import { createChildLogger } from "./logger.js"; | ||
import type { ITelemetryLoggerExt, ITelemetryPropertiesExt } from "./telemetryTypes.js"; | ||
import type { | ||
ITelemetryEventExt, | ||
ITelemetryLoggerExt, | ||
ITelemetryPropertiesExt, | ||
} from "./telemetryTypes.js"; | ||
@@ -238,3 +242,6 @@ /** | ||
function matchObjects(actual: ITelemetryPropertiesExt, expected: ITelemetryPropertiesExt): boolean { | ||
function matchObjects( | ||
actual: ITelemetryPropertiesExt, | ||
expected: ITelemetryPropertiesExt, | ||
): boolean { | ||
for (const [expectedKey, expectedValue] of Object.entries(expected)) { | ||
@@ -264,1 +271,30 @@ const actualValue = actual[expectedKey]; | ||
} | ||
/** | ||
* Mock {@link ITelemetryLoggerExt} implementation. | ||
* | ||
* @remarks Can be created via {@link createMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export interface IMockLoggerExt extends ITelemetryLoggerExt { | ||
/** | ||
* Gets the events that have been logged so far. | ||
*/ | ||
events(): readonly ITelemetryEventExt[]; | ||
} | ||
/** | ||
* Creates an {@link IMockLoggerExt}. | ||
* | ||
* @internal | ||
*/ | ||
export function createMockLoggerExt(minLogLevel?: LogLevel): IMockLoggerExt { | ||
const mockLogger = new MockLogger(minLogLevel); | ||
const childLogger = createChildLogger({ logger: mockLogger }); | ||
Object.assign(childLogger, { | ||
events: (): readonly ITelemetryEventExt[] => | ||
mockLogger.events.map((e) => e as ITelemetryEventExt), | ||
}); | ||
return childLogger as IMockLoggerExt; | ||
} |
@@ -6,4 +6,2 @@ /*! | ||
import { performance } from "@fluid-internal/client-utils"; | ||
import { roundToDecimalPlaces } from "./mathTools.js"; | ||
@@ -17,16 +15,6 @@ import type { | ||
/** | ||
* Expected type of the custom data passed into the logger. | ||
* @internal | ||
*/ | ||
export interface IMeasuredCodeResult<TKey extends string> { | ||
/** | ||
* Optional properties to log custom data. The set of properties must be the same for all calls to the `measure` function. | ||
*/ | ||
telemetryProperties?: { readonly [key in TKey]: number }; | ||
} | ||
/** | ||
* Telemetry class that measures the execution time of a given piece of code and accumulates user defined telemetry metrics, to finally log an event through the {@link TelemetryEventBatcher.logger | logger} provided to this class when the number of calls to the {@link TelemetryEventBatcher.measure | measure} function reaches the specified by {@link TelemetryEventBatcher.threshold | threshold}. | ||
* Telemetry class that accumulates measurements which are eventually logged in a telemetry event through the provided | ||
* {@link TelemetryEventBatcher.logger | logger} when the number of calls to the function reaches the specified {@link TelemetryEventBatcher.threshold | threshold}. | ||
* | ||
* @remarks It is expected to be used for a single event type. If the set of `telemetryProperties` is different for different events, a separate `TelemetryEventBatcher` should be created for each event type. | ||
* @remarks It is expected to be used for a single event type. If different properties should be logged at different times, a separate `TelemetryEventBatcher` should be created with separate `TMetrics` type. | ||
* @typeparam TMetrics - The set of keys that should be logged. | ||
@@ -40,7 +28,2 @@ * E.g., `keyof Foo` for logging properties `bar` and `baz` from `type Foo = { bar: number, baz: number }`. | ||
/** | ||
* Stores the accumulated duration of the code passed into the logger. | ||
*/ | ||
private accumulatedDuration: number = 0; | ||
/** | ||
* Stores the sum of the custom data passed into the logger. | ||
@@ -78,23 +61,2 @@ */ | ||
/** | ||
* Executes the specified code, keeping statistics of its execution time and the telemetry properties it returns, and when the {@link TelemetryEventBatcher.threshold} is reached it logs a performance event which includes the maxes and averages. | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @param customData - Custom data to be logged. | ||
* | ||
* @returns Whatever the passed-in code block returns. | ||
*/ | ||
public measure<T extends IMeasuredCodeResult<TMetrics>>(codeToMeasure: () => T): T { | ||
const start = performance.now(); | ||
const returnValue = codeToMeasure(); | ||
const duration = performance.now() - start; | ||
this.accumulatedDuration += duration; | ||
if (returnValue.telemetryProperties) { | ||
this.accumulateAndLog(returnValue.telemetryProperties); | ||
} | ||
return returnValue; | ||
} | ||
/** | ||
* Accumulates the custom data and sends it to the logger every {@link TelemetryEventBatcher.threshold} calls. | ||
@@ -105,3 +67,3 @@ * | ||
*/ | ||
private accumulateAndLog(customData: Record<TMetrics, number>): void { | ||
public accumulateAndLog(customData: Record<TMetrics, number>): void { | ||
for (const key of Object.keys(customData) as TMetrics[]) { | ||
@@ -127,7 +89,5 @@ this.dataSums[key] = (this.dataSums[key] ?? 0) + customData[key]; | ||
telemetryEvent.duration = this.accumulatedDuration /= this.counter; | ||
for (const key of Object.keys(this.dataSums) as TMetrics[]) { | ||
if (this.dataSums[key] !== undefined) { | ||
telemetryEvent[`avg${key}`] = roundToDecimalPlaces( | ||
telemetryEvent[`avg_${key}`] = roundToDecimalPlaces( | ||
this.dataSums[key]! / this.counter, | ||
@@ -138,3 +98,3 @@ 6, | ||
if (this.dataMaxes[key] !== undefined) { | ||
telemetryEvent[`max${key}`] = this.dataMaxes[key]; | ||
telemetryEvent[`max_${key}`] = this.dataMaxes[key]; | ||
} | ||
@@ -147,3 +107,2 @@ } | ||
this.counter = 0; | ||
this.accumulatedDuration = 0; | ||
this.dataSums = {}; | ||
@@ -150,0 +109,0 @@ this.dataMaxes = {}; |
@@ -107,1 +107,16 @@ /*! | ||
} | ||
/** | ||
* Runs the specified function and returns an object with the time it took to run as well as any output from it. | ||
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}. | ||
* | ||
* @param codeToMeasure - The code to be executed and measured. | ||
* @returns The total duration of the code execution and whatever the passed-in code block returns. | ||
* @internal | ||
*/ | ||
export function measure<T>(codeToMeasure: () => T): { duration: number; output: T } { | ||
const start = performance.now(); | ||
const output = codeToMeasure(); | ||
const duration = performance.now() - start; | ||
return { duration, output }; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10305
811760
+ Added@fluid-internal/client-utils@2.0.0-dev-rc.5.0.0.272889(transitive)
+ Added@fluidframework/core-interfaces@2.0.0-dev-rc.5.0.0.272889(transitive)
+ Added@fluidframework/core-utils@2.0.0-dev-rc.5.0.0.272889(transitive)
+ Added@fluidframework/driver-definitions@2.0.0-dev-rc.5.0.0.272889(transitive)
- Removed@fluid-internal/client-utils@2.0.0-dev-rc.5.0.0.272251(transitive)
- Removed@fluidframework/core-interfaces@2.0.0-dev-rc.5.0.0.272251(transitive)
- Removed@fluidframework/core-utils@2.0.0-dev-rc.5.0.0.272251(transitive)
- Removed@fluidframework/driver-definitions@2.0.0-dev-rc.5.0.0.272251(transitive)
Updated@fluid-internal/client-utils@2.0.0-dev-rc.5.0.0.272889
Updated@fluidframework/core-interfaces@2.0.0-dev-rc.5.0.0.272889
Updated@fluidframework/driver-definitions@2.0.0-dev-rc.5.0.0.272889