From 77965571accf18dd1a1c547d29c54de1ce9b0bff Mon Sep 17 00:00:00 2001 From: clarenceli-msft <86381878+clarenceli-msft@users.noreply.github.com> Date: Fri, 21 Apr 2023 18:19:04 -0400 Subject: [PATCH] Add telemetry to mixinattributor (#15033) [AB#3574](https://dev.azure.com/fluidframework/internal/_workitems/edit/3547) --- .../attributor/src/mixinAttributor.ts | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/framework/attributor/src/mixinAttributor.ts b/packages/framework/attributor/src/mixinAttributor.ts index 31f8b70dd45f..fb6e3e8b6767 100644 --- a/packages/framework/attributor/src/mixinAttributor.ts +++ b/packages/framework/attributor/src/mixinAttributor.ts @@ -22,7 +22,11 @@ import { IContainerRuntime } from "@fluidframework/container-runtime-definitions import { IRequest, IResponse, FluidObject } from "@fluidframework/core-interfaces"; import { assert, bufferToString, unreachableCase } from "@fluidframework/common-utils"; import { UsageError } from "@fluidframework/container-utils"; -import { loggerToMonitoringContext } from "@fluidframework/telemetry-utils"; +import { + ChildLogger, + PerformanceEvent, + loggerToMonitoringContext, +} from "@fluidframework/telemetry-utils"; import { Attributor, IAttributor, OpStreamAttributor } from "./attributor"; import { AttributorSerializer, chain, deltaEncoder, Encoder } from "./encoders"; import { makeLZ4Encoder } from "./lz4Encoder"; @@ -131,6 +135,7 @@ export const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime ); const mc = loggerToMonitoringContext(context.taggedLogger); + const shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false; if (shouldTrackAttribution) { (context.options.attribution ??= {}).track = true; @@ -147,17 +152,34 @@ export const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime )) as ContainerRuntimeWithAttributor; runtime.runtimeAttributor = runtimeAttributor as RuntimeAttributor; + const logger = ChildLogger.create(runtime.logger, "Attributor"); + // Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize // this to avoid blocking on such information until application actually requests some op-based attribution // info or we need to summarize. All that really needs to happen immediately is to start recording // op seq# -> attributionInfo for new ops. - await runtime.runtimeAttributor.initialize( - deltaManager, - audience, - baseSnapshot, - async (id) => runtime.storage.readBlob(id), - shouldTrackAttribution, + await PerformanceEvent.timedExecAsync( + logger, + { + eventName: "initialize", + }, + async (event) => { + void runtime.runtimeAttributor?.initialize( + deltaManager, + audience, + baseSnapshot, + async (id) => runtime.storage.readBlob(id), + shouldTrackAttribution, + ); + event.end({ + attributionEnabledInConfig: shouldTrackAttribution, + attributionEnabledInDoc: runtime.runtimeAttributor + ? runtime.runtimeAttributor.isEnabled + : false, + }); + }, ); + return runtime; }