Skip to content
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

Update messaging for measuring message delay between App and Hub #2499

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

juanscr
Copy link
Contributor

@juanscr juanscr commented Sep 5, 2024

Description

This pull request has two purposes:

  1. Fix the way the message request is timestamped by using a monotonic timer instead of the Date as it could be subject to user clock skew.
  2. Add a mechanism for app developers to access Host to App message delay to analyze how much the message travel time impacts the latency of each function call or initialization.

For the second purpose, with this PR, an app developer can register a function that receives the message delays per function call as soon as a response is received from the host so they can log it or store it in their own telemetry. As app developers do not have information about the internal message IDs, the handler gets passed information about the callback that is resolving so they can approximately pinpoint which call had that message delay.

Note: it was decided to not expose message IDs as it is a really big architectural change in the codebase and the value of exposing them to app developers would be really small in comparison to the change.

Main changes in the PR:

  1. Change the timestamp on all message requests from Date.now() to use performance.now() + performance.timeOrigin.
  2. Add a function to register a handler that will be called each time a response is received from the host with information about the message delay.

Validation

Validation performed:

  1. Ran all the unit tests and passed them successfully.
  2. Execute the build and see that all test apps properly build.
  3. Create a test app with a registered handler and log the values that were being received.

Unit Tests added:

Yes

End-to-end tests added:

No

Additional Requirements

Change file added:

Yes

Next/remaining steps:

A following PR in the host SDK will be done in order to properly measure the App to Host message delay with the changes added in this pull request.

@juanscr juanscr requested a review from a team as a code owner September 5, 2024 03:39
packages/teams-js/src/public/app.ts Outdated Show resolved Hide resolved
packages/teams-js/src/internal/interfaces.ts Show resolved Hide resolved
packages/teams-js/src/internal/communication.ts Outdated Show resolved Hide resolved
@juanscr juanscr force-pushed the juancard/messageDelay branch 2 times, most recently from 61059e3 to fe1cd61 Compare September 11, 2024 00:41
packages/teams-js/src/internal/utils.ts Show resolved Hide resolved
packages/teams-js/src/internal/telemetry.ts Outdated Show resolved Hide resolved
packages/teams-js/src/internal/telemetry.ts Outdated Show resolved Hide resolved
if (callbackInformation && message.timestamp) {
handleHostToAppPerformanceMetrics({
actionName: callbackInformation.name,
messageDelay: getCurrentTimestamp() - message.timestamp,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from you local testing, can you please add some data points for values recorded both for two-way and one-way messages

With this new timestamped messaged, the host can properly compare
and evaluate how much time the request got delayed to an issue on a
busy event loop.
This new handler will allow any application developer to register
a function for analyzing or storing performance metrics related to
latencies due to a message delay sending the response back from the
host to the app.
The old field will be preserved with backwards compatibility
with previous versions that still consume this field.
All the telemetry related code is added to the telemetry module to
avoid cluttering the communication layer with nuances about
telemetry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants