Skip to content

Add vercel.functions.metric() - #273

Open
tobiaslins wants to merge 1 commit into
mainfrom
agent/python-functions-metric
Open

Add vercel.functions.metric()#273
tobiaslins wants to merge 1 commit into
mainfrom
agent/python-functions-metric

Conversation

@tobiaslins

@tobiaslins tobiaslins commented Aug 10, 2026

Copy link
Copy Markdown

Summary

  • add vercel.functions.metric(name, value, tags=None)
  • add the invocation-context callback used by the Vercel Python runtime
  • safely no-op when no compatible runtime invocation is active

Why

This gives Python Functions the same custom metric helper as @vercel/functions, while keeping transport details owned by the runtime. Documentation is intentionally omitted during the soft launch.

This PR pairs with the Python runtime IPC change in https://github.com/vercel/vercel-internal/pull/178.

Validation

  • uv run --no-sync poe test vercel vercel-cache (1062 passed, 27 credential-gated tests skipped)
  • uv run --no-sync poe lint vercel vercel-cache
  • uv run poe typecheck vercel vercel-cache
  • focused metric/context tests (13 passed)

The required vercel feature and vercel-cache internal news fragments are included. The local check-news-fragments command could not run because uv 0.11.2 removed the workspace metadata --locked option still used by the repository script.

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vercel-py Ready Ready Preview Aug 10, 2026 9:16am

Request Review

@tobiaslins
tobiaslins marked this pull request as ready for review August 10, 2026 09:46
_cv_wait_until: ContextVar[Callable[[Awaitable[object]], None] | None] = ContextVar(
"vercel_wait_until", default=None
)
_cv_metric: ContextVar[_MetricCallback | None] = ContextVar("vercel_metric", default=None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an odd location for this. vercel/functions would be more appropriate. Also, ContextVar is probably not the right vehicle because the callback does not change between requests, so it should just be a global.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, I would reverse this. Instead of the runtime patching the SDK, the SDK should detect the presence of the runtime and call runtime callbacks.

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.

2 participants