@civitai/next-axiom

中文文档
0.17.0发布于 2024/09/18MITTypeScriptCommonJS近 30 天下载 1.2万

A fork of next-axiom 0.17

原始使用文档
文档目录7 节
  1. Installation
  2. Using Vercel Integration
  3. Using Any Other Platform
  4. Usage
  5. Web Vitals
  6. Log Levels
  7. getServerSideProps

next-axiom: The official Next.js library for Axiom next-axiom: The official Next.js library for Axiom

build Latest release License

Axiom unlocks observability at any scale.

  • Ingest with ease, store without limits: Axiom’s next-generation datastore enables ingesting petabytes of data with ultimate efficiency. Ship logs from Kubernetes, AWS, Azure, Google Cloud, DigitalOcean, Nomad, and others.
  • Query everything, all the time: Whether DevOps, SecOps, or EverythingOps, query all your data no matter its age. No provisioning, no moving data from cold/archive to “hot”, and no worrying about slow queries. All your data, all. the. time.
  • Powerful dashboards, for continuous observability: Build dashboards to collect related queries and present information that’s quick and easy to digest for you and your team. Dashboards can be kept private or shared with others, and are the perfect way to bring together data from different sources.

For more information, check out the official documentation.

Installation

Using Vercel Integration

Make sure you have the Axiom Vercel integration installed. Once it is done, perform the steps below:

  • In your Next.js project, run install next-axiom as follows:
npm install --save next-axiom
  • In the next.config.js file, wrap your Next.js config in withAxiom as follows:
const { withAxiom } = require('next-axiom');

module.exports = withAxiom({
  // ... your existing config
});

Using Any Other Platform

Create an API token in Axiom settings and export it as AXIOM_TOKEN, as well as the Axiom dataset name as AXIOM_DATASET. Once it is done, perform the steps below:

  • In your Next.js project, run install next-axiom as follows:
npm install --save next-axiom
  • In the next.config.js file, wrap your Next.js config in withAxiom as follows:
const { withAxiom } = require('next-axiom');

module.exports = withAxiom({
  // ... your existing config
});

:warning: next-axiom is still experimental for non-Vercel platforms and is subject to change.

Usage

Web Vitals

:warning: Web-Vitals are not yet supported in Next.js 13 and above. Please use Next.js 12 or below.

Go to pages/_app.js or pages/_app.ts and add the following line to report web vitals:

export { reportWebVitals } from 'next-axiom';

Note: WebVitals are only sent from production deployments.

Wrapping your handlers in withAxiom will make req.log available and log exceptions:

:warning: Nextjs 13.x server side components are not yet supported.

import { withAxiom, AxiomAPIRequest } from 'next-axiom';

async function handler(req: AxiomAPIRequest, res: NextApiResponse) {
  req.log.info('Login function called');

  // You can create intermediate loggers
  const log = req.log.with({ scope: 'user' });
  log.info('User logged in', { userId: 42 });

  res.status(200).text('hi');
}

export default withAxiom(handler);

Import and use log in the frontend like this:

import { log } from `next-axiom`;

// pages/index.js
function home() {
    ...
    log.debug('User logged in', { userId: 42 })
    ...
}

Log Levels

The log level defines the lowest level of logs sent to Axiom. The default is debug, resulting in all logs being sent. Available levels are (from lowest to highest): debug, info, warn, error

For example, if you don't want debug logs to be sent to Axiom:

export AXIOM_LOG_LEVEL=info

You can also disable logging completely by setting the log level to off:

export AXIOM_LOG_LEVEL=off

getServerSideProps

To be able to use next-axiom with getServerSideProps you need to wrap your function with withAxiomGetServerSideProps, becasue there is no way at the moment to automatically detected if getServerSideProps is used.

import { withAxiomGetServerSideProps } from 'next-axiom'
export const getServerSideProps = withAxiomGetServerSideProps(async ({ req, log })  => {
  log.info('Hello, world!');
  return {
    props: {
    },
  }
});


### License

Distributed under the [MIT License](LICENSE).

版本与发布记录

@civitai/next-axiom 共发布 1 个版本,首次发布于 2024/09/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.17.0latest2024/09/182 年前

关于 @civitai/next-axiom 的常见问题

@civitai/next-axiom 是什么?

A fork of next-axiom 0.17

如何安装 @civitai/next-axiom?

在项目目录运行 npm install @civitai/next-axiom,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(^12.1.4 || ^13 || ^14)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@civitai/next-axiom 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@civitai/next-axiom 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@civitai/next-axiom 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=15。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@civitai/next-axiom 可以商用吗?

@civitai/next-axiom 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@civitai/next-axiom 的下载量有多少?

根据 npm 官方下载统计,@civitai/next-axiom 在 2026/10/10 – 2026/11/08 这 30 天内被下载 11,833 次,日均约 394 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@civitai/next-axiom 还在维护吗?

最新版本 0.17.0 发布于 2024/09/18(2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/09/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。