npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@omni-api/plugin-observability

v0.0.2

Published

Observability for OmniAPI: structured logger + OTel tracing + Prometheus metrics. All optional, all pluggable.

Downloads

20

Readme

@omni/plugin-observability

OmniAPI 一站式可观测:结构化日志 + OTel 追踪 + Prometheus 指标,三件套全部 peer-optional —— 装哪个用哪个,都不装也能跑。

安装

最小:

pnpm add @omni/plugin-observability

按需启用(业务自己决定要哪个):

pnpm add pino                       # 结构化日志
pnpm add @opentelemetry/api         # 分布式追踪(你需要自己配 SDK / Exporter)
pnpm add prom-client                # Prometheus 指标

快速使用

import { createObservability } from '@omni/plugin-observability';

const obs = await createObservability({
  logger: { level: 'info', bindings: { service: 'orders', env: 'prod' } },
  metrics: { prefix: 'myapp' },
});

defineProcedure({
  name: 'order.create',
  middleware: [obs.middleware /* 自动 log + trace + metrics */],
  // ...
});

// HTTP 暴露 /metrics
import { createHttpAdapter } from '@omni/http';
const http = createHttpAdapter({ registry, logger: obs.logger });
http.server.get('/_metrics', async (_req, reply) => {
  reply.header('content-type', 'text/plain; version=0.0.4');
  return obs.metrics.render();
});

自动产出

每个 procedure 调用都会产生:

日志

INFO  procedure.success {"procedure":"order.create","source":"http","requestId":"req_xxx","durationMs":42}
WARN  procedure.failure {"procedure":"order.delete","code":"FORBIDDEN","durationMs":3,"errorMessage":"..."}
ERROR procedure.failure {"procedure":"x","code":"INTERNAL",...}   # 5xx 用 error 级别

日志级别策略:

  • 4xx 业务错误 → warn(业务可预期)
  • 5xx / 非 OmniError → error

指标(Prometheus)

  • omni_procedure_total{name, source, status, code} —— 计数
    • status: success / client_error / server_error
    • code: OK / VALIDATION_ERROR / FORBIDDEN / ...
  • omni_procedure_duration_seconds{name, source, status} —— 直方图(默认桶 1ms~10s)

Trace

  • 每个 procedure 一个 span:procedure <name>
  • 自动属性:omni.procedure.nameomni.sourceomni.request_idomni.user_idomni.duration_ms
  • 异常自动 recordException + setStatus(ERROR)

子模块单独使用

import { createLogger, createTracer, createMetrics } from '@omni/plugin-observability';

const logger  = await createLogger({ level: 'info' });
const tracer  = await createTracer({ name: 'orders' });
const metrics = await createMetrics({ prefix: 'app' });

为什么 peer-optional?

避免框架强绑定具体观测栈。业务可能:

  • 只要日志(pino),不要 metrics
  • 内部已经有自家 OTel 配置
  • 只想跑测试,三个都不要

→ 这些场景全部支持,零 if-else。