vercel/vercel-plugin

custom-metrics

Emit and query Vercel Custom Metrics.

Vedi sorgente

Come usare

  1. Copia il comando e controlla il pacchetto prima di installarlo nel tuo ambiente agente.
  2. Controlla strumenti, credenziali e ambienti richiesti nel documento originale.
  3. Descrivi input e risultato desiderato; confronta l’output con le fonti.
npx skills add https://github.com/vercel/vercel-plugin --skill custom-metrics

Prima di iniziare

  • L’installazione non include abbonamenti, quote API o accesso ai file.
  • Stelle e installazioni indicano attività, non un test indipendente di qualità o sicurezza.
Documento Skill originale

Contenuto dal repository con titoli, esempi, codice, tabelle, link e immagini preservati.

Vercel Custom Metrics

Use Custom Metrics for numeric application and business measurements emitted by server-side code running in a Vercel Function. The workflow is emit a numeric sample with `metric()` → invoke the deployed function → discover and query the metric with `vc metrics` or Observability.

Add metrics proactively

Do not wait for the user to ask. When you create or meaningfully change server code that runs as a Vercel Function, add metric() calls in the same change if the code does work someone would want to watch in production:

  • Business events: signups, orders, payments, checkouts, invites, subscriptions.
  • Calls to slow or fallible dependencies: AI model calls, external APIs, databases, caches, queues. Record duration and outcome.
  • Background work: webhooks, scheduled jobs, queue consumers, workflow steps. Record processed counts, failures, and batch sizes.
  • AI features: token usage, model, latency, and tool-call outcomes.

Keep it small: usually one outcome counter and one duration per handler or dependency call, tagged with outcome and one or two other bounded attributes. Skip trivial handlers (health checks, static redirects, pure pass-through proxies), client components, and code that does not run in a Vercel Function.

metric() is safe to add by default once @vercel/functions is 3.9.0 or later; check the installed version and upgrade it in the same change if it is older. It is synchronous, does not need awaiting, and is a no-op when the runtime does not support Custom Metrics (for example local development or another host), so it does not break those environments.

Custom Metrics are available on Pro and Enterprise with Observability Plus, and each metric() call is billed as one Observability event ($1.20 per 1M). A function can call metric() at most 100 times per invocation. Emit once per logical operation, not inside tight loops or once per item of a large batch; record a batch total or size instead.

When you add metrics, say so in one line of your summary and list the metric names, so the user can find them with vc metrics schema or in Observability.

If the project already uses a third-party metrics SDK (Datadog, StatsD, Prometheus, OpenTelemetry metrics), do not remove it unasked. For new metrics in Vercel Functions, prefer metric() unless the user wants everything in the existing tool.

Emit a metric

Install or upgrade @vercel/functions, then import metric from its root entry point:

bash
pnpm add @vercel/functions
ts
import { metric } from '@vercel/functions';

export async function POST() {
  const startedAt = performance.now();

  try {
    await createOrder();
    metric('orders.created', 1, { outcome: 'success' });
    return Response.json({ ok: true });
  } catch (error) {
    metric('orders.created', 1, { outcome: 'error' });
    throw error;
  } finally {
    metric('orders.duration_ms', performance.now() - startedAt);
  }
}

The signature is:

ts
metric(name: string, value: number, tags?: Record<string, string>): void
  • name identifies one stable measurement, such as orders.created or orders.duration_ms.
  • value is the numeric sample. Emit 1 for an increment that will be summed; emit the observed value for a duration, size, or score.
  • tags are optional string attributes. After ingestion, discovered tag keys appear as dimensions for filtering and grouping.
  • metric() is synchronous and returns void; do not await it.
  • The helper is a no-op when the runtime does not expose Custom Metrics support. Verify instrumentation through a deployed Vercel Function invocation, not local execution alone.

Model metrics for useful queries

  • Prefer stable, dotted names with a unit suffix where useful: checkout.completed, checkout.duration_ms, queue.batch_size.
  • Do not use the reserved vercel. prefix for application-defined names.
  • Keep variable data in tags instead of metric names. Use checkout.completed with { plan: 'pro' }, not checkout.completed.pro.
  • Keep tag cardinality bounded. Good tags are outcome, plan, provider, or a normalized route. Do not attach user IDs, request IDs, email addresses, raw URLs, or other unique or sensitive values.
  • Emit one sample at the point where the outcome is known. For retryable or at-least-once work, decide whether attempts or successful logical operations are the intended measurement and name the metric accordingly.

