Skip to content

Commit 6702e86

Browse files
sshaderConvex, Inc.
authored and
Convex, Inc.
committed
Add a hidden V2 for datadog and axiom log sinks (#24954)
This is a refactor for introducing a new event format for datadog and axiom log sinks. GitOrigin-RevId: da47af1b65e16533ebeb770a4cf9e1b1cf0a805e
1 parent 3d5f7a0 commit 6702e86

File tree

4 files changed

+404
-219
lines changed

4 files changed

+404
-219
lines changed

crates/application/src/function_log.rs

Lines changed: 37 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ use common::{
2525
LogLines,
2626
},
2727
log_streaming::{
28-
EventSource,
28+
self,
2929
FunctionEventSource,
3030
LogEvent,
3131
LogSender,
32-
LogTopic,
32+
StructuredLogEvent,
3333
},
3434
runtime::{
3535
Runtime,
@@ -212,68 +212,47 @@ impl FunctionExecution {
212212
LogLine::Unstructured(_) => self.unix_timestamp,
213213
LogLine::Structured { timestamp, .. } => *timestamp,
214214
};
215-
let JsonValue::Object(payload) = json!({
216-
"message": line.clone().to_pretty_string()
217-
}) else {
218-
anyhow::bail!("could not create JSON object");
219-
};
220-
Ok::<_, anyhow::Error>(LogEvent {
221-
topic: LogTopic::Console,
222-
source: EventSource::Function(self.event_source()),
223-
payload,
215+
LogEvent {
224216
timestamp,
225-
})
226-
})
227-
.filter_map(|event| match event {
228-
Err(mut e) => {
229-
tracing::error!("Dropping log event due to failed payload conversion: {e:?}");
230-
report_error(&mut e);
231-
None
232-
},
233-
Ok(ev) => Some(ev),
217+
event: StructuredLogEvent::Console {
218+
source: self.event_source(),
219+
log_line: line.clone(),
220+
},
221+
}
234222
})
235223
.collect()
236224
}
237225

238226
fn udf_execution_record_log_events(&self) -> anyhow::Result<Vec<LogEvent>> {
239-
let execution_time: u64 = Duration::from_secs_f64(self.execution_time)
240-
.as_millis()
241-
.try_into()?;
242-
let (reason, status) = match self.params.err() {
243-
Some(err) => (json!(err.to_string()), "failure"),
244-
None => (JsonValue::Null, "success"),
245-
};
246-
247-
let JsonValue::Object(payload) = json!({
248-
"status": status,
249-
"reason": reason,
250-
"executionTimeMs": execution_time,
251-
"databaseReadBytes": self.usage_stats.database_read_bytes,
252-
"databaseWriteBytes": self.usage_stats.database_write_bytes,
253-
"storageReadBytes": self.usage_stats.storage_read_bytes,
254-
"storageWriteBytes": self.usage_stats.storage_write_bytes,
255-
}) else {
256-
anyhow::bail!("could not create JSON object for UdfExecutionRecord");
257-
};
227+
let execution_time = Duration::from_secs_f64(self.execution_time);
258228

259229
let mut events = vec![LogEvent {
260-
topic: LogTopic::UdfExecutionRecord,
261230
timestamp: self.unix_timestamp,
262-
source: EventSource::Function(self.event_source()),
263-
payload,
231+
event: StructuredLogEvent::FunctionExecution {
232+
source: self.event_source(),
233+
error: self.params.err().cloned(),
234+
execution_time,
235+
usage_stats: log_streaming::AggregatedFunctionUsageStats {
236+
database_read_bytes: self.usage_stats.database_read_bytes,
237+
database_write_bytes: self.usage_stats.database_write_bytes,
238+
storage_read_bytes: self.usage_stats.storage_read_bytes,
239+
storage_write_bytes: self.usage_stats.storage_write_bytes,
240+
vector_index_read_bytes: self.usage_stats.vector_index_read_bytes,
241+
vector_index_write_bytes: self.usage_stats.vector_index_write_bytes,
242+
},
243+
},
264244
}];
265245

266246
if let Some(err) = self.params.err() {
267-
events.push(LogEvent::construct_exception(
268-
err,
269-
self.unix_timestamp,
270-
EventSource::Function(self.event_source()),
271-
self.udf_server_version
272-
.as_ref()
273-
.map(|v| v.to_string())
274-
.as_deref(),
275-
&self.identity,
276-
)?);
247+
events.push(LogEvent {
248+
timestamp: self.unix_timestamp,
249+
event: StructuredLogEvent::Exception {
250+
error: err.clone(),
251+
user_identifier: self.identity.user_identifier().cloned(),
252+
source: self.event_source(),
253+
udf_server_version: self.udf_server_version.clone(),
254+
},
255+
});
277256
}
278257

279258
Ok(events)
@@ -304,25 +283,13 @@ impl FunctionExecutionProgress {
304283
LogLine::Unstructured(_) => self.function_start_timestamp,
305284
LogLine::Structured { timestamp, .. } => *timestamp,
306285
};
307-
let JsonValue::Object(payload) = json!({
308-
"message": line.to_pretty_string()
309-
}) else {
310-
anyhow::bail!("could not create JSON object");
311-
};
312-
Ok::<_, anyhow::Error>(LogEvent {
313-
topic: LogTopic::Console,
314-
source: EventSource::Function(self.event_source.clone()),
315-
payload,
286+
LogEvent {
316287
timestamp,
317-
})
318-
})
319-
.filter_map(|event| match event {
320-
Err(mut e) => {
321-
tracing::error!("Dropping log event due to failed payload conversion: {e:?}");
322-
report_error(&mut e);
323-
None
324-
},
325-
Ok(ev) => Some(ev),
288+
event: StructuredLogEvent::Console {
289+
source: self.event_source.clone(),
290+
log_line: line,
291+
},
292+
}
326293
})
327294
.collect()
328295
}

0 commit comments

Comments
 (0)