Skip to content

send eligibility data to host to log telemetry #2650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/teams-test-app/src/components/AppAPIs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ const ProcessActionSubmitForCEA = (): React.ReactElement =>
}
},
submit: async (input) => {
console.log(`Potential app id (${input.appId}) prints like this`);
const objectAppId = new AppId(input.appId);
console.log(`objectAppId app id (${objectAppId}) prints like this`);

await externalAppCardActionsForCEA.processActionSubmit(
new AppId(input.appId),
new AppId(objectAppId as unknown as string),

input.conversationId,
input.actionSubmitPayload,
);
Expand Down
3 changes: 3 additions & 0 deletions packages/teams-js/src/internal/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as validOriginsJSON from '../artifactsForCDN/validDomains.json';
import { ApiName } from './telemetry';

/**
* @hidden
Expand Down Expand Up @@ -177,3 +178,5 @@ export const errorRuntimeNotSupported = 'The runtime version is not supported';

/** @hidden */
export const errorCallNotStarted = 'The call was not properly started';

export const reportTelemetryBackToHost = [ApiName.Copilot_Eligibility_GetEligibilityInfo];
27 changes: 26 additions & 1 deletion packages/teams-js/src/internal/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ 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 { reportTelemetryBackToHost } from './constants';
import { ensureInitialized } from './internalAPIs';
import { getLogger } from './telemetry';
import { isNullOrUndefined } from './typeCheckUtilities';
Expand Down Expand Up @@ -198,12 +199,36 @@ export function registerHostToAppPerformanceMetricsHandler(
* Limited to Microsoft-internal use
*/
export function handleHostToAppPerformanceMetrics(metrics: HostToAppPerformanceMetrics): void {
console.log('NOW IT WILL CHECK WHETHER THE HANDLER IS REGISTERED OR NOT --> ' + metrics.actionName);
// 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
shouldSendTelemetryBack(metrics.actionName as ApiName) &&
callFunctionInHost(
'reportTelemetryEvent',
[metrics.actionName, metrics.actionId, metrics.messageDelay, metrics.requestStartedAt],
'v3_reportTelemetryEvent',
);

if (!HandlersPrivate.hostToAppPerformanceMetricsHandler) {
return;
}
HandlersPrivate.hostToAppPerformanceMetricsHandler(metrics);
}

/**
* @internal
* Limited to Microsoft-internal use
*
* @hidden
*/
function shouldSendTelemetryBack(actionName: ApiName): boolean {
console.log('NOW IT WILL CHECK the action name --> ' + actionName);
console.log(
'NOW IT WILL decide whether to post it back to hub sdk --> ' + reportTelemetryBackToHost.includes(actionName),
);
return reportTelemetryBackToHost.includes(actionName);
}
/**
* @internal
* Limited to Microsoft-internal use
Expand Down
5 changes: 5 additions & 0 deletions packages/teams-js/src/internal/hostToAppTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class HostToAppMessageDelayTelemetry {
}
handleHostToAppPerformanceMetrics({
actionName: message.func,
actionId: message.uuid?.toString() || 'theUuidOfMessageIsNotAvailable',
messageDelay: endTime - timestamp,
requestStartedAt: timestamp,
});
Expand Down Expand Up @@ -86,8 +87,12 @@ 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,
actionId: callbackID.toString(),
messageDelay: endTime - message.monotonicTimestamp,
requestStartedAt: callbackInformation.calledAt,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ export interface ClipboardParams {
export interface HostToAppPerformanceMetrics {
/** The name of the action the host is responding to. */
actionName: string;
/** The Id of the message from what the response was received */
actionId: string;
/** The delay the message took traveling from host to app */
messageDelay: number;
/** The time when the request was dispatched */
Expand Down
Loading