@@ -1225,22 +1225,25 @@ static int json_payload_append_converted_value(
12251225 return result ;
12261226}
12271227
1228- static int process_json_payload_log_records_entry (
1229- struct flb_opentelemetry * ctx ,
1230- struct flb_log_event_encoder * encoder ,
1231- msgpack_object * log_records_object )
1228+ static int process_json_payload_log_records_entry (struct flb_opentelemetry * ctx ,
1229+ struct flb_log_event_encoder * encoder ,
1230+ msgpack_object * log_records_object )
12321231{
1233- msgpack_object_map * log_records_entry ;
1232+ int result ;
1233+ int body_type ;
12341234 char timestamp_str [32 ];
1235+ msgpack_object_map * log_records_entry ;
12351236 msgpack_object * timestamp_object ;
12361237 uint64_t timestamp_uint64 ;
12371238 msgpack_object * metadata_object ;
12381239 msgpack_object * body_object ;
1239- int body_type ;
1240- struct flb_time timestamp ;
1241- int result ;
1240+ msgpack_object * observed_time_unix_nano = NULL ;
12421241 msgpack_object * severity_number = NULL ;
12431242 msgpack_object * severity_text = NULL ;
1243+ msgpack_object * trace_id = NULL ;
1244+ msgpack_object * span_id = NULL ;
1245+ struct flb_time timestamp ;
1246+
12441247
12451248 if (log_records_object -> type != MSGPACK_OBJECT_MAP ) {
12461249 flb_plg_error (ctx -> ins , "unexpected logRecords entry type" );
@@ -1300,6 +1303,15 @@ static int process_json_payload_log_records_entry(
13001303 flb_time_from_uint64 (& timestamp , timestamp_uint64 );
13011304 }
13021305
1306+ /* observedTimeUnixNano (yes, we do it again) */
1307+ result = find_map_entry_by_key (log_records_entry , "observedTimeUnixNano" , 0 , FLB_TRUE );
1308+ if (result == -1 ) {
1309+ result = find_map_entry_by_key (log_records_entry , "observed_time_unix_nano" , 0 , FLB_TRUE );
1310+ }
1311+ else if (result >= 0 ) {
1312+ observed_time_unix_nano = & log_records_entry -> ptr [result ].val ;
1313+ }
1314+
13031315 /* severityNumber */
13041316 result = find_map_entry_by_key (log_records_entry , "severityNumber" , 0 , FLB_TRUE );
13051317 if (result == -1 ) {
@@ -1334,6 +1346,24 @@ static int process_json_payload_log_records_entry(
13341346 metadata_object = & log_records_entry -> ptr [result ].val ;
13351347 }
13361348
1349+ /* traceId */
1350+ result = find_map_entry_by_key (log_records_entry , "traceId" , 0 , FLB_TRUE );
1351+ if (result == -1 ) {
1352+ result = find_map_entry_by_key (log_records_entry , "trace_id" , 0 , FLB_TRUE );
1353+ }
1354+ if (result >= 0 ) {
1355+ trace_id = & log_records_entry -> ptr [result ].val ;
1356+ }
1357+
1358+ /* spanId */
1359+ result = find_map_entry_by_key (log_records_entry , "spanId" , 0 , FLB_TRUE );
1360+ if (result == -1 ) {
1361+ result = find_map_entry_by_key (log_records_entry , "span_id" , 0 , FLB_TRUE );
1362+ }
1363+ if (result >= 0 ) {
1364+ span_id = & log_records_entry -> ptr [result ].val ;
1365+ }
1366+
13371367 result = find_map_entry_by_key (log_records_entry , "body" , 0 , FLB_TRUE );
13381368
13391369 if (result == -1 ) {
@@ -1363,6 +1393,27 @@ static int process_json_payload_log_records_entry(
13631393 flb_log_event_encoder_append_string (encoder , FLB_LOG_EVENT_METADATA , ctx -> logs_metadata_key , flb_sds_len (ctx -> logs_metadata_key ));
13641394 flb_log_event_encoder_begin_map (encoder , FLB_LOG_EVENT_METADATA );
13651395
1396+ if (observed_time_unix_nano != NULL && observed_time_unix_nano -> type == MSGPACK_OBJECT_STR ) {
1397+ memset (timestamp_str , 0 , sizeof (timestamp_str ));
1398+
1399+ if (timestamp_object -> via .str .size < sizeof (timestamp_str )) {
1400+ strncpy (timestamp_str ,
1401+ timestamp_object -> via .str .ptr ,
1402+ timestamp_object -> via .str .size );
1403+ }
1404+ else {
1405+ strncpy (timestamp_str ,
1406+ timestamp_object -> via .str .ptr ,
1407+ sizeof (timestamp_str ) - 1 );
1408+ }
1409+
1410+ timestamp_uint64 = strtoul (timestamp_str , NULL , 10 );
1411+
1412+ flb_log_event_encoder_append_metadata_values (encoder ,
1413+ FLB_LOG_EVENT_STRING_VALUE ("observed_timestamp" , 18 ),
1414+ FLB_LOG_EVENT_INT64_VALUE (timestamp_uint64 ));
1415+ }
1416+
13661417 if (severity_number != NULL ) {
13671418 flb_log_event_encoder_append_metadata_values (encoder ,
13681419 FLB_LOG_EVENT_STRING_VALUE ("severity_number" , 15 ),
@@ -1380,6 +1431,18 @@ static int process_json_payload_log_records_entry(
13801431 result = json_payload_append_converted_kvlist (encoder , FLB_LOG_EVENT_METADATA , metadata_object );
13811432 }
13821433
1434+ if (trace_id != NULL && (trace_id -> type == MSGPACK_OBJECT_STR || trace_id -> type == MSGPACK_OBJECT_BIN )) {
1435+ flb_log_event_encoder_append_metadata_values (encoder ,
1436+ FLB_LOG_EVENT_STRING_VALUE ("trace_id" , 8 ),
1437+ FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE (trace_id ));
1438+ }
1439+
1440+ if (span_id != NULL && (span_id -> type == MSGPACK_OBJECT_STR || span_id -> type == MSGPACK_OBJECT_BIN )) {
1441+ flb_log_event_encoder_append_metadata_values (encoder ,
1442+ FLB_LOG_EVENT_STRING_VALUE ("span_id" , 7 ),
1443+ FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE (span_id ));
1444+ }
1445+
13831446 flb_log_event_encoder_commit_map (encoder , FLB_LOG_EVENT_METADATA );
13841447
13851448 }
0 commit comments