Skip to content

feat(semconv): generate ourios-semconv constants crate via weaver forge - #105

Merged
jensholdgaard merged 4 commits into
mainfrom
feat/ourios-semconv-codegen
Jun 3, 2026
Merged

feat(semconv): generate ourios-semconv constants crate via weaver forge#105
jensholdgaard merged 4 commits into
mainfrom
feat/ourios-semconv-codegen

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented Jun 3, 2026

Copy link
Copy Markdown
Owner

What

Phase 2 of the telemetry code work. Adds the ourios-semconv crate — a dependency-free leaf of weaver-generated const &str names for every metric and attribute in semconv/registry/ — plus the generator and a CI no-diff guard.

This is the drift-proof codegen path chosen for the constants: instrumentation references ourios_semconv::OURIOS_COMPACTION_SWEEPS rather than a hand-typed "ourios.compaction.sweeps", so code names provably match the registry.

Design

  • Leaf crate, zero deps — mirrors upstream opentelemetry-semantic-conventions (itself a standalone weaver-generated crate). Kept out of ourios-core so any crate wanting a name pulls nothing and the dependency DAG direction stays clean (maintainer decision).
  • templates/registry/rust/{weaver.yaml,lib.rs.j2} — the weaver forge generator.
  • crates/ourios-semconv/src/lib.rs — GENERATED, do-not-hand-edit (header says so).
  • CI no-diff guard — the existing semconv job now also weaver registry generate + cargo fmt -p ourios-semconv + git diff --exit-code, so the checked-in constants can't drift from the registry.
  • tests/exports.rs — a hand-written guard locking the public const names (a rename breaks this compile/assert alongside the no-diff check).

Blessing

The new leaf crate + the codegen step are blessed in RFC 0009 §3.6, the same way ourios-telemetry was blessed in RFC 0001 §6.8. (CLAUDE.md §7 layout extension.)

Scope

No instrumentation yet — Phase 3 wires these constants into the compaction metrics (global::meter("ourios.compaction"), seeded at init per §6.8 collect-on-read).

Verification

  • weaver registry check + weaver registry generate (regenerate is a no-op vs the committed file) ✓
  • cargo fmt --all --check, clippy --all-targets --all-features -D warnings, cargo test -p ourios-semconv
  • mdbook build

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a semantic-conventions library exposing standardized OpenTelemetry metric and attribute name constants.
  • Documentation

    • Added RFC details describing code-generation and CI sync/format workflow for semantic conventions.
  • Chores

    • Strengthened CI to re-generate semantic conventions, run formatting, and fail on any regeneration diffs.
    • Added generation templates and a dependency-free constants crate.
  • Tests

    • Added compile-time tests to ensure exported constants match the registry.

Phase 2 of the telemetry code work. Adds the dependency-free leaf
crate `ourios-semconv` holding `const &str` names for every metric
and attribute in `semconv/registry/`, generated by `weaver registry
generate` from a forge template at `templates/registry/rust/`.

Instrumentation will reference these constants instead of hand-typed
strings, so code names provably match the registry. Mirrors upstream
`opentelemetry-semantic-conventions` (also a standalone weaver-
generated leaf crate); kept out of `ourios-core` so anyone wanting a
name pulls zero deps and the DAG direction stays clean.

- `templates/registry/rust/{weaver.yaml,lib.rs.j2}` — the generator.
- `crates/ourios-semconv/src/lib.rs` — GENERATED; do not hand-edit.
- The `semconv` CI job now also regenerates + `cargo fmt` + `git diff
  --exit-code`, so the checked-in constants can't drift from the
  registry (drift-proof, the maintainer-chosen path).
- A hand-written `tests/exports.rs` locks the public const names.

Blessed in RFC 0009 §3.6 (the new leaf crate + the codegen step),
the same way `ourios-telemetry` was blessed in RFC 0001 §6.8.

Verification: weaver registry check + generate (no-diff), cargo fmt
--all --check, clippy --all-targets --all-features -D warnings, cargo
test -p ourios-semconv, mdbook build — all green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jensholdgaard
jensholdgaard requested a review from Copilot June 3, 2026 18:12
@jensholdgaard

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c3b8ad2-31ba-4140-b019-e1ec518d4260

📥 Commits

Reviewing files that changed from the base of the PR and between 390a6ac and 8f8d5ca.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • crates/ourios-semconv/src/lib.rs
  • docs/rfcs/0009-compaction.md
  • templates/registry/rust/lib.rs.j2
  • templates/registry/rust/weaver.yaml
✅ Files skipped from review due to trivial changes (3)
  • templates/registry/rust/weaver.yaml
  • docs/rfcs/0009-compaction.md
  • crates/ourios-semconv/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/ci.yml
  • templates/registry/rust/lib.rs.j2

📝 Walkthrough

Walkthrough

Weaver templates now generate OpenTelemetry metric and attribute name constants into a new dependency-free crate crates/ourios-semconv; the crate is added to the workspace, a test verifies exported constants, CI regenerates+formats the crate and fails if generated output differs, and RFC docs describe the workflow.

Changes

Semantic Conventions Code Generation and Validation

Layer / File(s) Summary
Code generation templates
templates/registry/rust/lib.rs.j2, templates/registry/rust/weaver.yaml
Jinja2 template lib.rs.j2 emits pub const &str for metrics and attribute keys; Weaver config renders the template across the registry in single-application mode.
Workspace crate setup
Cargo.toml, crates/ourios-semconv/Cargo.toml, crates/ourios-semconv/src/lib.rs
Adds crates/ourios-semconv to the workspace; creates a non-published leaf library crate with generated src/lib.rs exporting metric and attribute name constants and #![deny(unsafe_code)].
Export validation test
crates/ourios-semconv/tests/exports.rs
Adds a test that asserts generated public constants equal specific registry string literals to catch generation drift at CI/compile time.
CI regeneration and no-diff verification
.github/workflows/ci.yml
semconv job comment updated; installs rustfmt; adds steps to run weaver registry generate and cargo fmt -p ourios-semconv, then checks git status --porcelain and emits git diff / fails if generated output differs.
Documentation (RFC)
docs/rfcs/0009-compaction.md
Documents the generation workflow, template location, recommended regeneration/formatting command (including --future), and that CI fails on diffs to prevent drift.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I stitched a crate from registry thread,
Constants snug, no naming dread.
CI trims the weave and checks the seam,
Tests keep the names exactly as they seem.
Hop, hop—regenerate another dream.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: introducing a weaver-generated ourios-semconv constants crate via code generation.
Description check ✅ Passed The PR description is comprehensive and follows the template structure with clear sections (What, Design, Blessing, Scope, Verification) covering purpose, design decisions, and validation results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ourios-semconv-codegen

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a weaver-generated, dependency-free Rust crate (ourios-semconv) that exports const &str metric/attribute names derived from semconv/registry, plus CI enforcement to prevent drift between the registry and checked-in generated code.

Changes:

  • Introduces crates/ourios-semconv with generated constants and a small export-lock test.
  • Adds weaver forge templates under templates/registry/rust/ to generate the crate’s src/lib.rs.
  • Extends the CI semconv (weaver) job to regenerate + rustfmt the crate and fail on diffs; updates RFC 0009 to document the approach.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
templates/registry/rust/weaver.yaml Weaver-forge config to render the Rust generator template.
templates/registry/rust/lib.rs.j2 Jinja template that generates metric/attribute pub const exports.
docs/rfcs/0009-compaction.md Documents the codegen approach and drift-proof CI enforcement.
crates/ourios-semconv/tests/exports.rs Integration test to lock a few representative public constant names/values.
crates/ourios-semconv/src/lib.rs Generated constants module checked into the repo.
crates/ourios-semconv/Cargo.toml New crate manifest (intentionally dependency-free).
Cargo.toml Adds crates/ourios-semconv to the workspace members.
Cargo.lock Records the new workspace package.
.github/workflows/ci.yml Updates semconv (weaver) job to regenerate + format + no-diff verify.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread templates/registry/rust/lib.rs.j2 Outdated
Comment thread .github/workflows/ci.yml Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)

104-105: ⚡ Quick win

git diff --exit-code won't catch newly generated untracked files.

git diff only compares tracked files, so if regeneration ever emits a new file under crates/ourios-semconv/src that isn't yet committed, the drift check passes silently. Staging first makes the check cover additions/deletions too.

♻️ Hardened drift check
       - name: Verify generated constants are in sync
-        run: git diff --exit-code -- crates/ourios-semconv/src
+        run: |
+          git add -A -- crates/ourios-semconv/src
+          git diff --cached --exit-code -- crates/ourios-semconv/src
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 104 - 105, The CI step "Verify
generated constants are in sync" currently runs a plain git diff which misses
untracked new files; change it to first stage all changes under the
generated-constants directory, run git diff against the staged/index (so
additions/deletions are detected), then unstage/reset the index so the workspace
is unchanged; update the step that runs the existing git diff command to perform
these three operations in sequence.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@templates/registry/rust/lib.rs.j2`:
- Around line 4-7: The header comment in templates/registry/rust/lib.rs.j2
incorrectly references a non-existent CI job name "semconv-codegen"; update the
template to reference the actual job name "semconv" so regenerated headers
(e.g., crates/ourios-semconv/src/lib.rs) are accurate—search for the string
"semconv-codegen" in templates/registry/rust/lib.rs.j2 and replace it with
"semconv" (ensuring the surrounding sentence remains grammatically correct),
then regenerate the registry output to verify the comment now matches the job
name defined in .github/workflows/ci.yml.

---

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 104-105: The CI step "Verify generated constants are in sync"
currently runs a plain git diff which misses untracked new files; change it to
first stage all changes under the generated-constants directory, run git diff
against the staged/index (so additions/deletions are detected), then
unstage/reset the index so the workspace is unchanged; update the step that runs
the existing git diff command to perform these three operations in sequence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d4656767-6579-4f43-a34e-af3553aab121

📥 Commits

Reviewing files that changed from the base of the PR and between 9470cca and ecb547f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .github/workflows/ci.yml
  • Cargo.toml
  • crates/ourios-semconv/Cargo.toml
  • crates/ourios-semconv/src/lib.rs
  • crates/ourios-semconv/tests/exports.rs
  • docs/rfcs/0009-compaction.md
  • templates/registry/rust/lib.rs.j2
  • templates/registry/rust/weaver.yaml

Comment thread templates/registry/rust/lib.rs.j2 Outdated
@jensholdgaard
jensholdgaard requested a review from Copilot June 3, 2026 18:20
@jensholdgaard

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Comment thread templates/registry/rust/weaver.yaml Outdated
Comment thread docs/rfcs/0009-compaction.md Outdated
@jensholdgaard
jensholdgaard requested a review from Copilot June 3, 2026 18:26
@jensholdgaard

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Comment thread templates/registry/rust/weaver.yaml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread docs/rfcs/0009-compaction.md Outdated
@jensholdgaard
jensholdgaard requested a review from Copilot June 3, 2026 18:37
@jensholdgaard

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants