Skip to content

Commit 6332524

Browse files
committed
decode_opentelemetry: add missing fields handlers
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 685edfc commit 6332524

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

src/ctr_decode_opentelemetry.c

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,16 @@ static struct ctrace_attributes *convert_otel_attrs(size_t n_attributes,
350350
Opentelemetry__Proto__Common__V1__AnyValue *val;
351351

352352
ctr_decoded_attributes = malloc(sizeof(struct opentelemetry_decode_value));
353+
if (!ctr_decoded_attributes) {
354+
ctr_errno();
355+
return NULL;
356+
}
357+
353358
ctr_decoded_attributes->ctr_attr = ctr_attributes_create();
359+
if (!ctr_decoded_attributes->ctr_attr) {
360+
free(ctr_decoded_attributes);
361+
return NULL;
362+
}
354363

355364
result = 0;
356365

@@ -376,9 +385,9 @@ static struct ctrace_attributes *convert_otel_attrs(size_t n_attributes,
376385
return attr;
377386
}
378387

379-
static int ctr_span_set_attributes(struct ctrace_span *span,
380-
size_t n_attributes,
381-
Opentelemetry__Proto__Common__V1__KeyValue **attributes)
388+
static int span_set_attributes(struct ctrace_span *span,
389+
size_t n_attributes,
390+
Opentelemetry__Proto__Common__V1__KeyValue **attributes)
382391
{
383392
struct ctrace_attributes *ctr_attributes;
384393

@@ -394,9 +403,9 @@ static int ctr_span_set_attributes(struct ctrace_span *span,
394403
return 0;
395404
}
396405

397-
static int ctr_span_set_events(struct ctrace_span *span,
398-
size_t n_events,
399-
Opentelemetry__Proto__Trace__V1__Span__Event **events)
406+
static int span_set_events(struct ctrace_span *span,
407+
size_t n_events,
408+
Opentelemetry__Proto__Trace__V1__Span__Event **events)
400409
{
401410
int index_event;
402411
struct ctrace_span_event *ctr_event;
@@ -409,22 +418,19 @@ static int ctr_span_set_events(struct ctrace_span *span,
409418
event = events[index_event];
410419

411420
ctr_event = ctr_span_event_add_ts(span, event->name, event->time_unix_nano);
412-
413421
if (ctr_event == NULL) {
414422
return -1;
415423
}
416424

417-
ctr_attributes = convert_otel_attrs(event->n_attributes, event->attributes);
418-
419-
if (ctr_attributes == NULL) {
420-
return -1;
421-
}
422-
423-
if (ctr_event->attr) {
424-
ctr_attributes_destroy(ctr_event->attr);
425+
if (event->n_attributes > 0 && event->attributes != NULL) {
426+
ctr_attributes = convert_otel_attrs(event->n_attributes, event->attributes);
427+
if (ctr_attributes == NULL) {
428+
return -1;
429+
}
430+
else {
431+
ctr_span_event_set_attributes(ctr_event, ctr_attributes);
432+
}
425433
}
426-
427-
ctr_event->attr = ctr_attributes;
428434
ctr_span_event_set_dropped_attributes_count(ctr_event, event->dropped_attributes_count);
429435
}
430436

@@ -544,6 +550,8 @@ int ctr_decode_opentelemetry_create(struct ctrace **out_ctr,
544550
resource = ctr_resource_span_get_resource(resource_span);
545551
resource_set_data(resource, otel_resource_span->resource);
546552

553+
ctr_resource_set_dropped_attr_count(resource, otel_resource_span->resource->dropped_attributes_count);
554+
547555
for (scope_span_index = 0; scope_span_index < otel_resource_span->n_scope_spans; scope_span_index++) {
548556
otel_scope_span = otel_resource_span->scope_spans[scope_span_index];
549557
if (otel_scope_span == NULL) {
@@ -571,16 +579,25 @@ int ctr_decode_opentelemetry_create(struct ctrace **out_ctr,
571579
ctr_span_set_trace_id(span, otel_span->trace_id.data, otel_span->trace_id.len);
572580
ctr_span_set_span_id(span, otel_span->span_id.data, otel_span->span_id.len);
573581
ctr_span_set_parent_span_id(span, otel_span->parent_span_id.data, otel_span->parent_span_id.len);
582+
583+
if (otel_span->trace_state && strlen(otel_span->trace_state) > 0) {
584+
ctr_span_set_trace_state(span, otel_span->trace_state, strlen(otel_span->trace_state));
585+
}
586+
574587
ctr_span_kind_set(span, otel_span->kind);
575588
ctr_span_start_ts(ctr, span, otel_span->start_time_unix_nano);
576589
ctr_span_end_ts(ctr, span, otel_span->end_time_unix_nano);
577590
if (otel_span->status) {
578591
ctr_span_set_status(span, otel_span->status->code, otel_span->status->message);
579592
}
580-
ctr_span_set_attributes(span, otel_span->n_attributes, otel_span->attributes);
581-
ctr_span_set_events(span, otel_span->n_events, otel_span->events);
593+
594+
span_set_attributes(span, otel_span->n_attributes, otel_span->attributes);
595+
span_set_events(span, otel_span->n_events, otel_span->events);
596+
582597
ctr_span_set_dropped_attributes_count(span, otel_span->dropped_attributes_count);
583598
ctr_span_set_dropped_events_count(span, otel_span->dropped_events_count);
599+
ctr_span_set_dropped_links_count(span, otel_span->dropped_links_count);
600+
584601
ctr_span_set_links(span, otel_span->n_links, otel_span->links);
585602
}
586603
}

0 commit comments

Comments
 (0)