Skip to content

feat(telemetry): scaffold ourios-telemetry crate (OTLP MeterProvider bootstrap) - #104

Merged
jensholdgaard merged 3 commits into
mainfrom
feat/ourios-telemetry-scaffold
Jun 3, 2026
Merged

feat(telemetry): scaffold ourios-telemetry crate (OTLP MeterProvider bootstrap)#104
jensholdgaard merged 3 commits into
mainfrom
feat/ourios-telemetry-scaffold

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented Jun 3, 2026

Copy link
Copy Markdown
Owner

What

Phase 1 of the telemetry code work, unblocked by the two merged telemetry RFCs (#102 RFC 0009 §3.6 metrics; #103 RFC 0001 §6.8 OTel-SDK + OTLP-push amendment).

Scaffolds the new ourios-telemetry crate — the single place the heavy OTel SDK + OTLP exporter + transport live, so instrumented library crates depend only on the lightweight opentelemetry API via global::meter(...) (the §6.8 "Export architecture" dependency split, RFC-blessed in #103).

API

  • init(&TelemetryConfig) -> Result<TelemetryGuard, _> — builds the OTLP push MeterProvider (periodic reader, configurable interval), sets service.name = ourios-<role> as a Resource attribute (per §6.8: producer identity is a resource attribute, never a data-point attribute), installs it as the process-global provider, and returns a guard. TelemetryGuard::shutdown() flushes explicitly; Drop flushes best-effort.
  • init_in_memory(&str) (behind the testing feature) — wires an InMemoryMetricExporter so other crates' tests (e.g. the miner's §8 metric-collection test) can collect the exported stream without standing up an OTLP endpoint.

Scope / what's deferred

  • No instrumentation yet. Follow-on slices: (2) weaver name-constant codegen from semconv/registry/; (3) compaction instrumentation (RFC 0009 §3.6 via global::meter("ourios.compaction"), seeding instruments at init per the §6.8 collect-on-read rule).
  • Error type is hand-rolled (Display + Error + From) to match the workspace convention — no new thiserror dependency.
  • New crate extends the CLAUDE.md §7 layout; the new-crate commitment was blessed in RFC 0001 §6.8 (docs(rfc-0001): realign §6.8 telemetry export to OTel SDK + OTLP #103).

Versions

Aligned to the OTel stack already in the lockfile: opentelemetry, opentelemetry_sdk, opentelemetry-otlp all 0.32.

Verification

  • cargo fmt --all --check
  • cargo clippy --all-targets --all-features -- -D warnings ✓ (pedantic clean)
  • cargo test --workspace --all-features ✓ (incl. the crate's in-memory metric-collection test)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added OpenTelemetry metrics with OTLP export, configurable service name, endpoint override, and export interval.
    • Provided telemetry init APIs including a testing-mode in-memory exporter for assertions.
    • Added graceful shutdown and force-flush to ensure metrics are exported on stop.
  • Chores

    • Added the telemetry crate to the workspace configuration.

…bootstrap)

First slice of the telemetry code work unblocked by RFC 0001 §6.8
(the OTel SDK + OTLP-push amendment, #103) and RFC 0009 §3.6 (#102).

Implements the §6.8 "Export architecture" dependency split: this is
the single crate that carries the heavy OTel SDK + OTLP exporter +
transport, so instrumented library crates can depend only on the
lightweight `opentelemetry` API (`global::meter(...)`).

- `init(&TelemetryConfig)` builds the OTLP push MeterProvider
  (periodic reader, configurable interval), sets `service.name =
  ourios-<role>` as a Resource attribute (not a data-point attribute,
  per §6.8), installs it as the process-global provider, and returns a
  `TelemetryGuard` whose `shutdown()` flushes on exit (Drop flushes
  best-effort).
- `init_in_memory` (behind the `testing` feature) wires an
  InMemoryMetricExporter for other crates' tests (e.g. the miner's §8
  metric-collection test) to collect the exported stream without an
  OTLP endpoint.

No instrumentation yet — that lands in the follow-on slices (weaver
name-constant codegen, then compaction instrumentation). Error type is
hand-rolled to match the workspace convention (no thiserror dep).

Verification: cargo fmt --check, clippy --all-targets --all-features
-D warnings, and cargo test --workspace --all-features all green.

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

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@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: ea8c394b-e72c-4550-84d5-77f44f07a573

📥 Commits

Reviewing files that changed from the base of the PR and between 6620e40 and 8f6d7a8.

📒 Files selected for processing (1)
  • crates/ourios-telemetry/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/ourios-telemetry/src/lib.rs

📝 Walkthrough

Walkthrough

Adds a new ourios-telemetry crate and registers it in the workspace. The crate provides configuration types, error and lifecycle management, an init() that wires an OTLP gRPC periodic exporter and global meter provider, a feature-gated in-memory init for tests, and a unit test for counter export.

Changes

OpenTelemetry Metrics Telemetry Module

Layer / File(s) Summary
Workspace & crate setup
Cargo.toml, crates/ourios-telemetry/Cargo.toml
Registers the new crate in the workspace and declares package metadata, dependencies for opentelemetry metrics, opentelemetry_sdk (metrics + rt-tokio), opentelemetry-otlp (grpc-tonic), a testing feature, dev-deps, and workspace lints.
Types, errors, and lifecycle management
crates/ourios-telemetry/src/lib.rs
Adds DEFAULT_EXPORT_INTERVAL, TelemetryConfig (service_name, otlp_endpoint, export_interval), TelemetryError (Exporter, Flush, Shutdown) and TelemetryGuard owning the SdkMeterProvider with shutdown(), force_flush(), and Drop. Includes a Resource helper.
Initialization pipeline and testing
crates/ourios-telemetry/src/lib.rs
Implements init() to build an OTLP gRPC MetricExporter, wrap it in a PeriodicReader with configured interval, attach Resource, install the provider globally, and return a guard. Adds init_in_memory() under testing and a tokio unit test that records and asserts exported metrics.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant init as init(config)
  participant OTLPExporter
  participant PeriodicReader
  participant MeterProvider
  participant GlobalRegistry
  
  Caller->>init: TelemetryConfig
  init->>OTLPExporter: build(endpoint, tonic)
  OTLPExporter-->>init: MetricExporter
  init->>PeriodicReader: wrap exporter + interval
  PeriodicReader-->>init: PeriodicReader
  init->>MeterProvider: new with reader + resource
  MeterProvider-->>init: SdkMeterProvider
  init->>GlobalRegistry: set_meter_provider()
  init-->>Caller: TelemetryGuard
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • jensholdgaard/ourios#103: Introduces the ourios-telemetry crate implementing OTLP push telemetry and related init/guard patterns.

Poem

🐰 I hopped in code to plant a stream,

OTLP dreams and counter gleam,
A guard to hold, a flush so neat,
Metrics march in steady beat,
📊✨ Hop, export, and then repeat.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: scaffolding a new ourios-telemetry crate for OTLP MeterProvider bootstrap.
Description check ✅ Passed The PR description is comprehensive and addresses all required template sections with detailed context, API design, scope, versions, and verification steps.
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-telemetry-scaffold

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

@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

Adds a new ourios-telemetry crate that centralizes the OpenTelemetry SDK + OTLP exporter setup, aligning with the RFC 0001 §6.8 dependency split (library crates use only the OTel API, while this crate owns the SDK/exporter stack).

Changes:

  • Introduces ourios-telemetry with TelemetryConfig, init() (OTLP push SdkMeterProvider), and TelemetryGuard shutdown/drop handling.
  • Adds testing-feature init_in_memory() to support in-memory metric export for tests.
  • Wires the new crate into the workspace members and lockfile.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/ourios-telemetry/src/lib.rs Implements OTLP MeterProvider bootstrap, guard-based shutdown, and an in-memory test pipeline + smoke test.
crates/ourios-telemetry/Cargo.toml Defines the new crate, its OTel dependencies/features, and workspace lint settings.
Cargo.toml Adds crates/ourios-telemetry to workspace members.
Cargo.lock Locks new transitive deps pulled in by OTLP/tonic exporter stack.

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

Comment thread crates/ourios-telemetry/src/lib.rs
Comment thread crates/ourios-telemetry/src/lib.rs
@jensholdgaard
jensholdgaard requested a review from Copilot June 3, 2026 17:45
@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 3 out of 4 changed files in this pull request and generated 1 comment.

Comment thread crates/ourios-telemetry/src/lib.rs Outdated
@jensholdgaard
jensholdgaard requested a review from Copilot June 3, 2026 17:52
@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 3 out of 4 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