Skip to content
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

feat: OTLP Exporter builders to return specific Error type #2790

Merged

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Mar 12, 2025

Fixes #2561

Also removes now unused Error enum from Log SDK. Another set of cleanup required to clean Metrics, Traces completely.
Also, the newly introduced enum ExporterBuildError is not fully refined, this can be done in follow ups. This is necessary to unblock Log SDK Stable Release.

Note: This is a breaking change for OTLP Exporter, however, the impact is minimal (most users/examples simply unwrap/expect the Result instead of matching on it.), as described in the changelog, so I propose to make the change even though OTLP Exporter is marked RC.

Verified

This commit was signed with the committer’s verified signature.
nakatanakatana nakatanakatana

Verified

This commit was signed with the committer’s verified signature.
nakatanakatana nakatanakatana
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 74.32432% with 19 lines in your changes missing coverage. Please review.

Project coverage is 80.2%. Comparing base (ddac8e1) to head (d131ea7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-otlp/src/exporter/http/mod.rs 68.0% 8 Missing ⚠️
opentelemetry-otlp/src/exporter/mod.rs 90.9% 3 Missing ⚠️
opentelemetry-otlp/src/exporter/tonic/mod.rs 66.6% 3 Missing ⚠️
opentelemetry-otlp/src/metric.rs 0.0% 2 Missing ⚠️
opentelemetry-otlp/src/span.rs 0.0% 2 Missing ⚠️
opentelemetry-otlp/src/exporter/http/logs.rs 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2790     +/-   ##
=======================================
+ Coverage   79.6%   80.2%   +0.5%     
=======================================
  Files        124     123      -1     
  Lines      23315   23334     +19     
=======================================
+ Hits       18582   18720    +138     
+ Misses      4733    4614    -119     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
suzuki-shunsuke Shunsuke Suzuki

Verified

This commit was signed with the committer’s verified signature. The key has expired.
suzuki-shunsuke Shunsuke Suzuki
@cijothomas cijothomas requested a review from Copilot March 12, 2025 06:11
Copy link

@Copilot 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 OTLP Exporter builders to return a well-defined error type (ExporterBuildError) instead of a generic or signal‐specific error, thereby improving error handling clarity and consistency. It also removes an unused Error enum from the Log SDK and updates tests, examples, and changelogs to reflect these breaking changes.

  • Update error type definitions and conversions across tonic and http exporters.
  • Remove the unused Log SDK error enum.
  • Adjust tests, examples, and changelogs to document the breaking changes.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
opentelemetry-otlp/src/exporter/tonic/mod.rs Updated error conversions and function signatures to use ExporterBuildError.
opentelemetry-otlp/src/exporter/mod.rs Updated error handling in trait implementations and FromStr.
opentelemetry-otlp/src/exporter/http/mod.rs Switched error type to ExporterBuildError and added a TODO for thread-spawn handling.
opentelemetry-sdk/CHANGELOG.md & opentelemetry-otlp/CHANGELOG.md Documented breaking changes for the new error handling approach.
Various exporter and span modules, examples, and tests Modified build functions and tests to accommodate the updated error type.
Comments suppressed due to low confidence (1)

opentelemetry-otlp/src/exporter/http/mod.rs:171

  • Consider handling errors from thread spawning instead of using unwrap, to prevent potential panics. Propagate a proper ExporterBuildError instead of unwrapping the thread result.
.join().unwrap(), // TODO: Return ExporterBuildError::ThreadSpawnFailed

Verified

This commit was signed with the committer’s verified signature. The key has expired.
suzuki-shunsuke Shunsuke Suzuki
Copy link
Contributor

@pitoniak32 pitoniak32 left a comment

Choose a reason for hiding this comment

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

I just took a brief look, and overall I agree with these changes and think its a good direction to go.

the only small comment I have currently is asserting the errors are of the expected variant for the builder errors

@cijothomas
Copy link
Member Author

comment I have currently is asserting the errors are of the expected variant for the builder errors

Thanks. I expect to add more tests in a follow up. Tests require some combinations of feature flags to ensure it validates what we want it to validate!
(I just added a basic test in this PR).

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
use opentelemetry_sdk::Resource;

use std::error::Error;

fn init_tracer_provider() -> Result<opentelemetry_sdk::trace::SdkTracerProvider, TraceError> {
fn init_tracer_provider() -> Result<opentelemetry_sdk::trace::SdkTracerProvider, ExporterBuildError>
Copy link
Contributor

Choose a reason for hiding this comment

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

unintended change for the {?

pub enum ExporterBuildError {
/// Spawning a new thread failed.
#[error("Spawning a new thread failed. Unable to create Reqwest-Blocking client.")]
ThreadSpawnFailed,
Copy link
Contributor

Choose a reason for hiding this comment

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

This will only happens if reqwest-blocking is used right? If so can we guard it in feature flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, thats why I put a big TODO on this. we definitely need to refine it and see which ones makes sense and remove others.


/// Feature required to use the specified compression algorithm.
#[cfg(any(not(feature = "gzip-tonic"), not(feature = "zstd-tonic")))]
#[error("feature '{0}' is required to use the compression algorithm '{1}'")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm looks like a little bit inconsistent if the first letter is upper case across the variant?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes will address them in follow ups.

Copy link
Contributor

@TommyCpp TommyCpp left a comment

Choose a reason for hiding this comment

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

Nothing blocking. LGTM once the comments are addressed

@cijothomas cijothomas merged commit 8872bf8 into open-telemetry:main Mar 14, 2025
22 of 23 checks passed
@cijothomas cijothomas deleted the cijothomas/otlp-error-return branch March 14, 2025 15:22
Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM - Spent some time to review, and realized it is merged meanwhile :)

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.

Should OTLP Exporter Error enum be public and visible to the processor?
4 participants