@@ -350,7 +350,16 @@ static struct ctrace_attributes *convert_otel_attrs(size_t n_attributes,
350
350
Opentelemetry__Proto__Common__V1__AnyValue * val ;
351
351
352
352
ctr_decoded_attributes = malloc (sizeof (struct opentelemetry_decode_value ));
353
+ if (!ctr_decoded_attributes ) {
354
+ ctr_errno ();
355
+ return NULL ;
356
+ }
357
+
353
358
ctr_decoded_attributes -> ctr_attr = ctr_attributes_create ();
359
+ if (!ctr_decoded_attributes -> ctr_attr ) {
360
+ free (ctr_decoded_attributes );
361
+ return NULL ;
362
+ }
354
363
355
364
result = 0 ;
356
365
@@ -376,9 +385,9 @@ static struct ctrace_attributes *convert_otel_attrs(size_t n_attributes,
376
385
return attr ;
377
386
}
378
387
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 )
382
391
{
383
392
struct ctrace_attributes * ctr_attributes ;
384
393
@@ -394,9 +403,9 @@ static int ctr_span_set_attributes(struct ctrace_span *span,
394
403
return 0 ;
395
404
}
396
405
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 )
400
409
{
401
410
int index_event ;
402
411
struct ctrace_span_event * ctr_event ;
@@ -409,22 +418,19 @@ static int ctr_span_set_events(struct ctrace_span *span,
409
418
event = events [index_event ];
410
419
411
420
ctr_event = ctr_span_event_add_ts (span , event -> name , event -> time_unix_nano );
412
-
413
421
if (ctr_event == NULL ) {
414
422
return -1 ;
415
423
}
416
424
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
+ }
425
433
}
426
-
427
- ctr_event -> attr = ctr_attributes ;
428
434
ctr_span_event_set_dropped_attributes_count (ctr_event , event -> dropped_attributes_count );
429
435
}
430
436
@@ -544,6 +550,8 @@ int ctr_decode_opentelemetry_create(struct ctrace **out_ctr,
544
550
resource = ctr_resource_span_get_resource (resource_span );
545
551
resource_set_data (resource , otel_resource_span -> resource );
546
552
553
+ ctr_resource_set_dropped_attr_count (resource , otel_resource_span -> resource -> dropped_attributes_count );
554
+
547
555
for (scope_span_index = 0 ; scope_span_index < otel_resource_span -> n_scope_spans ; scope_span_index ++ ) {
548
556
otel_scope_span = otel_resource_span -> scope_spans [scope_span_index ];
549
557
if (otel_scope_span == NULL ) {
@@ -571,16 +579,25 @@ int ctr_decode_opentelemetry_create(struct ctrace **out_ctr,
571
579
ctr_span_set_trace_id (span , otel_span -> trace_id .data , otel_span -> trace_id .len );
572
580
ctr_span_set_span_id (span , otel_span -> span_id .data , otel_span -> span_id .len );
573
581
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
+
574
587
ctr_span_kind_set (span , otel_span -> kind );
575
588
ctr_span_start_ts (ctr , span , otel_span -> start_time_unix_nano );
576
589
ctr_span_end_ts (ctr , span , otel_span -> end_time_unix_nano );
577
590
if (otel_span -> status ) {
578
591
ctr_span_set_status (span , otel_span -> status -> code , otel_span -> status -> message );
579
592
}
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
+
582
597
ctr_span_set_dropped_attributes_count (span , otel_span -> dropped_attributes_count );
583
598
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
+
584
601
ctr_span_set_links (span , otel_span -> n_links , otel_span -> links );
585
602
}
586
603
}
0 commit comments