Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ pub struct TrafficConfig {
log_weight: u32,

/// Target size of each log record body in bytes (Static data source only).
/// When set, generates a log body string of approximately this size.
/// When unset, uses the default hardcoded body ("Order processed successfully").
/// When set, pre-generates a pool of 50 distinct body strings of this size;
/// records cycle through the pool for realistic dictionary cardinality.
/// When 0, the body is omitted entirely.
/// When unset, cycles through ~50 default log message templates.
#[serde(default)]
log_body_size_bytes: Option<usize>,

Expand All @@ -165,6 +167,11 @@ pub struct TrafficConfig {
/// When unset, uses the default 2 attributes (thread.id, thread.name).
#[serde(default)]
num_log_attributes: Option<usize>,

/// When true, each log record gets a unique random trace_id and span_id,
/// matching real log-to-trace correlation and adding per-record entropy.
#[serde(default)]
use_trace_context: bool,
}

impl Config {
Expand Down Expand Up @@ -282,6 +289,7 @@ impl TrafficConfig {
log_weight,
log_body_size_bytes: None,
num_log_attributes: None,
use_trace_context: false,
}
}

Expand Down Expand Up @@ -359,6 +367,12 @@ impl TrafficConfig {
pub const fn num_log_attributes(&self) -> Option<usize> {
self.num_log_attributes
}

/// Returns whether log records should include trace_id and span_id.
#[must_use]
pub const fn use_trace_context(&self) -> bool {
self.use_trace_context
}
}

const fn default_signals_per_second() -> Option<usize> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ enum SignalGenerator {
log_body_size_bytes: Option<usize>,
/// Number of log attributes (None = default attributes)
num_log_attributes: Option<usize>,
/// Whether to populate trace_id/span_id on log records
use_trace_context: bool,
},
}

Expand Down Expand Up @@ -172,11 +174,13 @@ impl SignalGenerator {
SignalGenerator::Static {
log_body_size_bytes,
num_log_attributes,
use_trace_context,
..
} => OtlpProtoMessage::Logs(static_signal::static_otlp_logs_with_config(
count,
*log_body_size_bytes,
*num_log_attributes,
*use_trace_context,
self.attrs_for_batch(batch_index),
)),
}
Expand Down Expand Up @@ -300,6 +304,7 @@ impl local::Receiver<OtapPdata> for FakeGeneratorReceiver {
rotation,
log_body_size_bytes: traffic_config.log_body_size_bytes(),
num_log_attributes: traffic_config.num_log_attributes(),
use_trace_context: traffic_config.use_trace_context(),
}
}
};
Expand Down Expand Up @@ -1364,6 +1369,7 @@ mod tests {
rotation,
log_body_size_bytes: None,
num_log_attributes: None,
use_trace_context: false,
};

// attrs_for_batch should rotate through the two sets
Expand Down Expand Up @@ -1417,6 +1423,7 @@ mod tests {
rotation: vec![],
log_body_size_bytes: None,
num_log_attributes: None,
use_trace_context: false,
};
assert!(generator.attrs_for_batch(0).is_none());
assert!(generator.attrs_for_batch(1).is_none());
Expand Down
Loading
Loading