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

@optima-chat/observability

v0.3.1

Published

Optima 生产可观测性共享库 - 诊断、日志、追踪 (Next.js/Node.js)

Readme

@optima/core

Optima 生产可观测性共享库 - 专为 Next.js/Node.js 设计

功能

  • 诊断端点: /health 健康检查、/debug/info/debug/config
  • 结构化日志: JSON/Text 格式、自动注入追踪信息
  • 分布式追踪: trace_id 生成与传递、AsyncLocalStorage 上下文
  • HTTP 客户端: 自动传递追踪 header

安装

npm install @optima/core
# 或
pnpm add @optima/core

使用方法

健康检查端点

// app/api/health/route.ts
import { createHealthHandler } from "@optima/core/diagnostics";

export const GET = createHealthHandler({
  serviceName: "agentic-chat",
  checks: {
    database: async () => {
      // 检查数据库连接
      return { status: "healthy" };
    },
    redis: async () => {
      // 检查 Redis
      return { status: "healthy" };
    },
  },
});

调试端点

// app/api/debug/info/route.ts
import { createDebugInfoHandler } from "@optima/core/diagnostics";
export const GET = createDebugInfoHandler();

// app/api/debug/config/route.ts
import { createDebugConfigHandler } from "@optima/core/diagnostics";
export const GET = createDebugConfigHandler();

API Route 追踪

// app/api/users/route.ts
import { withTracing } from "@optima/core/tracing";

async function handler(request: Request) {
  // 处理请求
  return Response.json({ users: [] });
}

export const GET = withTracing(handler, {
  serviceName: "agentic-chat",
  serviceShort: "chat",
});

结构化日志

import { createLogger } from "@optima/core/logging";

const logger = createLogger({
  serviceName: "agentic-chat",
  format: "json", // 或 "text"
  level: "info",
});

logger.info("User logged in", { userId: "123" });
logger.error("Failed to process", { error: "timeout" }, new Error("Timeout"));

带追踪的 HTTP 请求

import { tracedFetch, createTracedClient } from "@optima/core/http";

// 单次请求
const response = await tracedFetch("http://user-auth/api/users");

// 创建客户端
const authApi = createTracedClient("http://user-auth:8000");
const user = await authApi.get("/users/123");
await authApi.post("/users", { name: "John" });

环境变量

| 变量 | 说明 | 默认值 | |------|------|--------| | GIT_COMMIT | Git commit hash | unknown | | GIT_BRANCH | Git 分支 | unknown | | APP_VERSION | 应用版本 | 0.0.0 | | BUILD_DATE | 构建日期 | 当前时间 | | DEPLOYMENT_ID | 部署 ID (蓝绿) | - | | LOG_FORMAT | 日志格式 | json | | LOG_LEVEL | 日志级别 | info | | DEBUG_KEY | Debug 端点密钥 | - |

Trace ID 格式

格式: {timestamp_hex}-{random_hex}-{service_short}
示例: 67890abc-f1e2d3c4b5a6-chat

响应 Header

| Header | 说明 | |--------|------| | X-Trace-ID | 追踪 ID | | X-Request-ID | 请求 ID | | X-Response-Time | 响应时间 | | X-Served-By | 服务名-版本 | | X-Deployment-ID | 部署 ID |

License

MIT