Skip to content

Commit 0955024

Browse files
committed
lib: ctraces: upgrade to v0.5.6
Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
1 parent 103c544 commit 0955024

File tree

3 files changed

+120
-5
lines changed

3 files changed

+120
-5
lines changed

lib/ctraces/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ endif()
2727
# CTraces Version
2828
set(CTR_VERSION_MAJOR 0)
2929
set(CTR_VERSION_MINOR 5)
30-
set(CTR_VERSION_PATCH 5)
30+
set(CTR_VERSION_PATCH 6)
3131
set(CTR_VERSION_STR "${CTR_VERSION_MAJOR}.${CTR_VERSION_MINOR}.${CTR_VERSION_PATCH}")
3232

3333
# Define __FILENAME__ consistently across Operating Systems

lib/ctraces/src/ctr_encode_opentelemetry.c

+25-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <ctraces/ctraces.h>
2121
#include <fluent-otel-proto/fluent-otel.h>
2222

23+
static void destroy_scope_spans(Opentelemetry__Proto__Trace__V1__ScopeSpans **scope_spans,
24+
size_t count);
25+
2326
static inline Opentelemetry__Proto__Common__V1__AnyValue *ctr_variant_to_otlp_any_value(struct cfl_variant *value);
2427
static inline Opentelemetry__Proto__Common__V1__KeyValue *ctr_variant_kvpair_to_otlp_kvpair(struct cfl_kvpair *input_pair);
2528
static inline Opentelemetry__Proto__Common__V1__AnyValue *ctr_variant_kvlist_to_otlp_any_value(struct cfl_variant *value);
@@ -914,11 +917,21 @@ static Opentelemetry__Proto__Common__V1__InstrumentationScope *set_instrumentati
914917
return NULL;
915918
}
916919

917-
otel_scope->name = instrumentation_scope->name;
918-
otel_scope->version = instrumentation_scope->version;
920+
if (instrumentation_scope->name) {
921+
otel_scope->name = instrumentation_scope->name;
922+
}
923+
else {
924+
otel_scope->name = "";
925+
}
926+
if (instrumentation_scope->version) {
927+
otel_scope->version = instrumentation_scope->version;
928+
}
929+
else {
930+
otel_scope->version = "";
931+
}
919932
otel_scope->n_attributes = get_attributes_count(instrumentation_scope->attr);
920933
otel_scope->dropped_attributes_count = instrumentation_scope->dropped_attr_count;
921-
otel_scope->attributes = set_attributes_from_ctr(instrumentation_scope->attr);;
934+
otel_scope->attributes = set_attributes_from_ctr(instrumentation_scope->attr);
922935

923936
return otel_scope;
924937
}
@@ -976,11 +989,19 @@ static Opentelemetry__Proto__Trace__V1__ScopeSpans **set_scope_spans(struct ctra
976989

977990
otel_scope_span = initialize_scope_span();
978991
if (!otel_scope_span) {
992+
if (scope_span_index > 0) {
993+
destroy_scope_spans(scope_spans, scope_span_index - 1);
994+
}
995+
996+
free(scope_spans);
997+
979998
return NULL;
980999
}
9811000

9821001
otel_scope_span->schema_url = scope_span->schema_url;
983-
otel_scope_span->scope = set_instrumentation_scope(scope_span->instrumentation_scope);
1002+
if (scope_span->instrumentation_scope != NULL) {
1003+
otel_scope_span->scope = set_instrumentation_scope(scope_span->instrumentation_scope);
1004+
}
9841005

9851006
span_count = cfl_list_size(&scope_span->spans);
9861007
otel_scope_span->n_spans = span_count;

lib/ctraces/tests/decoding.c

+94
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,81 @@ static struct ctrace *generate_encoder_test_data()
429429
return context;
430430
}
431431

432+
static int generate_sample_resource_minimal_attributes(struct ctrace_resource *resource)
433+
{
434+
struct ctrace_attributes *attributes;
435+
int result;
436+
437+
attributes = ctr_attributes_create();
438+
439+
if (attributes == NULL) {
440+
return -1;
441+
}
442+
443+
result = ctr_attributes_set_string(attributes, "receiver.tool", "ctraces");
444+
445+
if (result != 0) {
446+
ctr_attributes_destroy(attributes);
447+
448+
return -2;
449+
}
450+
451+
result = ctr_resource_set_attributes(resource, attributes);
452+
453+
if (result != 0) {
454+
ctr_attributes_destroy(attributes);
455+
456+
return -3;
457+
}
458+
459+
return 0;
460+
}
461+
462+
static struct ctrace *generate_encoder_test_data_with_empty_spans()
463+
{
464+
struct ctrace_resource_span *resource_span;
465+
struct ctrace_scope_span *scope_span;
466+
struct ctrace *context;
467+
int result;
468+
469+
context = ctr_create(NULL);
470+
471+
if (context == NULL) {
472+
return NULL;
473+
}
474+
475+
resource_span = ctr_resource_span_create(context);
476+
477+
if (resource_span == NULL) {
478+
ctr_destroy(context);
479+
480+
return NULL;
481+
}
482+
483+
ctr_resource_span_set_schema_url(resource_span, "");
484+
ctr_resource_set_dropped_attr_count(resource_span->resource, 0);
485+
486+
result = generate_sample_resource_minimal_attributes(resource_span->resource);
487+
488+
if (result != 0) {
489+
ctr_destroy(context);
490+
491+
return NULL;
492+
}
493+
494+
scope_span = ctr_scope_span_create(resource_span);
495+
496+
if (scope_span == NULL) {
497+
ctr_destroy(context);
498+
499+
return NULL;
500+
}
501+
502+
ctr_scope_span_set_schema_url(scope_span, "");
503+
504+
return context;
505+
}
506+
432507
/*
433508
* perform the following and then compare text buffers
434509
*
@@ -483,6 +558,24 @@ void test_msgpack_to_cmt()
483558
ctr_destroy(context);
484559
}
485560

561+
void test_msgpack_to_ctr_with_empty_spans()
562+
{
563+
struct ctrace *context;
564+
char *referece_text_buffer;
565+
566+
context = generate_encoder_test_data_with_empty_spans();
567+
TEST_ASSERT(context != NULL);
568+
569+
referece_text_buffer = ctr_encode_text_create(context);
570+
TEST_ASSERT(referece_text_buffer != NULL);
571+
572+
printf("%s\n", referece_text_buffer);
573+
msgpack_encode_decode_and_compare(context);
574+
575+
ctr_encode_text_destroy(referece_text_buffer);
576+
ctr_destroy(context);
577+
}
578+
486579
void test_simple_to_msgpack_and_back()
487580
{
488581
struct ctrace *ctx;
@@ -640,5 +733,6 @@ void test_simple_to_msgpack_and_back()
640733
TEST_LIST = {
641734
{"cmt_simple_to_msgpack_and_back", test_simple_to_msgpack_and_back},
642735
{"cmt_msgpack", test_msgpack_to_cmt},
736+
{"empty_spans", test_msgpack_to_ctr_with_empty_spans},
643737
{ 0 }
644738
};

0 commit comments

Comments
 (0)