otel-weaver
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenTelemetry Weaver
OpenTelemetry Weaver
Use this skill when an organization wants to define its own semantic conventions on top of upstream OTel and generate language bindings from them.
Usage:
- pair with to decide which attributes already exist upstream and should not be redeclared in the local registry
otel-semantic-conventions - use only for SDK package selection; Weaver versions are tracked separately at https://github.com/open-telemetry/weaver/releases
otel-sdk-versions
If a companion skill is unavailable:
- do not stop
- do not rely on memory alone when the guidance can be checked from official sources
- consult the Weaver repo, , and
schemas/semconv-syntax.v2.md/docs/usage.mddocs/validate.md - state which fallback you used and leave any unverified item unresolved
当组织希望在上游OTel语义约定基础上定义自己的语义约定,并从中生成语言绑定代码时,可使用本技能。
使用场景:
- 搭配技能,判断哪些属性已存在于上游语义约定中,无需在本地注册中心重新声明
otel-semantic-conventions - 仅在选择SDK包时使用;Weaver的版本单独在https://github.com/open-telemetry/weaver/releases追踪
otel-sdk-versions
若配套技能不可用:
- 不要停滞
- 当指南可从官方来源查询时,不要仅依赖记忆
- 查阅Weaver仓库、以及
schemas/semconv-syntax.v2.md/docs/usage.mddocs/validate.md - 说明你使用的备选方案,并将未验证的项标记为未解决
Mental Model
核心模型
Three moving parts:
- Registry — directory of YAML files. is required; its
manifest.yaml(OTel schema URL format,schema_url) both names the registry and carries its version in the final path segment. Dependency entries also requirehttp[s]://host/path/<version>plus optionalschema_url. The rest declareregistry_path,attributes,metrics,spans,events. The version segment ofentitiesis yours to manage; bump it on changes. (schema_urlandsemconv_versionare deprecated in favor ofschema_base_url; top-levelschema_urlis not a v0.25.1 manifest field.)name - Templates — directory of MiniJinja files (Jinja2-compatible, not full Jinja2 — auto-escaping is off by default since v0.22.0 and loop /
breakare supported) plus acontinueper target language describing which templates to run, with what filter, in whatweaver.yaml, and with what output filename.application_mode - Policies — Rego rules evaluated by the Regorus (OPA-compatible) engine, in four packages: (raw parsed groups; unsupported and skipped with
before_resolution),--v2(resolved registry),after_resolution(only whencomparison_after_resolutionis passed), and--baseline-registry(per-sample duringlive_check_advice). Built-in OTel policies are the floor; custom policies layer on org rules.live-check
These three replace a hand-rolled (or equivalent): const blocks become the registry, the act of writing them becomes codegen, and tribal knowledge becomes policies.
const.go包含三个核心部分:
- 注册中心 —— YAML文件目录。必须包含;其中的
manifest.yaml(OTel Schema URL格式,schema_url)既为注册中心命名,又在最终路径段中携带其版本信息。依赖项条目同样需要http[s]://host/path/<version>,可选schema_url。其余文件用于声明registry_path、attributes、metrics、spans、events。entities的版本段由你自行管理;修改时需更新版本。(schema_url和semconv_version已被schema_base_url取代;顶层schema_url不是v0.25.1版本清单的字段。)name - 模板 —— MiniJinja文件(兼容Jinja2,但并非完整Jinja2——自v0.22.0起默认关闭自动转义,且支持循环/
break)目录,每个目标语言对应一个continue文件,描述要运行哪些模板、使用什么过滤器、处于何种weaver.yaml以及输出文件名。application_mode - 策略 —— 由Regorus(兼容OPA)引擎执行的Rego规则,分为四个包:(原始解析组;使用
before_resolution时不支持并跳过)、--v2(解析后的注册中心)、after_resolution(仅在传入comparison_after_resolution时生效)、--baseline-registry(live_check_advice过程中按样本执行)。内置OTel策略是基础;自定义策略可叠加组织规则。live-check
这三部分替代了手动编写的(或等效文件):常量块变为注册中心,编写常量的过程变为代码生成,经验性知识变为策略。
const.goNon-Negotiable Rules
不可违背的规则
- Install Weaver via one of the methods documented at https://github.com/open-telemetry/weaver#install (release binary, Docker image, or the
otel/weaver:vX.Y.ZGitHub Action). Neversetup-weaver— that resolves to an unrelated Scribd tool.brew install weaver - Reference upstream semconv attributes by rather than redeclaring them. Boundary domains (
ref,http,db,messaging,rpc,network, ...) belong in upstream OTel semconv, not in a local registry. Use the language SDK's semconv package for those at runtime.gen-ai - Every attribute and signal definition needs ; include it on enum members too, as required by the v2 syntax guide. Weaver v0.25.1 rejects missing definition stability but reports missing enum-member stability only as a non-fatal warning in normal mode.
stability - Use a domain prefix (e.g. ,
ecommerce.) for org-local attributes, metrics, and spans.acme. - Run the language formatter (,
gofmt -w,prettier, ...) on generated output. Jinja whitespace produces multiple blank lines; without formatting, the diff check in CI will fail spuriously.ruff format - Confirm the resolved schema shape before writing a template. For a registry, call the grouped jq helpers with
definition/2; the v2 template{"v2": true}preserves fields such as attributectx, metrickey, spanname/typeand structuredkind, plus entityspan.name.note/type/identity. Seedescriptionfor how to dump the exact shape.references/template-authoring.md
- 通过https://github.com/open-telemetry/weaver#install文档中记录的方法之一安装Weaver(发布二进制文件、Docker镜像,或
otel/weaver:vX.Y.ZGitHub Action)。绝不要使用setup-weaver——这会安装一个无关的Scribd工具。brew install weaver - 通过引用上游语义约定属性,而非重新声明。边界领域(
ref、http、db、messaging、rpc、network等)属于上游OTel语义约定,不应放在本地注册中心。运行时使用语言SDK的semconv包来处理这些领域。gen-ai - 每个属性和信号定义都需要;枚举成员也需要包含该字段,这是v2语法指南的要求。Weaver v0.25.1会拒绝缺失定义稳定性的内容,但在正常模式下仅将缺失枚举成员稳定性的情况报告为非致命警告。
stability - 为组织本地的属性、指标和跨度使用领域前缀(例如、
ecommerce.)。acme. - 对生成的输出运行语言格式化工具(、
gofmt -w、prettier等)。Jinja的空格会产生多个空行;如果不格式化,CI中的差异检查会出现误判失败。ruff format - 在编写模板前确认解析后的Schema结构。对于版本的注册中心,调用分组jq助手并传入
definition/2;v2模板的{"v2": true}会保留属性ctx、指标key、跨度name/type和结构化kind,以及实体span.name.note/type/identity等字段。请参阅description了解如何导出精确结构。references/template-authoring.md
Workflow
工作流程
- Install or locate Weaver. Follow the upstream install instructions at https://github.com/open-telemetry/weaver#install — pick a pinned release binary, the Docker image, or the
otel/weaver:vX.Y.ZGitHub Action. Use Docker for CI and reproducible local runs.setup-weaver - Author the registry. Required: plus one or more
manifest.yamlYAML files declaring attributes, attribute groups, metrics, spans, events, or entities. Seedefinition/2.references/registry-authoring.md - Author templates. One target dir per language under with
templates/registry/<lang>/plusweaver.yaml. See*.j2.references/template-authoring.md - Validate and generate. for fast feedback.
weaver registry check --v2 -r ./telemetry/registry/for codegen. Run the language formatter on the output.weaver registry generate --v2 --registry ./telemetry/registry/ --templates ./telemetry/templates/ <lang> <output-dir> - Wire into CI. Three gates: (schema),
check+generate(checked-in code is current),git diff --exit-codeagainst the base branch (surfaces breaking changes). Seediff.references/ci-integration.md
The Weaver CLI has more subcommands than this workflow touches: and for quick registry sanity checks, for keeping semconv snippets in docs current, // for working against live OTLP telemetry, for exposing a registry to LLM tooling, and for an HTTP+UI mode. All are out of scope here (see below) but worth knowing exist before assuming // is the whole surface.
statsjson-schemaupdate-markdownemitlive-checkinfermcpservecheckgeneratediff- 安装或定位Weaver。遵循上游安装说明https://github.com/open-telemetry/weaver#install——选择固定版本的二进制文件、Docker镜像,或
otel/weaver:vX.Y.ZGitHub Action。CI和可复现的本地运行使用Docker。setup-weaver - 编写注册中心。必须包含:以及一个或多个
manifest.yaml版本的YAML文件,用于声明属性、属性组、指标、跨度、事件或实体。请参阅definition/2。references/registry-authoring.md - 编写模板。在下为每种语言创建一个目标目录,包含
templates/registry/<lang>/和weaver.yaml文件。请参阅*.j2。references/template-authoring.md - 验证与生成。运行获取快速反馈。运行
weaver registry check --v2 -r ./telemetry/registry/进行代码生成。对输出运行语言格式化工具。weaver registry generate --v2 --registry ./telemetry/registry/ --templates ./telemetry/templates/ <lang> <output-dir> - 集成到CI。三个检查环节:(Schema验证)、
check+generate(确认已提交代码为最新)、与基准分支的git diff --exit-code(发现破坏性变更)。请参阅diff。references/ci-integration.md
Weaver CLI还有更多本工作流程未涉及的子命令:和用于快速的注册中心完整性检查,用于保持文档中语义约定片段的更新,//用于处理实时OTLP遥测数据,用于向LLM工具暴露注册中心,用于HTTP+UI模式。这些不在本文范围内(见下文),但在假设//是全部功能前,值得了解它们的存在。
statsjson-schemaupdate-markdownemitlive-checkinfermcpservecheckgeneratediffGotchas
常见陷阱
These cost time and are not obvious from the upstream docs:
- installs the wrong tool. Use GitHub releases or Docker.
brew install weaver - Generated output is not formatter-clean. Always run the language formatter after .
weaver registry generate - Jq helper defaults target the legacy schema. For , pass
definition/2and use the preserved v2 fields: attribute{"v2": true}, metrickey, spanname/typeandkind, plus entityspan.name.note/type/identity. Always generate and inspect the filtereddescriptionbefore writing a template.ctx - The Jinja filter takes a keyword argument:
comment. It already emits theattr.brief | comment(format="go")prefix; do not add another.// - Attributes, metrics, spans, events, and entities all have prebuilt grouped jq filters (,
semconv_grouped_attributes,semconv_grouped_metrics,semconv_grouped_spans,semconv_grouped_events). Forsemconv_grouped_entities, use (for example)definition/2as a folded YAML scalar; the bare helper defaults select the legacy schema.semconv_grouped_spans({"v2": true}) - emits "File format
weaver registry checkis not yet stable" (a warning) for custom v2 definition files in v0.25.1. This is normal; do not treat it as a failure.definition/2 - is opt-in but still elevates the
--futureinstability warning to an error for a custom v2 registry in v0.25.1. Leave it off until the format goes stable.definition/2 - CLI argument ordering for : target directory name is positional after
generateand--registry; the output directory follows.--templatespoints at the parent that contains target dirs, not at the language-specific subdir.--templates - Span name in registry vs. runtime: required schema fields are ,
type(kind/client/server/producer/consumer),internal,brief, and a structuredstability. For internal business spans, putting the dotted type identifier inname: { note: "..." }and rendering the resolvedname.notestring at runtime is clean.span.name.note - What does NOT belong in your local registry. DB, HTTP, messaging, RPC, network, GenAI, and similar boundary spans/attributes follow upstream OTel semconv. Until upstream is pulled in as a manifest dependency, instrumentation for those should reference the language SDK's semconv package directly. This is the most common modeling mistake.
- Counter and UpDownCounter names should not append ; this is the current semconv v1.44.0 naming rule.
_total - Duration instruments should use seconds () under the current semconv v1.44.0 unit guidance.
s
这些问题会耗费时间,且在上游文档中并不明显:
- 安装的是错误工具。请使用GitHub发布版本或Docker。
brew install weaver - 生成的输出未经过格式化。在后务必运行语言格式化工具。
weaver registry generate - Jq助手默认针对旧版Schema。对于版本,传入
definition/2并使用保留的v2字段:属性{"v2": true}、指标key、跨度name/type和kind,以及实体span.name.note/type/identity。编写模板前务必生成并检查过滤后的description。ctx - Jinja过滤器接受关键字参数:
comment。它已自动添加attr.brief | comment(format="go")前缀;不要重复添加。// - 属性、指标、跨度、事件和实体都有预构建的分组jq过滤器(、
semconv_grouped_attributes、semconv_grouped_metrics、semconv_grouped_spans、semconv_grouped_events)。对于semconv_grouped_entities版本,使用(例如)definition/2作为折叠YAML标量;默认的裸助手会选择旧版Schema。semconv_grouped_spans({"v2": true}) - 在v0.25.1中,会为自定义v2定义文件发出"File format
weaver registry checkis not yet stable"(警告)。这是正常现象;不要将其视为失败。definition/2 - 是可选参数,但在v0.25.1中仍会将自定义v2注册中心的
--future不稳定性警告提升为错误。在格式稳定前请勿启用。definition/2 - 的CLI参数顺序:目标目录名称是
generate和--registry之后的位置参数;输出目录紧随其后。--templates指向包含目标目录的父目录,而非特定语言的子目录。--templates - 注册中心中的跨度名称与运行时:Schema必填字段为、
type(kind/client/server/producer/consumer)、internal、brief,以及结构化stability。对于内部业务跨度,将点分隔的类型标识符放入name: { note: "..." },并在运行时渲染解析后的name.note字符串是更简洁的做法。span.name.note - 不应放入本地注册中心的内容。DB、HTTP、消息传递、RPC、网络、GenAI等边界跨度/属性遵循上游OTel语义约定。在将上游作为清单依赖项引入前,这些领域的工具应直接引用语言SDK的semconv包。这是最常见的建模错误。
- Counter和UpDownCounter的名称不应追加;这是当前semconv v1.44.0的命名规则。
_total - 时长工具应使用秒();这是当前semconv v1.44.0的单位指南。
s
References To Load On Demand
按需查阅的参考资料
- registry YAML field reference:
references/registry-authoring.md - Jinja2 patterns, jq filters, resolved-shape cheat sheet:
references/template-authoring.md - ready-to-lift GitHub Actions example:
references/ci-integration.md - hand-maintained-constants → registry walkthrough:
references/migration-playbook.md - semantic conventions skill:
otel-semantic-conventions - manual instrumentation skill:
manual-instrumentation
- 注册中心YAML字段参考:
references/registry-authoring.md - Jinja2模式、jq过滤器、解析结构速查表:
references/template-authoring.md - 可直接复用的GitHub Actions示例:
references/ci-integration.md - 手动维护常量→注册中心迁移指南:
references/migration-playbook.md - 语义约定技能:
otel-semantic-conventions - 手动埋点技能:
manual-instrumentation
Out Of Scope
超出范围的内容
These are natural follow-ups but not part of this skill:
- publishing the registry as a versioned artifact for downstream consumers
- declaring upstream semantic-conventions as a manifest dependency
- /
weaver registry live-check/emitagainst live OTLP telemetryinfer - /
weaver registry mcpweaver serve - custom Rego policies beyond the built-ins
- helper-function codegen (wrappers)
MyMetricName(meter)
这些是自然的后续内容,但不属于本技能范畴:
- 将注册中心作为版本化工件发布给下游消费者
- 将上游语义约定声明为清单依赖项
- 针对实时OTLP遥测数据运行/
weaver registry live-check/emitinfer - /
weaver registry mcpweaver serve - 内置策略之外的自定义Rego策略
- 辅助函数代码生成(包装器)
MyMetricName(meter)
Verification Contract
验证约定
If you authored or modified a Weaver registry, templates, or CI integration:
- re-open the changed files before finishing
- run against the
weaver registry check --v2registry and capture the resultdefinition/2 - run and the language formatter, then verify
weaver registry generate --v2is cleangit diff --exit-code - confirm each applicable item with codebase evidence
Report the final check with:
- completed
[x] - not applicable, with a reason
[~] - unresolved
[ ]
Use these items:
- registry has with a
manifest.yamlwhose final path segment is the versionschema_url - every definition and enum member has
stability - org-local attributes/metrics/spans use a domain prefix
- no boundary-domain (http/db/messaging/rpc/network/gen-ai) entries duplicated locally
- Counter and UpDownCounter names have no suffix
_total - duration histograms use (seconds)
s - templates use jq filters that match the resolved schema (for , call the prebuilt
definition/2helpers withsemconv_grouped_*){"v2": true} - generated output is formatter-clean
- CI runs ,
check+generate, andgit diff --exit-codeagainst the base branchdiff - changed files were re-read
- remaining risks or gaps are stated
如果你编写或修改了Weaver注册中心、模板或CI集成:
- 在完成前重新打开修改过的文件
- 针对版本的注册中心运行
definition/2并记录结果weaver registry check --v2 - 运行和语言格式化工具,然后验证
weaver registry generate --v2结果为干净(无差异)git diff --exit-code - 用代码库证据确认每个适用项
使用以下格式报告最终检查结果:
- 已完成
[x] - 不适用,附原因
[~] - 未解决
[ ]
检查项:
- 注册中心包含,且其
manifest.yaml的最终路径段为版本号schema_url - 每个定义和枚举成员都有字段
stability - 组织本地的属性/指标/跨度使用领域前缀
- 无边界领域(http/db/messaging/rpc/network/gen-ai)条目在本地重复声明
- Counter和UpDownCounter名称无后缀
_total - 时长直方图使用(秒)作为单位
s - 模板使用与解析后Schema匹配的jq过滤器(对于版本,调用预构建的
definition/2助手并传入semconv_grouped_*){"v2": true} - 生成的输出已格式化
- CI运行、
check+generate,以及与基准分支的git diff --exit-codediff - 已重新阅读修改过的文件
- 已说明剩余风险或空白点