From 498d3d2e749ba582e1e2859634783e5f0d1129d2 Mon Sep 17 00:00:00 2001 From: Lakhveer Kaur Date: Tue, 3 Dec 2024 11:48:31 -0800 Subject: [PATCH] send eleigibility data to hubsdk to log telemetry --- apps/teams-test-app/src/components/AppAPIs.tsx | 1 + packages/teams-js/src/internal/handlers.ts | 13 ++++++++++++- .../teams-js/src/internal/hostToAppTelemetry.ts | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/teams-test-app/src/components/AppAPIs.tsx b/apps/teams-test-app/src/components/AppAPIs.tsx index c7da2095ed..4b0c411ebb 100644 --- a/apps/teams-test-app/src/components/AppAPIs.tsx +++ b/apps/teams-test-app/src/components/AppAPIs.tsx @@ -20,6 +20,7 @@ const GetContext = (): ReactElement => onClick: { withPromise: async () => { const context = await app.getContext(); + console.log('This is the context: ' + context); return JSON.stringify(context); }, withCallback: (setResult) => { diff --git a/packages/teams-js/src/internal/handlers.ts b/packages/teams-js/src/internal/handlers.ts index 2613d474a6..344eb7db7e 100644 --- a/packages/teams-js/src/internal/handlers.ts +++ b/packages/teams-js/src/internal/handlers.ts @@ -5,7 +5,7 @@ import { FrameContexts } from '../public/constants'; import { HostToAppPerformanceMetrics, LoadContext, ResumeContext } from '../public/interfaces'; import * as pages from '../public/pages/pages'; import { runtime } from '../public/runtime'; -import { Communication, sendMessageEventToChild, sendMessageToParent } from './communication'; +import { callFunctionInHost, Communication, sendMessageEventToChild, sendMessageToParent } from './communication'; import { ensureInitialized } from './internalAPIs'; import { getLogger } from './telemetry'; import { isNullOrUndefined } from './typeCheckUtilities'; @@ -198,9 +198,20 @@ export function registerHostToAppPerformanceMetricsHandler( * Limited to Microsoft-internal use */ export function handleHostToAppPerformanceMetrics(metrics: HostToAppPerformanceMetrics): void { + console.log('NOW IT WILL CHEKCK WHETHER THE HANDLER IS REGISTERED OR NOT'); + // post the metrics to the parent window without using async/await. That will make sure the metric is posted asynchronously, + // and does not stop the response to go to the calling app. + // IF we don't want to post back everything, we can add a check here to see if the API name is copilot.eligibility + callFunctionInHost( + 'reportTelemetryEvent', + [metrics.actionName, metrics.messageDelay, metrics.requestStartedAt], + 'v3_reportTelemetryEvent', + ); if (!HandlersPrivate.hostToAppPerformanceMetricsHandler) { + console.log('not registered'); return; } + console.log('registered'); HandlersPrivate.hostToAppPerformanceMetricsHandler(metrics); } diff --git a/packages/teams-js/src/internal/hostToAppTelemetry.ts b/packages/teams-js/src/internal/hostToAppTelemetry.ts index 80d58d2d40..e701b7eed2 100644 --- a/packages/teams-js/src/internal/hostToAppTelemetry.ts +++ b/packages/teams-js/src/internal/hostToAppTelemetry.ts @@ -86,6 +86,9 @@ export default class HostToAppMessageDelayTelemetry { ); return; } + console.log('callbackInformation', callbackInformation); + console.log('message', message); + //the api call should always reach here regardless the handler is registered or not handleHostToAppPerformanceMetrics({ actionName: callbackInformation.name, messageDelay: endTime - message.monotonicTimestamp,