Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ async fn run_extension(config: Arc<Config>, metrics: &mut ExtensionMetrics) -> R
// Set up telemetry components

// Create aggregator
let function_name = env::var("AWS_LAMBDA_FUNCTION_NAME").unwrap_or_else(|_| "unknown".to_string());
let aggregator = Arc::new(tokio::sync::Mutex::new(
telemetry::TelemetryAggregator::new(
config.max_buffer_size_bytes(),
100, // max batch entries
function_name,
)
));

Expand Down
9 changes: 6 additions & 3 deletions src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ pub struct TelemetryAggregator {
buffer: Vec<u8>,
max_content_size_bytes: usize,
max_batch_entries_size: usize,
function_name: String,
}

impl TelemetryAggregator {
pub fn new(max_content_size_bytes: usize, max_batch_entries_size: usize) -> Self {
pub fn new(max_content_size_bytes: usize, max_batch_entries_size: usize, function_name: String) -> Self {
Self {
messages: VecDeque::new(),
buffer: Vec::with_capacity(max_content_size_bytes),
max_content_size_bytes,
max_batch_entries_size,
function_name,
}
}

Expand All @@ -45,7 +47,8 @@ impl TelemetryAggregator {
let mut event_json = serde_json::json!({
"_timestamp": event.time.timestamp_micros(),
"record": event.record,
"type": event.event_type
"type": event.event_type,
"function_name": self.function_name
});

// Add requestId if present
Expand Down Expand Up @@ -261,7 +264,7 @@ mod tests {

#[test]
fn test_telemetry_aggregator() {
let mut aggregator = TelemetryAggregator::new(1024, 10);
let mut aggregator = TelemetryAggregator::new(1024, 10, "test-function".to_string());

let events = vec![
TelemetryEvent {
Expand Down