Skip to content

Commit 7fd8a07

Browse files
Aditya Prajapatimgeriesa
authored andcommitted
in_event_type: set correct span_id length and event type
Signed-off-by: Aditya Prajapati <[email protected]> Signed-off-by: Manal Geries <[email protected]>
1 parent 9f2b21c commit 7fd8a07

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

plugins/in_event_type/event_type.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,38 @@
3232
#include <cmetrics/cmt_histogram.h>
3333

3434
#define CALLBACK_TIME 2
35+
#define OTEL_SPAN_ID_LEN 8
3536

3637
struct event_type {
3738
int coll_fd;
3839
int type;
3940
};
4041

42+
static struct ctrace_id *create_random_span_id()
43+
{
44+
char *buf;
45+
ssize_t ret;
46+
struct ctrace_id *cid;
47+
48+
buf = calloc(1, OTEL_SPAN_ID_LEN);
49+
if (!buf) {
50+
ctr_errno();
51+
return NULL;
52+
}
53+
54+
ret = ctr_random_get(buf, OTEL_SPAN_ID_LEN);
55+
if (ret < 0) {
56+
free(buf);
57+
return NULL;
58+
}
59+
60+
cid = ctr_id_create(buf, OTEL_SPAN_ID_LEN);
61+
free(buf);
62+
63+
return cid;
64+
65+
}
66+
4167
static int send_logs(struct flb_input_instance *ins)
4268
{
4369
int ret;
@@ -211,7 +237,7 @@ static int send_traces(struct flb_input_instance *ins)
211237
trace_id = ctr_id_create_random();
212238

213239
/* generate a random ID for the new span */
214-
span_id = ctr_id_create_random();
240+
span_id = create_random_span_id();
215241

216242
/* Create a root span */
217243
span_root = ctr_span_create(ctx, scope_span, "main", NULL);
@@ -277,7 +303,7 @@ static int send_traces(struct flb_input_instance *ins)
277303

278304
/* delete old span id and generate a new one */
279305
ctr_id_destroy(span_id);
280-
span_id = ctr_id_create_random();
306+
span_id = create_random_span_id();
281307
ctr_span_set_span_id_with_cid(span_child, span_id);
282308

283309
/* destroy the IDs since is not longer needed */
@@ -289,7 +315,7 @@ static int send_traces(struct flb_input_instance *ins)
289315

290316
/* create a Link (no valid IDs of course) */
291317
trace_id = ctr_id_create_random();
292-
span_id = ctr_id_create_random();
318+
span_id = create_random_span_id();
293319

294320
link = ctr_link_create_with_cid(span_child, trace_id, span_id);
295321
ctr_link_set_trace_state(link, "aaabbbccc");
@@ -358,12 +384,15 @@ static int cb_event_type_init(struct flb_input_instance *ins,
358384
if (tmp) {
359385
if (strcasecmp(tmp, "logs") == 0) {
360386
ctx->type = FLB_EVENT_TYPE_LOGS;
387+
ins->event_type = FLB_INPUT_LOGS;
361388
}
362389
else if (strcasecmp(tmp, "metrics") == 0) {
363390
ctx->type = FLB_EVENT_TYPE_METRICS;
391+
ins->event_type = FLB_INPUT_METRICS;
364392
}
365393
else if (strcasecmp(tmp, "traces") == 0) {
366394
ctx->type = FLB_EVENT_TYPE_TRACES;
395+
ins->event_type = FLB_INPUT_TRACES;
367396
}
368397
}
369398

0 commit comments

Comments
 (0)