{"id":27050,"plugin_id":"plugin_connector_690a90ec05c881918afb6a55dc9bbaa1","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-10-06T18:03:10.647Z","digest":"3cef64b743f139d5ae4555d2b75304e63bc4bdf6ccd3c39bc7e840823b33b895","against":null,"payload":{"description":"Emit and query Vercel Custom Metrics. Use when instrumenting application or business measurements in Vercel Functions, using metric() from @vercel/functions, choosing metric names and attributes, or querying emitted values with vc metrics.","included_files":[{"relative_path":"agents/openai.yaml","size_in_bytes":106}],"name":"custom-metrics","skill_md_contents":"---\nname: custom-metrics\ndescription: Emit and query Vercel Custom Metrics. Use when instrumenting application or business measurements in Vercel Functions, using metric() from @vercel/functions, choosing metric names and attributes, or querying emitted values with vc metrics.\nsummary: Emit numeric measurements from Functions and query them with vc metrics\nmetadata:\n  priority: 9\n  docs:\n    - \"https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package\"\n    - \"https://vercel.com/docs/cli/metrics\"\n    - \"https://vercel.com/docs/observability/observability-plus\"\n  sitemap: \"https://vercel.com/sitemap/docs.xml\"\n  pathPatterns: []\n  bashPatterns:\n    - '\\b(?:vercel|vc)\\s+metrics\\s+(?!schema(?:\\s|$)|vercel\\.)[A-Za-z_][A-Za-z0-9_./-]*\\b'\n    - '\\b(?:vercel|vc)\\s+metrics\\s+schema\\s+(?!vercel\\.)[A-Za-z_][A-Za-z0-9_./-]*\\b'\n  importPatterns: []\n  promptSignals:\n    phrases:\n      - \"custom metric\"\n      - \"custom metrics\"\n      - \"emit a metric\"\n      - \"emit metrics\"\n      - \"report a metric\"\n      - \"report metrics\"\n      - \"application metrics\"\n      - \"business metrics\"\n      - \"@vercel/functions metric\"\n    allOf:\n      - [emit, metric]\n      - [report, metric]\n      - [instrument, metric]\n      - [vercel, metric]\n    anyOf:\n      - \"observability\"\n      - \"instrumentation\"\n      - \"duration\"\n      - \"counter\"\n      - \"percentile\"\n    noneOf:\n      - \"font metrics\"\n      - \"core web vitals\"\n    minScore: 6\nretrieval:\n  aliases:\n    - Vercel application metrics\n    - Vercel business metrics\n    - function metrics\n    - vc metrics\n  intents:\n    - emit a custom metric\n    - instrument a Vercel Function\n    - query a custom metric\n    - measure application behavior\n  entities:\n    - metric\n    - \"@vercel/functions\"\n    - Vercel Custom Metrics\n    - vc metrics\n    - Observability Plus\n  examples:\n    - emit checkout duration as a custom metric\n    - add a business counter to this Vercel Function\n    - query my custom metric with vc metrics\n    - group an application metric by outcome\n---\n\n# Vercel Custom Metrics\n\nUse 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**.\n\n## Emit a metric\n\nInstall or upgrade `@vercel/functions`, then import `metric` from its root entry point:\n\n```bash\npnpm add @vercel/functions\n```\n\n```ts\nimport { metric } from '@vercel/functions';\n\nexport async function POST() {\n  const startedAt = performance.now();\n\n  try {\n    await createOrder();\n    metric('orders.created', 1, { outcome: 'success' });\n    return Response.json({ ok: true });\n  } catch (error) {\n    metric('orders.created', 1, { outcome: 'error' });\n    throw error;\n  } finally {\n    metric('orders.duration_ms', performance.now() - startedAt);\n  }\n}\n```\n\nThe signature is:\n\n```ts\nmetric(name: string, value: number, tags?: Record<string, string>): void\n```\n\n- `name` identifies one stable measurement, such as `orders.created` or `orders.duration_ms`.\n- `value` is the numeric sample. Emit `1` for an increment that will be summed; emit the observed value for a duration, size, or score.\n- `tags` are optional string attributes. After ingestion, discovered tag keys appear as dimensions for filtering and grouping.\n- `metric()` is synchronous and returns `void`; do not `await` it.\n- 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.\n\n## Model metrics for useful queries\n\n- Prefer stable, dotted names with a unit suffix where useful: `checkout.completed`, `checkout.duration_ms`, `queue.batch_size`.\n- Do not use the reserved `vercel.` prefix for application-defined names.\n- Keep variable data in tags instead of metric names. Use `checkout.completed` with `{ plan: 'pro' }`, not `checkout.completed.pro`.\n- 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.\n- 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.\n\nChoose the query aggregation to match what was emitted:\n\n| Measurement | Emit | Query |\n| --- | --- | --- |\n| Occurrence or increment | `metric('checkout.completed', 1)` | `sum` or `persecond` |\n| Duration or size | `metric('checkout.duration_ms', duration)` | `avg`, `p75`, `p95`, `max` |\n| Sampled level | `metric('queue.batch_size', size)` | `avg`, `min`, `max`, percentiles |\n\n## Discover and query the metric\n\nRun the deployed code at least once, then use the linked project and correct team scope:\n\n```bash\nvc metrics schema\nvc metrics schema orders.duration_ms\n\nvc metrics orders.created -a sum --group-by outcome --since 24h\nvc metrics orders.duration_ms -a p95 --since 1h\nvc metrics orders.duration_ms -a p95 --group-by outcome --since 24h --format=json\n```\n\n`vc` and `vercel` are equivalent. 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.\n\nCustom Metrics querying requires Observability Plus and availability for the selected team. If a metric is missing:\n\n1. Confirm the function was deployed to Vercel and the instrumented path actually ran.\n2. Confirm `@vercel/functions` exports `metric`; upgrade it if necessary.\n3. Check `vc whoami`, the selected team, and the linked project.\n4. Allow for ingestion delay, then rerun `vc metrics schema`.\n5. Confirm Observability Plus and Custom Metrics are enabled for the team.\n\n## Use the right signal\n\n- Use **Custom Metrics** for numeric values you want to aggregate, trend, and filter.\n- Use **Web Analytics custom events** for user interaction and conversion events in Web Analytics.\n- Use **OpenTelemetry spans** for traces, operation timing, and request causality.\n- Use **logs** for detailed diagnostic context and individual records.\n\nDo not encode detailed event payloads into metric tags. Pair a low-cardinality metric with structured logs or traces when investigation needs per-request detail.\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}