Skip to content

Commit 8d2016b

Browse files
gruebelcijothomas
authored andcommitted
test: validate code based config is preferrred over env vars in trace BatchConfig (open-telemetry#2809)
1 parent fe2d6e4 commit 8d2016b

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

opentelemetry-sdk/src/trace/span_processor.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ impl Default for BatchConfigBuilder {
704704
/// * `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
705705
/// * `OTEL_BSP_EXPORT_TIMEOUT`
706706
/// * `OTEL_BSP_MAX_CONCURRENT_EXPORTS`
707+
///
708+
/// Note: Programmatic configuration overrides any value set via the environment variable.
707709
fn default() -> Self {
708710
BatchConfigBuilder {
709711
max_queue_size: OTEL_BSP_MAX_QUEUE_SIZE_DEFAULT,
@@ -720,7 +722,11 @@ impl BatchConfigBuilder {
720722
/// Set max_queue_size for [`BatchConfigBuilder`].
721723
/// It's the maximum queue size to buffer spans for delayed processing.
722724
/// If the queue gets full it will drops the spans.
723-
/// The default value of is 2048.
725+
/// The default value is 2048.
726+
///
727+
/// Corresponding environment variable: `OTEL_BSP_MAX_QUEUE_SIZE`.
728+
///
729+
/// Note: Programmatically setting this will override any value set via the environment variable.
724730
pub fn with_max_queue_size(mut self, max_queue_size: usize) -> Self {
725731
self.max_queue_size = max_queue_size;
726732
self
@@ -731,6 +737,10 @@ impl BatchConfigBuilder {
731737
/// more than one batch worth of spans then it processes multiple batches
732738
/// of spans one batch after the other without any delay. The default value
733739
/// is 512.
740+
///
741+
/// Corresponding environment variable: `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`.
742+
///
743+
/// Note: Programmatically setting this will override any value set via the environment variable.
734744
pub fn with_max_export_batch_size(mut self, max_export_batch_size: usize) -> Self {
735745
self.max_export_batch_size = max_export_batch_size;
736746
self
@@ -743,6 +753,11 @@ impl BatchConfigBuilder {
743753
/// The default value is 1.
744754
/// If the max_concurrent_exports value is default value, it will cause exports to be performed
745755
/// synchronously on the BatchSpanProcessor task.
756+
/// The default value is 1.
757+
///
758+
/// Corresponding environment variable: `OTEL_BSP_MAX_CONCURRENT_EXPORTS`.
759+
///
760+
/// Note: Programmatically setting this will override any value set via the environment variable.
746761
pub fn with_max_concurrent_exports(mut self, max_concurrent_exports: usize) -> Self {
747762
self.max_concurrent_exports = max_concurrent_exports;
748763
self
@@ -751,6 +766,10 @@ impl BatchConfigBuilder {
751766
/// Set scheduled_delay_duration for [`BatchConfigBuilder`].
752767
/// It's the delay interval in milliseconds between two consecutive processing of batches.
753768
/// The default value is 5000 milliseconds.
769+
///
770+
/// Corresponding environment variable: `OTEL_BSP_SCHEDULE_DELAY`.
771+
///
772+
/// Note: Programmatically setting this will override any value set via the environment variable.
754773
pub fn with_scheduled_delay(mut self, scheduled_delay: Duration) -> Self {
755774
self.scheduled_delay = scheduled_delay;
756775
self
@@ -759,6 +778,10 @@ impl BatchConfigBuilder {
759778
/// Set max_export_timeout for [`BatchConfigBuilder`].
760779
/// It's the maximum duration to export a batch of data.
761780
/// The The default value is 30000 milliseconds.
781+
///
782+
/// Corresponding environment variable: `OTEL_BSP_EXPORT_TIMEOUT`.
783+
///
784+
/// Note: Programmatically setting this will override any value set via the environment variable.
762785
#[cfg(feature = "experimental_trace_batch_span_processor_with_async_runtime")]
763786
pub fn with_max_export_timeout(mut self, max_export_timeout: Duration) -> Self {
764787
self.max_export_timeout = max_export_timeout;
@@ -932,6 +955,40 @@ mod tests {
932955
);
933956
}
934957

958+
#[test]
959+
fn test_code_based_config_overrides_env_vars() {
960+
let env_vars = vec![
961+
(OTEL_BSP_EXPORT_TIMEOUT, Some("60000")),
962+
(OTEL_BSP_MAX_CONCURRENT_EXPORTS, Some("5")),
963+
(OTEL_BSP_MAX_EXPORT_BATCH_SIZE, Some("1024")),
964+
(OTEL_BSP_MAX_QUEUE_SIZE, Some("4096")),
965+
(OTEL_BSP_SCHEDULE_DELAY, Some("2000")),
966+
];
967+
968+
temp_env::with_vars(env_vars, || {
969+
let config = BatchConfigBuilder::default()
970+
.with_max_export_batch_size(512)
971+
.with_max_queue_size(2048)
972+
.with_scheduled_delay(Duration::from_millis(1000));
973+
#[cfg(feature = "experimental_trace_batch_span_processor_with_async_runtime")]
974+
let config = {
975+
config
976+
.with_max_concurrent_exports(10)
977+
.with_max_export_timeout(Duration::from_millis(2000))
978+
};
979+
let config = config.build();
980+
981+
assert_eq!(config.max_export_batch_size, 512);
982+
assert_eq!(config.max_queue_size, 2048);
983+
assert_eq!(config.scheduled_delay, Duration::from_millis(1000));
984+
#[cfg(feature = "experimental_trace_batch_span_processor_with_async_runtime")]
985+
{
986+
assert_eq!(config.max_concurrent_exports, 10);
987+
assert_eq!(config.max_export_timeout, Duration::from_millis(2000));
988+
}
989+
});
990+
}
991+
935992
#[test]
936993
fn test_batch_config_configurable_by_env_vars() {
937994
let env_vars = vec![

0 commit comments

Comments
 (0)