Skip to content

Commit 3b19fe7

Browse files
astuyveduncanista
andauthored
feat: honor serverless_logs (#475)
* feat: honor serverless_logs * fmt --------- Co-authored-by: jordan gonzález <[email protected]>
1 parent 891936a commit 3b19fe7

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

bottlecap/src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub struct Config {
8383
pub capture_lambda_payload_max_depth: u32,
8484
#[serde(deserialize_with = "deserialize_service_mapping")]
8585
pub service_mapping: HashMap<String, String>,
86+
pub serverless_logs_enabled: bool,
8687
// Trace Propagation
8788
#[serde(deserialize_with = "deserialize_trace_propagation_style")]
8889
pub trace_propagation_style: Vec<TracePropagationStyle>,
@@ -115,6 +116,7 @@ impl Default for Config {
115116
capture_lambda_payload: false,
116117
capture_lambda_payload_max_depth: 10,
117118
service_mapping: HashMap::new(),
119+
serverless_logs_enabled: true,
118120
// Trace Propagation
119121
trace_propagation_style: vec![
120122
TracePropagationStyle::Datadog,

bottlecap/src/logs/lambda/processor.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub struct LambdaProcessor {
3131
ready_logs: Vec<String>,
3232
// Main event bus
3333
event_bus: Sender<Event>,
34+
// Logs enabled
35+
logs_enabled: bool,
3436
}
3537

3638
const OOM_ERRORS: [&str; 7] = [
@@ -63,12 +65,14 @@ impl LambdaProcessor {
6365
let function_arn = tags_provider.get_canonical_id().unwrap_or_default();
6466

6567
let processing_rules = &datadog_config.logs_config_processing_rules;
68+
let logs_enabled = datadog_config.serverless_logs_enabled;
6669
let rules = LambdaProcessor::compile_rules(processing_rules);
6770
LambdaProcessor {
6871
function_arn,
6972
service,
7073
tags,
7174
rules,
75+
logs_enabled,
7276
invocation_context: InvocationContext::new(String::new(), 0.0, 0.0, 0, None),
7377
orphan_logs: Vec::new(),
7478
ready_logs: Vec::new(),
@@ -250,8 +254,8 @@ impl LambdaProcessor {
250254

251255
pub async fn process(&mut self, event: TelemetryEvent, aggregator: &Arc<Mutex<Aggregator>>) {
252256
if let Ok(mut log) = self.make_log(event).await {
253-
let should_send_log =
254-
LambdaProcessor::apply_rules(&self.rules, &mut log.message.message);
257+
let should_send_log = self.logs_enabled
258+
&& LambdaProcessor::apply_rules(&self.rules, &mut log.message.message);
255259
if should_send_log {
256260
if let Ok(serialized_log) = serde_json::to_string(&log) {
257261
// explicitly drop log so we don't accidentally re-use it and push
@@ -669,6 +673,42 @@ mod tests {
669673
assert_eq!(batch, serialized_log.as_bytes());
670674
}
671675

676+
#[tokio::test]
677+
async fn test_process_logs_disabled() {
678+
let aggregator = Arc::new(Mutex::new(Aggregator::default()));
679+
let config = Arc::new(config::Config {
680+
service: Some("test-service".to_string()),
681+
tags: Some("test:tags".to_string()),
682+
serverless_logs_enabled: false,
683+
..config::Config::default()
684+
});
685+
686+
let tags_provider = Arc::new(provider::Provider::new(
687+
Arc::clone(&config),
688+
LAMBDA_RUNTIME_SLUG.to_string(),
689+
&HashMap::from([("function_arn".to_string(), "test-arn".to_string())]),
690+
));
691+
692+
let (tx, _rx) = tokio::sync::mpsc::channel(2);
693+
694+
let mut processor =
695+
LambdaProcessor::new(Arc::clone(&tags_provider), Arc::clone(&config), tx.clone());
696+
697+
let event = TelemetryEvent {
698+
time: Utc.with_ymd_and_hms(2023, 1, 7, 3, 23, 47).unwrap(),
699+
record: TelemetryRecord::PlatformStart {
700+
request_id: "test-request-id".to_string(),
701+
version: Some("test".to_string()),
702+
},
703+
};
704+
705+
processor.process(event.clone(), &aggregator).await;
706+
707+
let mut aggregator_lock = aggregator.lock().unwrap();
708+
let batch = aggregator_lock.get_batch();
709+
assert_eq!(batch.len(), 0);
710+
}
711+
672712
#[tokio::test]
673713
async fn test_process_log_with_no_request_id() {
674714
let aggregator = Arc::new(Mutex::new(Aggregator::default()));

0 commit comments

Comments
 (0)