Skip to content

Commit c74ef23

Browse files
committed
tests: internal: opentelemetry: add test case for numeric attributes
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 8694de8 commit c74ef23

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/internal/data/opentelemetry/test_cases.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,29 @@
12551255
"log_body": {"a":{"d":[{"e":"g"}]}}
12561256
}
12571257
},
1258+
"resource_attribute_intvalue_string": {
1259+
"input": {
1260+
"resourceLogs": [{
1261+
"resource": {
1262+
"attributes": [
1263+
{"key": "resourceVersion", "value": {"intValue": "1"}}
1264+
]
1265+
},
1266+
"scopeLogs": [{
1267+
"logRecords": [{
1268+
"timeUnixNano": "1640995200000000000",
1269+
"body": {"stringValue": "test log"}
1270+
}]
1271+
}]
1272+
}]
1273+
},
1274+
"expected": {
1275+
"group_metadata": {"schema":"otlp","resource_id":0,"scope_id":0},
1276+
"group_body": {"resource":{"attributes":{"resourceVersion":1}}},
1277+
"log_metadata": {"otlp":{}},
1278+
"log_body": {"log": "test log"}
1279+
}
1280+
},
12581281
"unwrapped_plain_map": {
12591282
"input": {
12601283
"resourceLogs": [{

tests/internal/opentelemetry.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,27 @@ void test_json_payload_get_wrapped_value()
475475

476476
msgpack_sbuffer_destroy(&sbuf);
477477
msgpack_unpacked_destroy(&up);
478+
479+
/* Test integer value provided as a string */
480+
msgpack_sbuffer_init(&sbuf);
481+
msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write);
482+
483+
msgpack_pack_map(&pck, 1);
484+
msgpack_pack_str(&pck, 8);
485+
msgpack_pack_str_body(&pck, "intValue", 8);
486+
msgpack_pack_str(&pck, 1);
487+
msgpack_pack_str_body(&pck, "1", 1);
488+
489+
msgpack_unpacked_init(&up);
490+
msgpack_unpack_next(&up, sbuf.data, sbuf.size, NULL);
491+
492+
ret = flb_otel_utils_json_payload_get_wrapped_value(&up.data, &val, &type);
493+
TEST_CHECK(ret == 0);
494+
TEST_CHECK(type == MSGPACK_OBJECT_POSITIVE_INTEGER);
495+
TEST_CHECK(val->type == MSGPACK_OBJECT_STR);
496+
497+
msgpack_sbuffer_destroy(&sbuf);
498+
msgpack_unpacked_destroy(&up);
478499
}
479500

480501
#define OTEL_TEST_CASES_PATH FLB_TESTS_DATA_PATH "/data/opentelemetry/test_cases.json"

0 commit comments

Comments
 (0)