@@ -740,6 +740,8 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
740740 int log_record_count ;
741741 int max_scopes ;
742742 int max_resources ;
743+ int64_t prev_group_resource_id = -1 ;
744+ int64_t prev_group_scope_id = -1 ;
743745 int64_t resource_id = -1 ;
744746 int64_t scope_id = -1 ;
745747 int64_t tmp_resource_id = -1 ;
@@ -805,9 +807,14 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
805807 continue ;
806808 }
807809
810+ if (resource_id == -1 && prev_group_resource_id >= 0 && prev_group_resource_id == tmp_resource_id ) {
811+ /* continue with the previous resource */
812+ resource_id = prev_group_resource_id ;
813+ scope_id = prev_group_scope_id ;
814+ }
815+
808816 /* if we have a new resource_id, start a new resource context */
809817 if (resource_id != tmp_resource_id ) {
810-
811818 if (export_logs .n_resource_logs >= max_resources ) {
812819 flb_plg_error (ctx -> ins , "max resources limit reached" );
813820 ret = FLB_ERROR ;
@@ -847,15 +854,17 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
847854 set_resource_schema_url (ctx -> ra_resource_schema_url , event .body , resource_log );
848855
849856 /* prepare the scopes */
850- scope_logs = flb_calloc (100 , sizeof (Opentelemetry__Proto__Logs__V1__ScopeLogs * ));
851- if (!scope_logs ) {
852- flb_errno ();
853- ret = FLB_RETRY ;
854- break ;
855- }
857+ if (!resource_log -> scope_logs ) {
858+ scope_logs = flb_calloc (100 , sizeof (Opentelemetry__Proto__Logs__V1__ScopeLogs * ));
859+ if (!scope_logs ) {
860+ flb_errno ();
861+ ret = FLB_RETRY ;
862+ break ;
863+ }
856864
857- resource_log -> scope_logs = scope_logs ;
858- resource_log -> n_scope_logs = 0 ;
865+ resource_log -> scope_logs = scope_logs ;
866+ resource_log -> n_scope_logs = 0 ;
867+ }
859868
860869 /* update the current resource_id */
861870 resource_id = tmp_resource_id ;
@@ -893,12 +902,12 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
893902 flb_errno ();
894903 return -2 ;
895904 }
905+ log_record_count = 0 ;
896906
897907 scope_log -> log_records = log_records ;
898- scope_logs [resource_log -> n_scope_logs ] = scope_log ;
908+ resource_log -> scope_logs [resource_log -> n_scope_logs ] = scope_log ;
899909 resource_log -> n_scope_logs ++ ;
900910
901-
902911 /* group body: $scope['name'] */
903912 set_scope_name (ctx -> ra_scope_name , event .body , scope_log -> scope );
904913
@@ -911,13 +920,14 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
911920
912921 ret = FLB_OK ;
913922
914- if (record_type == FLB_LOG_EVENT_GROUP_START ) {
915- continue ;
916- }
923+ /* since we are starting a new group, just continue with the next record */
924+ continue ;
917925 }
918926 else if (record_type == FLB_LOG_EVENT_GROUP_END ) {
919927 /* do nothing */
920928 ret = FLB_OK ;
929+ prev_group_resource_id = resource_id ;
930+ prev_group_scope_id = scope_id ;
921931 resource_id = -1 ;
922932 scope_id = -1 ;
923933 continue ;
@@ -944,6 +954,7 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
944954 ret = FLB_RETRY ;
945955 break ;
946956 }
957+
947958 log_records [log_record_count ] = log_record ;
948959 opentelemetry__proto__logs__v1__log_record__init (log_record );
949960
0 commit comments