Skip to content

Commit 303e9f8

Browse files
committed
out_opensearch: add support for traces
In this patch, we add support for traces. A trace is converted directly to it representation in JSON format. Signed-off-by: Eduardo Silva <[email protected]>
1 parent 8d93378 commit 303e9f8

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

plugins/out_opensearch/opensearch.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,9 @@ static void cb_opensearch_flush(struct flb_event_chunk *event_chunk,
856856
struct flb_input_instance *ins, void *out_context,
857857
struct flb_config *config)
858858
{
859-
int ret;
859+
int ret = -1;
860860
size_t pack_size;
861-
char *pack;
861+
flb_sds_t pack;
862862
void *out_buf;
863863
size_t out_size;
864864
size_t b_sent;
@@ -874,12 +874,24 @@ static void cb_opensearch_flush(struct flb_event_chunk *event_chunk,
874874
}
875875

876876
/* Convert format */
877-
ret = opensearch_format(config, ins,
878-
ctx, NULL,
879-
event_chunk->type,
880-
event_chunk->tag, flb_sds_len(event_chunk->tag),
881-
event_chunk->data, event_chunk->size,
882-
&out_buf, &out_size);
877+
if (event_chunk->type == FLB_EVENT_TYPE_TRACES) {
878+
pack = flb_msgpack_raw_to_json_sds(event_chunk->data, event_chunk->size);
879+
if (pack) {
880+
ret = 0;
881+
}
882+
else {
883+
ret = -1;
884+
}
885+
}
886+
else if (event_chunk->type == FLB_EVENT_TYPE_LOGS) {
887+
ret = opensearch_format(config, ins,
888+
ctx, NULL,
889+
event_chunk->type,
890+
event_chunk->tag, flb_sds_len(event_chunk->tag),
891+
event_chunk->data, event_chunk->size,
892+
&out_buf, &out_size);
893+
}
894+
883895
if (ret != 0) {
884896
flb_upstream_conn_release(u_conn);
885897
FLB_OUTPUT_RETURN(FLB_ERROR);
@@ -1205,6 +1217,9 @@ struct flb_output_plugin out_opensearch_plugin = {
12051217
/* Configuration */
12061218
.config_map = config_map,
12071219

1220+
/* Events supported */
1221+
.event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_TRACES,
1222+
12081223
/* Test */
12091224
.test_formatter.callback = opensearch_format,
12101225

0 commit comments

Comments
 (0)