扩展
身份标头
evlog 发送的每个 drain 请求都会附带 User-Agent 和 X-Evlog-Source 标头,以便接收方识别并分类这些流量。在你的自定义 drain 需要不同身份时,可以覆盖或抑制这些标头。
evlog 发送的每个 drain 请求都会标记两个身份标头,以便接收方识别流量:
| 标头 | 值 |
|---|---|
User-Agent | evlog/<version>(仅限 Node / 服务端运行时——浏览器会剥离此标头) |
X-Evlog-Source | 适配器名称(axiom、datadog、otlp、posthog、sentry、better-stack、client、…) |
浏览器端的 evlog/http drain(客户端传输使用)会改为设置 X-Evlog-Source: client,因为浏览器无法覆盖 User-Agent。
为什么
- 在接收端进行分类。 在接收系统的日志中快速区分 evlog 流量与其他客户端。
- 跟踪适配器使用情况和版本漂移。 发布新的 evlog 版本,并在中心化位置观察
User-Agent分布的变化。 - 调试特定的 drain。 通过
X-Evlog-Source进行筛选,在大量入站请求中隔离某个适配器的行为。
读取版本
这两个常量都从 evlog/toolkit 导出,因此你的 drain(或你的接收端)可以引用这些规范值:
import { EVLOG_USER_AGENT, EVLOG_VERSION } from 'evlog/toolkit'
console.log(EVLOG_VERSION) // → "2.16.0"
console.log(EVLOG_USER_AGENT) // → "evlog/2.16.0"
从自定义 drain 中覆盖
使用 defineHttpDrain() 构建的适配器会自动将 drain 的 name 作为 source 传入,并将规范化的 evlog/<version> 作为 userAgent 传入。你无需为此操心。
当你直接基于 evlog/toolkit 中的 httpPost 构建 drain 时(例如为了一个具有不同身份的 fork,或为了希望使用自己 UA 的供应商),可以传入 source 和/或 userAgent 进行覆盖:
import { httpPost } from 'evlog/toolkit'
await httpPost({
url: 'https://my-platform.example.com/ingest',
headers: { 'Content-Type': 'application/json' },
body: '[]',
timeout: 5000,
label: 'my-platform',
source: 'my-platform', // 作为 X-Evlog-Source 发送
userAgent: 'my-fork/1.0', // 覆盖默认的 User-Agent
// userAgent: false, // 完全抑制该标头
})
下一步
- 自定义 Drains —
defineHttpDrain会自动注入身份标头 - Drain Pipeline — 在保留身份标头的同时,为任意 drain 包裹批处理 + 重试