Skip to content

Conversation

@houseme
Copy link
Contributor

@houseme houseme commented Nov 13, 2025

Type of Change

  • New Feature
  • Bug Fix
  • Documentation
  • Performance Improvement
  • Test/CI
  • Refactor
  • Other:

Related Issues

Summary of Changes

Summary

This PR refactors telemetry.rs to eliminate a double-consumption of the OTLP MetricExporter that triggered Rust error E0382 (value used after move). Metrics initialization is now performed through a single Recorder::builder path, avoiding redundant global installs.

Key Changes

  • Removed the pre-built MeterProviderBuilder path that consumed the exporter prematurely.
  • Added exporter and optional stdout PeriodicReader inside the Recorder::builder(...).with_meter_provider closure.
  • Removed duplicate Recorder::builder(...).install_global() invocation.
  • Ensured global::set_meter_provider and metrics::set_global_recorder are called exactly once.
  • Reused the same Resource instance across tracing, metrics, and logging.
  • Kept logging/tracing behavior unchanged.

Fixes

  • Resolves exporter move error (E0382).
  • Prevents accidental double registration of metrics recorder.

Files Affected

  • crates/obs/src/telemetry.rs

No Behavior Regression

Startup counters and feature flags (OBSERVABILITY_METRIC_ENABLED) remain intact.

Testing

Existing tests pass (recorder.rs and telemetry config tests). No new tests required as logic consolidation is internal.

Next Steps

Optional: add integration test asserting single metric export pipeline creation.


Checklist

  • I have read and followed the CONTRIBUTING.md guidelines
  • Passed make pre-commit
  • Added/updated necessary tests
  • Documentation updated (if needed)
  • CI/CD passed (if applicable)

Impact

  • Breaking change (compatibility)
  • Requires doc/config/deployment update
  • Other impact:

Additional Notes


Thank you for your contribution! Please ensure your PR follows the community standards (CODE_OF_CONDUCT.md) and sign the CLA if this is your first contribution.

- Fix Rust E0382 (use after move) by removing duplicate MetricExporter consumption.
- Consolidate MeterProvider construction into single Recorder builder path.
- Remove redundant Recorder::builder(...).install_global() call.
- Ensure PeriodicReader setup is performed only once (HTTP + optional stdout).
- Set global meter provider and metrics recorder exactly once.
- Preserve existing behavior for stdout/file vs HTTP modes.
- Minor cleanup: consistent resource reuse and interval handling.
@houseme houseme requested a review from Copilot November 13, 2025 11:17
@github-actions
Copy link

github-actions bot commented Nov 13, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

  • Cargo.lock

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the observability crate to fix a Rust move error (E0382) in metrics initialization by replacing the external metrics-exporter-opentelemetry dependency with a custom Recorder implementation. The refactoring consolidates metric initialization into a single builder pattern, eliminating duplicate global recorder installations.

Key changes:

  • Introduced a custom Recorder implementation with a builder pattern for unified metrics setup
  • Refactored metrics initialization to use Recorder::builder().with_meter_provider() closure, preventing exporter double-consumption
  • Renamed IS_OBSERVABILITY_ENABLED to OBSERVABILITY_METRIC_ENABLED for better clarity

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/obs/src/recorder.rs New custom Recorder implementation with builder pattern for OpenTelemetry metrics integration
crates/obs/src/telemetry.rs Refactored metrics initialization to use new Recorder builder, preventing exporter move error; simplified logging configuration
crates/obs/src/error.rs Moved GlobalError enum from global.rs to dedicated error module with new SetRecorder variant
crates/obs/src/global.rs Renamed observability flag and function; moved error types to separate module
crates/obs/src/system/mod.rs Updated function call to use renamed observability_metric_enabled()
crates/obs/src/lib.rs Added exports for new recorder and error modules
crates/obs/Cargo.toml Removed metrics-exporter-opentelemetry dependency
Cargo.toml Removed metrics-exporter-opentelemetry from workspace dependencies
Cargo.lock Updated lock file to reflect dependency removal and cleanup unused transitive dependencies

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

houseme and others added 2 commits November 13, 2025 19:23
Copy link
Contributor

Copilot AI left a comment

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 7 comments.


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

Copy link
Contributor

Copilot AI left a comment

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 5 comments.


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

@houseme houseme merged commit 5158498 into main Nov 13, 2025
16 checks passed
@houseme houseme deleted the fix/obs-metrics-1112 branch November 13, 2025 16:50
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.

1 participant