Skip to content

Commit e3d4338

Browse files
PettitWesleyedsiper
authored andcommitted
out_opensearch: fix trace_error truncating the response
Signed-off-by: Wesley Pettit <[email protected]>
1 parent cad2cc8 commit e3d4338

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

plugins/out_opensearch/opensearch.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,25 @@ static void cb_opensearch_flush(struct flb_event_chunk *event_chunk,
902902
/* we got an error */
903903
if (ctx->trace_error) {
904904
/*
905-
* If trace_error is set, trace the actual input/output to
906-
* OpenSearch that caused the problem.
905+
* If trace_error is set, trace the actual
906+
* response from Elasticsearch explaining the problem.
907+
* Trace_Output can be used to see the request.
907908
*/
908-
flb_plg_debug(ctx->ins, "error caused by: Input\n%s\n",
909-
pack);
910-
flb_plg_error(ctx->ins, "error: Output\n%s",
911-
c->resp.payload);
909+
if (pack_size < 4000) {
910+
flb_plg_debug(ctx->ins, "error caused by: Input\n%.*s\n",
911+
(int) pack_size, pack);
912+
}
913+
if (c->resp.payload_size < 4000) {
914+
flb_plg_error(ctx->ins, "error: Output\n%s",
915+
c->resp.payload);
916+
} else {
917+
/*
918+
* We must use fwrite since the flb_log functions
919+
* will truncate data at 4KB
920+
*/
921+
fwrite(c->resp.payload, 1, c->resp.payload_size, stderr);
922+
fflush(stderr);
923+
}
912924
}
913925
goto retry;
914926
}

0 commit comments

Comments
 (0)