Skip to content

Commit 0362502

Browse files
committed
add panic error when multiple HTTP features are enabled
1 parent 8882c31 commit 0362502

File tree

1 file changed

+24
-0
lines changed
  • opentelemetry-otlp/src/exporter/http

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ impl HttpExporterBuilder {
161161
.unwrap(), // TODO: Return ExporterBuildError::ThreadSpawnFailed
162162
) as Arc<dyn HttpClient>);
163163
}
164+
#[cfg(any(
165+
all(feature = "hyper-client", feature = "reqwest-client"),
166+
all(feature = "hyper-client", feature = "reqwest-blocking-client"),
167+
all(feature = "reqwest-client", feature = "reqwest-blocking-client")
168+
))]
169+
{
170+
panic!("Can't enable more than one HTTP client features simultaneously. Please choose only one: hyper-client, reqwest-client, or reqwest-blocking-client (default feature)");
171+
}
164172
}
165173

166174
let http_client = http_client.ok_or(ExporterBuildError::NoHttpClient)?;
@@ -741,4 +749,20 @@ mod tests {
741749
assert_eq!(url, "http://localhost:4318/v1/tracesbutnotreally");
742750
});
743751
}
752+
753+
#[cfg(any(
754+
all(feature = "hyper-client", feature = "reqwest-client"),
755+
all(feature = "hyper-client", feature = "reqwest-blocking-client"),
756+
all(feature = "reqwest-client", feature = "reqwest-blocking-client")
757+
))]
758+
#[test]
759+
#[should_panic(expected = "Can't enable more than one HTTP client features simultaneously.")]
760+
fn test_http_exporter_builder_panics_with_multiple_http_features() {
761+
let mut builder = HttpExporterBuilder {
762+
http_config: HttpConfig::default(),
763+
exporter_config: crate::ExportConfig::default(),
764+
};
765+
766+
let _ = builder.build_client("ENV_VAR_1", "PATH", "ENV_VAR_2", "ENV_VAR_3");
767+
}
744768
}

0 commit comments

Comments
 (0)