Skip to content

[ENH]: add metrics for span & metric exporters #5223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025

Conversation

codetheweb
Copy link
Contributor

@codetheweb codetheweb commented Aug 7, 2025

Description of changes

This adds new metrics for the total # of span & metric batches exported and segments the metrics based on success/error. This will help us be aware of when services drop spans/metrics.

Test plan

How are these changes tested?

I tested locally in Tilt by adding a 8MB test span and observing that the counter for span export errors was incremented.

Migration plan

Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?

Observability plan

What is the plan to instrument and monitor this change?

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?

Copy link

github-actions bot commented Aug 7, 2025

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Copy link
Contributor

propel-code-bot bot commented Aug 7, 2025

Add Metrics for Span & Metric Exporters with Success/Error Segmentation

This PR introduces new OpenTelemetry metrics to track the total number of span and metric batches exported, segmented by success and error status. Two wrapper structs (WrappedSpanExporter and WrappedMetricExporter) are implemented to instrument the relevant exporters, enabling real-time observability into exporter success/failure events and exposing error types as metric labels. Integration points in the initialization logic (init_tracer.rs) instantiate these wrappers in place of raw exporters. Various supporting changes update Cargo dependencies and the project module structure for the added wrappers.

Key Changes

• Added wrapped_span_exporter`.rs` and wrapped_metric_exporter.rs implementing wrappers for exporters with metrics counters.
• Instrumented exporters increment success or error counters with error details (as a metric label) on each export attempt.
• Updated init_tracer`.rs` to use the new wrapper types for both tracing and metrics exporters. • Modified module exports and imports in `lib.rs` and init_tracer.rs to include new wrappers.
• Added async-trait and futures as dependencies in Cargo.toml and Cargo.lock.

Affected Areas

• rust/tracing/src/init_tracer.rs
• rust/tracing/src/lib.rs
• rust/tracing/src/wrapped_span_exporter.rs
• rust/tracing/src/wrapped_metric_exporter.rs
• Cargo.toml
• Cargo.lock

This summary was automatically generated by @propel-code-bot

@codetheweb codetheweb force-pushed the feat-tracing-metric-exporter-metrics branch from 8161297 to d8de3e1 Compare August 7, 2025 16:50
@codetheweb codetheweb force-pushed the feat-tracing-metric-exporter-metrics branch from d8de3e1 to 1426081 Compare August 7, 2025 16:57
@codetheweb codetheweb requested a review from sanketkedia August 7, 2025 16:57
Comment on lines +47 to +64
Err(err) => {
let error_name = match err {
opentelemetry_sdk::metrics::MetricError::Other(_) => "other",
opentelemetry_sdk::metrics::MetricError::Config(_) => "config",
opentelemetry_sdk::metrics::MetricError::ExportErr(_) => "export_failed",
opentelemetry_sdk::metrics::MetricError::InvalidInstrumentConfiguration(_) => {
"invalid_instrument_configuration"
}
_ => "unknown",
};
counter.add(
1,
&[
KeyValue::new("status", "error"),
KeyValue::new("error", error_name.to_string()),
],
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[PerformanceOptimization]

A couple of small improvements here:

  1. The braces around "invalid_instrument_configuration" are not necessary.
  2. error_name is a &'static str, which can be converted into an opentelemetry::Value directly. Calling .to_string() creates an unnecessary heap allocation. You can pass error_name to KeyValue::new directly.

@codetheweb codetheweb merged commit a0c352b into main Aug 7, 2025
59 checks passed
@codetheweb codetheweb deleted the feat-tracing-metric-exporter-metrics branch August 7, 2025 23:56
codetheweb added a commit that referenced this pull request Aug 8, 2025
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