From 3ce15c6f68d40075acbaabb5941036f278091c4c Mon Sep 17 00:00:00 2001 From: Srinivasan J Date: Mon, 11 Dec 2023 05:57:51 +0530 Subject: [PATCH] out_stdout: Fix incomplete printing of traces This patch fixes print_traces_text() function to print all ctrace contexts the patch has been tested with opentelemetry-cpp-1.12.0/example_otlp_http http://localhost:4318/v1/traces DEBUG=yes bin, fluent-bit 2.2.0 and ctrace fix (https://github.com/fluent/ctraces/pull/46) Signed-off-by: Srinivasan J --- plugins/out_stdout/stdout.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/plugins/out_stdout/stdout.c b/plugins/out_stdout/stdout.c index 2d6bff59856..6183460a0db 100644 --- a/plugins/out_stdout/stdout.c +++ b/plugins/out_stdout/stdout.c @@ -135,24 +135,26 @@ static void print_traces_text(struct flb_output_instance *ins, size_t off = 0; cfl_sds_t text; struct ctrace *ctr = NULL; + int ok = CTR_DECODE_MSGPACK_SUCCESS; - /* get cmetrics context */ - ret = ctr_decode_msgpack_create(&ctr, (char *) data, bytes, &off); - if (ret != 0) { - flb_plg_error(ins, "could not process traces payload (ret=%i)", ret); - return; - } - - /* convert to text representation */ - text = ctr_encode_text_create(ctr); + /* Decode each ctrace context */ + while ((ret = ctr_decode_msgpack_create(&ctr, + (char *) data, + bytes, &off)) == ok) { + /* convert to text representation */ + text = ctr_encode_text_create(ctr); - /* destroy cmt context */ - ctr_destroy(ctr); + /* destroy ctr context */ + ctr_destroy(ctr); - printf("%s", text); - fflush(stdout); + printf("%s", text); + fflush(stdout); - ctr_encode_text_destroy(text); + ctr_encode_text_destroy(text); + } + if (ret != ok) { + flb_plg_debug(ins, "ctr decode msgpack returned : %d", ret); + } } static void cb_stdout_flush(struct flb_event_chunk *event_chunk,