Choose the query aggregation to match what was emitted:

MeasurementEmitQuery
Occurrence or incrementmetric('checkout.completed', 1)sum or persecond
Duration or sizemetric('checkout.duration_ms', duration)avg, p75, p95, max
Sampled levelmetric('queue.batch_size', size)avg, min, max, percentiles

Discover and query the metric

Run the deployed code at least once, then use the linked project and correct team scope:

bash
vc metrics schema
vc metrics schema orders.duration_ms

vc metrics orders.created --aggregation sum --group-by outcome --since 24h
vc metrics orders.duration_ms --aggregation p95 --since 1h
vc metrics orders.duration_ms --aggregation p95 --group-by outcome --since 24h --json

vc and vercel are equivalent. Use --aggregation; -a still works but is a deprecated shorthand. Use --json for machine-readable output (CLI 58.1+; older CLIs use --format=json). Always inspect the exact metric first with vc metrics schema <name> because the schema reports the available aggregations and discovered tag dimensions. Use -S <team> and -p <project> when the current link or scope is ambiguous; use --all only for a deliberate team-wide query.

Custom Metrics querying requires Observability Plus and availability for the selected team. If a metric is missing:

  1. Confirm the function was deployed to Vercel and the instrumented path actually ran.
  2. Confirm @vercel/functions is 3.9.0 or later, the first version that exports metric; upgrade it if necessary.
  3. Check vc whoami, the selected team, and the linked project.
  4. Allow for ingestion delay, then rerun vc metrics schema.
  5. Confirm Observability Plus and Custom Metrics are enabled for the team.

Use the right signal

  • Use Custom Metrics for numeric values you want to aggregate, trend, and filter.
  • Use Web Analytics custom events for user interaction and conversion events in Web Analytics.
  • Use OpenTelemetry spans for traces, operation timing, and request causality.
  • Use logs for detailed diagnostic context and individual records.

Do not encode detailed event payloads into metric tags. Pair a low-cardinality metric with structured logs or traces when investigation needs per-request detail.

dallo stesso repository

Altri Skills

Tutti gli Skills
vercel
Ufficiale

access-protected-vercel-deployment

Access and test Vercel deployments protected by Vercel Authentication, SSO, or Deployment Protection. Use when curl, agent-browser, Playwright, or another automated request reaches a Vercel login or protection page; when a protected preview or production URL returns 401 or 403; when TRUSTEDSOURCESENVIRONMENTMISMATCH appears; or when choosing between vercel curl and the x-vercel-trusted-oidc-idp-token header.

Installazioni / 1h
1
GitHub Stars
341
Aggiornato
20 nov
vercel
Ufficiale

client-side-security

Protect what runs in your users' browsers on Vercel with a Content-Security-Policy header and Page Integrity script monitoring. Use when adding or debugging a CSP, choosing where to set it (Next.js proxy.ts or next.config.js, vercel.json, Project Routes), allowing Vercel Toolbar under CSP, monitoring third-party scripts or tag managers, or meeting PCI DSS script requirements. For WAF rules and rate limits use vercel-firewall; for bots use botid.

Installazioni / 1h
1
GitHub Stars
341
Aggiornato
20 nov
vercel
Ufficiale

domains

Search, register, connect, transfer, and renew domain names on Vercel using the CLI or Domains Registrar API. Use for domain availability and pricing, custom domains, DNS records, nameservers, ownership verification, and domain orders.

Installazioni / 1h
1
GitHub Stars
341
Aggiornato
20 nov
vercel
Ufficiale

vercel-schedules

Vercel Schedules guidance — run a private function, route, or Vercel Queues topic on a cron cadence or once at a set time. Covers static schedules in vercel.json, dynamic per-user schedules with @vercel/schedules, handleSchedule, the vercel schedules CLI, environments, jitter, and migrating from Cron Jobs. Use when adding scheduled or recurring work, one-time reminders, or replacing crons.

Installazioni / 1h
1
GitHub Stars
341
Aggiornato
20 nov