@@ -16,8 +16,10 @@ use common::{
1616 Json ,
1717 Query ,
1818 } ,
19+ ExtractClientVersion ,
1920 HttpResponseError ,
2021 } ,
22+ version:: ClientType ,
2123 RequestId ,
2224} ;
2325use errors:: ErrorMetadata ;
@@ -45,7 +47,7 @@ pub enum FunctionExecutionJson {
4547 Completion {
4648 udf_type : String ,
4749 identifier : String ,
48- log_lines : Vec < String > ,
50+ log_lines : Vec < JsonValue > ,
4951 timestamp : f64 ,
5052 cached_result : bool ,
5153 execution_time : f64 ,
@@ -59,7 +61,7 @@ pub enum FunctionExecutionJson {
5961 udf_type : String ,
6062 identifier : String ,
6163 timestamp : f64 ,
62- log_lines : Vec < String > ,
64+ log_lines : Vec < JsonValue > ,
6365 request_id : String ,
6466 execution_id : String ,
6567 } ,
@@ -86,8 +88,8 @@ pub async fn stream_udf_execution(
8688 let ( log_entries, new_cursor) = entries_future_r?;
8789 let entries = log_entries
8890 . into_iter( )
89- . map( execution_to_json)
90- . collect :: <anyhow :: Result <_>> ( ) ?;
91+ . map( |e| execution_to_json( e , false ) )
92+ . try_collect ( ) ?;
9193 let response = StreamUdfExecutionResponse {
9294 entries,
9395 new_cursor,
@@ -131,6 +133,7 @@ pub struct StreamFunctionLogs {
131133pub async fn stream_function_logs (
132134 State ( st) : State < LocalAppState > ,
133135 ExtractIdentity ( identity) : ExtractIdentity ,
136+ ExtractClientVersion ( client_version) : ExtractClientVersion ,
134137 Query ( query_args) : Query < StreamFunctionLogs > ,
135138) -> Result < impl IntoResponse , HttpResponseError > {
136139 let entries_future = st
@@ -144,6 +147,22 @@ pub async fn stream_function_logs(
144147 ) ) ,
145148 _ => None ,
146149 } ;
150+ // As of writing, this endpoint is only used by the CLI and dashboard, both of
151+ // which support either unstructured `string` log lines or structured log
152+ // lines.
153+ let supports_structured_log_lines = match client_version. client ( ) {
154+ ClientType :: CLI => true ,
155+ ClientType :: Dashboard => true ,
156+ ClientType :: NPM
157+ | ClientType :: Actions
158+ | ClientType :: Python
159+ | ClientType :: Rust
160+ | ClientType :: StreamingImport
161+ | ClientType :: AirbyteExport
162+ | ClientType :: FivetranImport
163+ | ClientType :: FivetranExport
164+ | ClientType :: Unrecognized ( _) => false ,
165+ } ;
147166 futures:: select_biased! {
148167 entries_future_r = entries_future. fuse( ) => {
149168 let ( log_entries, new_cursor) = entries_future_r?;
@@ -166,15 +185,17 @@ pub async fn stream_function_logs(
166185 . map( |e| {
167186 let json = match e {
168187 FunctionExecutionPart :: Completion ( c) => {
169- execution_to_json( c) ?
188+ execution_to_json( c, supports_structured_log_lines ) ?
170189 } ,
171190 FunctionExecutionPart :: Progress ( c) => {
172191 FunctionExecutionJson :: Progress {
173192 udf_type: c. event_source. udf_type. to_string( ) ,
174193 identifier: c. event_source. path,
175194 timestamp: c. function_start_timestamp. as_secs_f64( ) ,
176195 log_lines: c. log_lines
177- . into_iter( ) . map( |l| l. to_pretty_string( ) ) . collect( ) ,
196+ . into_iter( )
197+ . map( |l| l. to_json( supports_structured_log_lines, false ) )
198+ . try_collect( ) ?,
178199 request_id: c. event_source. context. request_id. to_string( ) ,
179200 execution_id: c. event_source. context. execution_id. to_string( )
180201 }
@@ -204,7 +225,10 @@ pub async fn stream_function_logs(
204225 }
205226}
206227
207- fn execution_to_json ( execution : FunctionExecution ) -> anyhow:: Result < FunctionExecutionJson > {
228+ fn execution_to_json (
229+ execution : FunctionExecution ,
230+ supports_structured_log_lines : bool ,
231+ ) -> anyhow:: Result < FunctionExecutionJson > {
208232 let json = match execution. params {
209233 UdfParams :: Function { error, identifier } => {
210234 let identifier: String = identifier. strip ( ) . into ( ) ;
@@ -214,8 +238,8 @@ fn execution_to_json(execution: FunctionExecution) -> anyhow::Result<FunctionExe
214238 log_lines : execution
215239 . log_lines
216240 . into_iter ( )
217- . map ( |l| l. to_pretty_string ( ) )
218- . collect ( ) ,
241+ . map ( |l| l. to_json ( supports_structured_log_lines , false ) )
242+ . try_collect ( ) ? ,
219243 timestamp : execution. unix_timestamp . as_secs_f64 ( ) ,
220244 cached_result : execution. cached_result ,
221245 execution_time : execution. execution_time ,
@@ -237,8 +261,8 @@ fn execution_to_json(execution: FunctionExecution) -> anyhow::Result<FunctionExe
237261 log_lines : execution
238262 . log_lines
239263 . into_iter ( )
240- . map ( |l| l. to_pretty_string ( ) )
241- . collect ( ) ,
264+ . map ( |l| l. to_json ( supports_structured_log_lines , false ) )
265+ . try_collect ( ) ? ,
242266 timestamp : execution. unix_timestamp . as_secs_f64 ( ) ,
243267 cached_result : execution. cached_result ,
244268 execution_time : execution. execution_time ,
0 commit comments