Skip to content

Adds metrics function to return analytics about performance #78608

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

Open
wants to merge 3 commits into
base: canary
Choose a base branch
from

Conversation

tony13tv
Copy link

@tony13tv tony13tv commented Apr 28, 2025

What?
Adds a metrics function to "next/server", in the style of headers, to set arbitrary metrics adhering to the server timing spec.

Why?
I wanted to return metrics about the time consumed on each query executed on server actions.

How?
Added a serverTimingAsyncStorage which will wrap the execution of the server action, then inside the server action you can do:

import { metrics } from "next/server";
export async function getData() {
  const m = metrics();
  const time = performance.now();
  const users = await db.getUsers();
  m.set("db", {dur: performance.now() - time, desc: "getUsers"});
  return users;
}

@ijjk
Copy link
Member

ijjk commented Apr 28, 2025

Allow CI Workflow Run

  • approve CI run for commit: e4daad0

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ijjk
Copy link
Member

ijjk commented Apr 28, 2025

Allow CI Workflow Run

  • approve CI run for commit: b5471cf

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@tony13tv
Copy link
Author

Probably related #62353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants