-
Notifications
You must be signed in to change notification settings - Fork 485
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
Enable reqwest and reqwest-blocking client creation with custom timeout #2584
Merged
cijothomas
merged 11 commits into
open-telemetry:main
from
lalitb:otel-otlp-http-timeout
Feb 3, 2025
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2a82f5f
create blocking within thread
lalitb 01b0f48
Merge branch 'main' into otel-otlp-http-timeout
cijothomas 0d16ade
lint error
lalitb 91e9942
Merge branch 'otel-otlp-http-timeout' of github.com:lalitb/openteleme…
lalitb 24a6f4f
Remove commented error handling in HTTP exporter
lalitb ff7c9c0
add changelog
lalitb 4deb02a
Fix punctuation in CHANGELOG.md
lalitb 4957840
Merge branch 'main' into otel-otlp-http-timeout
lalitb 1b68aea
update timeout in changelog
lalitb 033835d
Merge branch 'main' into otel-otlp-http-timeout
cijothomas ed14fff
Merge branch 'main' into otel-otlp-http-timeout
cijothomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,15 +44,7 @@ | |
use opentelemetry_http::hyper::HyperClient; | ||
|
||
/// Configuration of the http transport | ||
#[derive(Debug)] | ||
#[cfg_attr( | ||
all( | ||
not(feature = "reqwest-client"), | ||
not(feature = "reqwest-blocking-client"), | ||
not(feature = "hyper-client") | ||
), | ||
derive(Default) | ||
)] | ||
#[derive(Debug, Default)] | ||
pub struct HttpConfig { | ||
/// Select the HTTP client | ||
client: Option<Arc<dyn HttpClient>>, | ||
|
@@ -61,44 +53,6 @@ | |
headers: Option<HashMap<String, String>>, | ||
} | ||
|
||
#[cfg(any( | ||
feature = "reqwest-blocking-client", | ||
feature = "reqwest-client", | ||
feature = "hyper-client" | ||
))] | ||
impl Default for HttpConfig { | ||
fn default() -> Self { | ||
#[cfg(feature = "reqwest-blocking-client")] | ||
let default_client = std::thread::spawn(|| { | ||
Some(Arc::new(reqwest::blocking::Client::new()) as Arc<dyn HttpClient>) | ||
}) | ||
.join() | ||
.expect("creating reqwest::blocking::Client on a new thread not to fail"); | ||
#[cfg(all(not(feature = "reqwest-blocking-client"), feature = "reqwest-client"))] | ||
let default_client = Some(Arc::new(reqwest::Client::new()) as Arc<dyn HttpClient>); | ||
#[cfg(all( | ||
not(feature = "reqwest-client"), | ||
not(feature = "reqwest-blocking-client"), | ||
feature = "hyper-client" | ||
))] | ||
// TODO - support configuring custom connector and executor | ||
let default_client = Some(Arc::new(HyperClient::with_default_connector( | ||
Duration::from_secs(10), | ||
None, | ||
)) as Arc<dyn HttpClient>); | ||
#[cfg(all( | ||
not(feature = "reqwest-client"), | ||
not(feature = "reqwest-blocking-client"), | ||
not(feature = "hyper-client") | ||
))] | ||
let default_client = None; | ||
HttpConfig { | ||
client: default_client, | ||
headers: None, | ||
} | ||
} | ||
} | ||
|
||
/// Configuration for the OTLP HTTP exporter. | ||
/// | ||
/// ## Examples | ||
|
@@ -171,11 +125,56 @@ | |
}, | ||
None => self.exporter_config.timeout, | ||
}; | ||
let http_client = self | ||
.http_config | ||
.client | ||
.take() | ||
.ok_or(crate::Error::NoHttpClient)?; | ||
|
||
#[allow(unused_mut)] // TODO - clippy thinks mut is not needed, but it is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is another issue about parsing env variables for timeout, I opened #2591 to track it separate from this PR |
||
let mut http_client = self.http_config.client.take(); | ||
|
||
if http_client.is_none() { | ||
#[cfg(all( | ||
not(feature = "reqwest-client"), | ||
not(feature = "reqwest-blocking-client"), | ||
feature = "hyper-client" | ||
))] | ||
{ | ||
// TODO - support configuring custom connector and executor | ||
http_client = Some(Arc::new(HyperClient::with_default_connector(timeout, None)) | ||
as Arc<dyn HttpClient>); | ||
} | ||
#[cfg(all( | ||
not(feature = "hyper-client"), | ||
not(feature = "reqwest-blocking-client"), | ||
feature = "reqwest-client" | ||
))] | ||
{ | ||
http_client = Some(Arc::new( | ||
reqwest::Client::builder() | ||
.timeout(timeout) | ||
.build() | ||
.unwrap_or_default(), | ||
) as Arc<dyn HttpClient>); | ||
} | ||
#[cfg(all( | ||
not(feature = "hyper-client"), | ||
not(feature = "reqwest-client"), | ||
feature = "reqwest-blocking-client" | ||
))] | ||
{ | ||
let timeout_clone = timeout; | ||
http_client = Some(Arc::new( | ||
std::thread::spawn(move || { | ||
reqwest::blocking::Client::builder() | ||
.timeout(timeout_clone) | ||
.build() | ||
.unwrap_or_else(|_| reqwest::blocking::Client::new()) | ||
}) | ||
.join() | ||
.unwrap(), // Unwrap thread result | ||
) as Arc<dyn HttpClient>); | ||
} | ||
} | ||
|
||
let http_client = http_client.ok_or(crate::Error::NoHttpClient)?; | ||
|
||
#[allow(clippy::mutable_key_type)] // http headers are not mutated | ||
let mut headers: HashMap<HeaderName, HeaderValue> = self | ||
.http_config | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/open-telemetry/opentelemetry-specification/blob/714b1ae1382ba57850f29ee94b854b2aa7d1be83/specification/protocol/exporter.md?plain=1#L67 should it be 10 instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. It's indeed 10sec. Have update the changelog accordingly.
opentelemetry-rust/opentelemetry-otlp/src/exporter/mod.rs
Line 55 in dde68a0