Skip to content

Commit e105812

Browse files
committed
in_opentelemetry: traces: fix handling of JSON status code
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent eb5a706 commit e105812

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

plugins/in_opentelemetry/opentelemetry_traces.c

+23-2
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ static int process_span_status(struct flb_opentelemetry *ctx,
550550
{
551551
int ret;
552552
int code = 0;
553+
cfl_sds_t tmp = NULL;
553554
char *message = NULL;
554555

555556
if (status->type != MSGPACK_OBJECT_MAP) {
@@ -559,8 +560,28 @@ static int process_span_status(struct flb_opentelemetry *ctx,
559560

560561
/* code */
561562
ret = find_map_entry_by_key(&status->via.map, "code", 0, FLB_TRUE);
562-
if (ret >= 0 && status->via.map.ptr[ret].val.type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
563-
code = status->via.map.ptr[ret].val.via.u64;
563+
if (ret >= 0 && status->via.map.ptr[ret].val.type == MSGPACK_OBJECT_STR) {
564+
tmp = cfl_sds_create_len(status->via.map.ptr[ret].val.via.str.ptr,
565+
status->via.map.ptr[ret].val.via.str.size);
566+
if (!tmp) {
567+
return -1;
568+
}
569+
570+
if (strcasecmp(tmp, "UNSET") == 0) {
571+
code = CTRACE_SPAN_STATUS_CODE_UNSET;
572+
}
573+
else if (strcasecmp(tmp, "OK") == 0) {
574+
code = CTRACE_SPAN_STATUS_CODE_OK;
575+
}
576+
else if (strcasecmp(tmp, "ERROR") == 0) {
577+
code = CTRACE_SPAN_STATUS_CODE_ERROR;
578+
}
579+
else {
580+
flb_plg_error(ctx->ins, "status code value is invalid: %s", tmp);
581+
cfl_sds_destroy(tmp);
582+
return -1;
583+
}
584+
cfl_sds_destroy(tmp);
564585
}
565586
else {
566587
flb_plg_error(ctx->ins, "status code is missing");

0 commit comments

Comments
 (0)