create-evlog-adapter
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate evlog Adapter
创建evlog适配器
Add a new built-in adapter to evlog. Every adapter follows the same architecture. This skill walks through all 8 touchpoints. Every single touchpoint is mandatory -- do not skip any.
为evlog添加一个新的内置适配器。所有适配器遵循相同的架构。本指南将带你完成全部8个关键步骤,每一个步骤都是必填项——请勿跳过任何一项。
PR Title
PR标题
Recommended format for the pull request title:
feat: add {name} adapterThe exact wording may vary depending on the adapter (e.g., , ), but it should always follow the conventional commit prefix.
feat: add OTLP adapterfeat: add Axiom drain adapterfeat:拉取请求标题的推荐格式:
feat: add {name} adapter具体措辞可根据适配器调整(例如 、),但必须始终遵循的约定式提交前缀。
feat: add OTLP adapterfeat: add Axiom drain adapterfeat:Touchpoints Checklist
关键步骤清单
| # | File | Action |
|---|---|---|
| 1 | | Create adapter source |
| 2 | | Add build entry |
| 3 | | Add |
| 4 | | Create tests |
| 5 | | Create adapter doc page (before |
| 6 | | Add adapter to overview (links, card, env vars) |
| 7 | | Add adapter to the "Built-in Adapters" table |
| 8 | Renumber | Ensure |
Important: Do NOT consider the task complete until all 8 touchpoints have been addressed.
| 序号 | 文件 | 操作 |
|---|---|---|
| 1 | | 创建适配器源代码 |
| 2 | | 添加构建入口 |
| 3 | | 添加 |
| 4 | | 创建测试用例 |
| 5 | | 创建适配器文档页面(放在 |
| 6 | | 在概览中添加适配器(链接、卡片、环境变量) |
| 7 | | 在“内置适配器”表格中添加该适配器 |
| 8 | 重命名 | 确保添加新适配器后 |
重要提示:只有完成全部8个步骤,任务才算完成。
Naming Conventions
命名规范
Use these placeholders consistently:
| Placeholder | Example (Datadog) | Usage |
|---|---|---|
| | File names, import paths, env var suffix |
| | PascalCase in function/interface names |
| | SCREAMING_CASE in env var prefixes |
请统一使用以下占位符:
| 占位符 | 示例(Datadog) | 用途 |
|---|---|---|
| | 文件名、导入路径、环境变量后缀 |
| | 函数/接口名称使用大驼峰命名 |
| | 环境变量前缀使用全大写加下划线命名 |
Step 1: Adapter Source
步骤1:适配器源代码
Create .
packages/evlog/src/adapters/{name}.tsRead references/adapter-template.md for the full annotated template.
Key architecture rules:
- Config interface -- service-specific fields (API key, endpoint, etc.) plus optional
timeout?: number - -- import from
getRuntimeConfig()(shared helper, do NOT redefine locally)./_utils - Config priority (highest to lowest):
- Overrides passed to
create{Name}Drain() runtimeConfig.evlog.{name}runtimeConfig.{name}- Environment variables: then
NUXT_{NAME}_*{NAME}_*
- Overrides passed to
- Factory function -- returns
create{Name}Drain(overrides?: Partial<Config>)(ctx: DrainContext) => Promise<void> - Exported send functions -- and
sendTo{Name}(event, config)for direct use and testabilitysendBatchTo{Name}(events, config) - Error handling -- try/catch with , never throw from the drain
console.error('[evlog/{name}] ...') - Timeout -- with 5000ms default, configurable via
AbortControllerconfig.timeout - Event transformation -- if the service needs a specific format, export a converter
to{Name}Event()
创建文件。
packages/evlog/src/adapters/{name}.ts可参考references/adapter-template.md获取完整的带注释模板。
核心架构规则:
- 配置接口 —— 包含服务特定字段(API密钥、端点等)以及可选的
timeout?: number - —— 从
getRuntimeConfig()导入(共享工具函数,请勿在本地重新定义)./_utils - 配置优先级(从高到低):
- 传递给的覆盖配置
create{Name}Drain() runtimeConfig.evlog.{name}runtimeConfig.{name}- 环境变量:先后
NUXT_{NAME}_*{NAME}_*
- 传递给
- 工厂函数 —— 返回
create{Name}Drain(overrides?: Partial<Config>)(ctx: DrainContext) => Promise<void> - 导出的发送函数 —— 和
sendTo{Name}(event, config),用于直接调用和测试sendBatchTo{Name}(events, config) - 错误处理 —— 使用try/catch包裹,并通过输出错误,切勿从输出函数中抛出异常
console.error('[evlog/{name}] ...') - 超时设置 —— 默认5000ms,可通过配置,使用
config.timeout实现AbortController - 事件转换 —— 如果目标服务需要特定格式,需导出转换函数
to{Name}Event()
Step 2: Build Config
步骤2:构建配置
Add a build entry in alongside the existing adapters:
packages/evlog/tsdown.config.tstypescript
'adapters/{name}': 'src/adapters/{name}.ts',Place it after the last adapter entry (currently at line 22).
sentry在中,在现有适配器旁边添加一个构建入口:
packages/evlog/tsdown.config.tstypescript
'adapters/{name}': 'src/adapters/{name}.ts',将其放在最后一个适配器入口之后(当前最后一个是,位于第22行)。
sentryStep 3: Package Exports
步骤3:包导出配置
In , add two entries:
packages/evlog/package.jsonIn (after the last adapter, currently ):
exports./posthogjson
"./{name}": {
"types": "./dist/adapters/{name}.d.mts",
"import": "./dist/adapters/{name}.mjs"
}In (after the last adapter):
typesVersions["*"]json
"{name}": [
"./dist/adapters/{name}.d.mts"
]在中添加两项配置:
packages/evlog/package.json在中(放在最后一个适配器之后,当前最后一个是):
exports./posthogjson
"./{name}": {
"types": "./dist/adapters/{name}.d.mts",
"import": "./dist/adapters/{name}.mjs"
}在中(放在最后一个适配器之后):
typesVersions["*"]json
"{name}": [
"./dist/adapters/{name}.d.mts"
]Step 4: Tests
步骤4:测试用例
Create .
packages/evlog/test/adapters/{name}.test.tsRead references/test-template.md for the full annotated template.
Required test categories:
- URL construction (default + custom endpoint)
- Headers (auth, content-type, service-specific)
- Request body format (JSON structure matches service API)
- Error handling (non-OK responses throw with status)
- Batch operations ()
sendBatchTo{Name} - Timeout handling (default 5000ms + custom)
创建文件。
packages/evlog/test/adapters/{name}.test.ts可参考references/test-template.md获取完整的带注释模板。
必需的测试类别:
- URL构造(默认端点+自定义端点)
- 请求头(认证、内容类型、服务特定头)
- 请求体格式(JSON结构匹配服务API)
- 错误处理(非成功响应时抛出状态错误)
- 批量操作()
sendBatchTo{Name} - 超时处理(默认5000ms+自定义超时)
Step 5: Adapter Documentation Page
步骤5:适配器文档页面
Create where is the next number before (custom should always be last).
apps/docs/content/3.adapters/{n}.{name}.md{n}custom.mdUse this frontmatter structure:
yaml
---
title: "{Name} Adapter"
description: "Send logs to {Name} for [value prop]. Zero-config setup with environment variables."
navigation:
title: "{Name}"
icon: i-simple-icons-{name} # or i-lucide-* for generic
links:
- label: "{Name} Dashboard"
icon: i-lucide-external-link
to: https://{service-url}
target: _blank
color: neutral
variant: subtle
- label: "OTLP Adapter"
icon: i-simple-icons-opentelemetry
to: /adapters/otlp
color: neutral
variant: subtle
---Sections to include:
- Intro paragraph -- what the service is and what the adapter does
- Installation -- import path
evlog/{name} - Quick Setup -- Nitro plugin with
create{Name}Drain() - Configuration -- table of env vars and config options
- Configuration Priority -- overrides > runtimeConfig > env vars
- Advanced -- custom options, event transformation details
- Querying/Using -- how to find evlog events in the target service
- Troubleshooting -- common errors (missing config, auth failures)
- Direct API Usage -- and
sendTo{Name}()examplessendBatchTo{Name}() - Next Steps -- links to other adapters and best practices
Use the existing Axiom adapter page () as a reference for tone, structure, and depth.
apps/docs/content/3.adapters/2.axiom.md创建,其中是之前的下一个序号(custom必须始终处于最后位置)。
apps/docs/content/3.adapters/{n}.{name}.md{n}custom.md使用以下前置元数据结构:
yaml
---
title: "{Name} 适配器"
description: "将日志发送至{Name}以[实现价值]。支持通过环境变量实现零配置启动。"
navigation:
title: "{Name}"
icon: i-simple-icons-{name} # 通用图标可使用i-lucide-*
links:
- label: "{Name} 控制台"
icon: i-lucide-external-link
to: https://{service-url}
target: _blank
color: neutral
variant: subtle
- label: "OTLP 适配器"
icon: i-simple-icons-opentelemetry
to: /adapters/otlp
color: neutral
variant: subtle
---需包含的章节:
- 介绍段落 —— 说明目标服务是什么,以及该适配器的作用
- 安装 —— 导入路径
evlog/{name} - 快速开始 —— 使用的Nitro插件示例
create{Name}Drain() - 配置 —— 环境变量和配置选项表格
- 配置优先级 —— 覆盖配置 > runtimeConfig > 环境变量
- 进阶用法 —— 自定义选项、事件转换细节
- 查询与使用 —— 如何在目标服务中查找evlog事件
- 故障排查 —— 常见错误(缺少配置、认证失败等)
- 直接API调用 —— 和
sendTo{Name}()的使用示例sendBatchTo{Name}() - 下一步 —— 指向其他适配器和最佳实践的链接
可参考现有的Axiom适配器页面()的语气、结构和内容深度。
apps/docs/content/3.adapters/2.axiom.mdStep 6: Update Adapters Overview Page
步骤6:更新适配器概览页面
Edit to add the new adapter in three places:
apps/docs/content/3.adapters/1.overview.md编辑,在三个位置添加新适配器:
apps/docs/content/3.adapters/1.overview.md6a. Frontmatter links
array
links6a. 前置元数据links
数组
linksAdd a link entry alongside the existing adapters:
yaml
- label: "{Name}"
icon: i-simple-icons-{name}
to: /adapters/{name}
color: neutral
variant: subtle在现有适配器旁边添加一个链接项:
yaml
- label: "{Name}"
icon: i-simple-icons-{name}
to: /adapters/{name}
color: neutral
variant: subtle6b. ::card-group
section
::card-group6b. ::card-group
章节
::card-groupAdd a card block for the new adapter (before the Custom card):
markdown
:::card
---
icon: i-simple-icons-{name}
title: {Name}
to: /adapters/{name}
---
[Short description of what the adapter does.]
:::为新适配器添加一个卡片块(放在Custom卡片之前):
markdown
:::card
---
icon: i-simple-icons-{name}
title: {Name}
to: /adapters/{name}
---
[适配器功能的简短描述]
:::6c. Zero-Config Setup .env
example
.env6c. 零配置启动.env
示例
.envAdd the adapter's env vars in the code block. The variable names depend on the service (e.g., , , ):
.envNUXT_AXIOM_TOKENNUXT_OTLP_ENDPOINTNUXT_POSTHOG_API_KEYbash
undefined在代码块中添加该适配器的环境变量。变量名称取决于服务(例如、、):
.envNUXT_AXIOM_TOKENNUXT_OTLP_ENDPOINTNUXT_POSTHOG_API_KEYbash
undefined{Name}
{Name}
NUXT_{NAME}_<RELEVANT_VAR>=xxx
undefinedNUXT_{NAME}_<相关变量>=xxx
undefinedStep 7: Update AGENTS.md
步骤7:更新AGENTS.md
Add the new adapter to the "Built-in Adapters" table in the root file, in the "Log Draining & Adapters" section:
AGENTS.mdmarkdown
| {Name} | `evlog/{name}` | Send logs to {Name} for [description] |Also add a usage example block (following the pattern of existing adapters in AGENTS.md):
markdown
**Using {Name} Adapter:**
\`\`\`typescript
// server/plugins/evlog-drain.ts
import { create{Name}Drain } from 'evlog/{name}'
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('evlog:drain', create{Name}Drain())
})
\`\`\`
Set the required environment variables (e.g., \`NUXT_{NAME}_TOKEN\`, \`NUXT_{NAME}_ENDPOINT\`, etc. -- depends on the service).在根目录的文件的**“内置适配器”**表格中(位于“日志输出与适配器”章节)添加新适配器:
AGENTS.mdmarkdown
| {Name} | `evlog/{name}` | 将日志发送至{Name}以[描述用途] |同时添加一个使用示例块(遵循AGENTS.md中现有适配器的格式):
markdown
**使用{Name}适配器:**
\`\`\`typescript
// server/plugins/evlog-drain.ts
import { create{Name}Drain } from 'evlog/{name}'
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('evlog:drain', create{Name}Drain())
})
\`\`\`
设置所需的环境变量(例如`NUXT_{NAME}_TOKEN`、`NUXT_{NAME}_ENDPOINT`等,具体取决于服务)。Step 8: Renumber custom.md
custom.md步骤8:重命名custom.md
custom.mdIf the new adapter's number conflicts with , renumber to be the last entry. For example, if the new adapter is , rename to .
custom.mdcustom.md5.{name}.md5.custom.md6.custom.md如果新适配器的序号与冲突,请将重命名为最后一个序号。例如,如果新适配器是,则将重命名为。
custom.mdcustom.md5.{name}.md5.custom.md6.custom.mdVerification
验证
After completing all steps, run:
bash
cd packages/evlog
bun run build # Verify build succeeds with new entry
bun run test # Verify tests pass完成所有步骤后,运行以下命令:
bash
cd packages/evlog
bun run build # 验证构建是否成功包含新入口
bun run test # 验证测试是否通过