/src/fluent-bit/lib/cprofiles/src/cprof_encode_opentelemetry.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* CProfiles |
4 | | * ========= |
5 | | * Copyright (C) 2024 The CProfiles Authors |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | |
21 | | #include <cprofiles/cprof_encode_opentelemetry.h> |
22 | | #include <cprofiles/cprof_variant_utils.h> |
23 | | |
24 | | static int is_string_releaseable(char *address) |
25 | 0 | { |
26 | 0 | return (address != NULL && |
27 | 0 | address != protobuf_c_empty_string); |
28 | 0 | } |
29 | | |
30 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_to_otlp_any_value(struct cfl_variant *value); |
31 | | static inline Opentelemetry__Proto__Common__V1__KeyValue *cfl_variant_kvpair_to_otlp_kvpair(struct cfl_kvpair *input_pair); |
32 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_kvlist_to_otlp_any_value(struct cfl_variant *value); |
33 | | |
34 | | static inline void otlp_any_value_destroy(Opentelemetry__Proto__Common__V1__AnyValue *value); |
35 | | static inline void otlp_kvpair_destroy(Opentelemetry__Proto__Common__V1__KeyValue *kvpair); |
36 | | static inline void otlp_kvlist_destroy(Opentelemetry__Proto__Common__V1__KeyValueList *kvlist); |
37 | | static inline void otlp_array_destroy(Opentelemetry__Proto__Common__V1__ArrayValue *array); |
38 | | |
39 | | static inline void otlp_kvpair_list_destroy(Opentelemetry__Proto__Common__V1__KeyValue **pair_list, size_t entry_count); |
40 | | |
41 | | static inline void otlp_kvpair_destroy(Opentelemetry__Proto__Common__V1__KeyValue *kvpair) |
42 | 0 | { |
43 | 0 | if (kvpair != NULL) { |
44 | 0 | if (kvpair->key != NULL) { |
45 | 0 | free(kvpair->key); |
46 | 0 | } |
47 | |
|
48 | 0 | if (kvpair->value != NULL) { |
49 | 0 | otlp_any_value_destroy(kvpair->value); |
50 | 0 | } |
51 | |
|
52 | 0 | free(kvpair); |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | static inline void otlp_kvlist_destroy(Opentelemetry__Proto__Common__V1__KeyValueList *kvlist) |
57 | 0 | { |
58 | 0 | size_t index; |
59 | |
|
60 | 0 | if (kvlist != NULL) { |
61 | 0 | if (kvlist->values != NULL) { |
62 | 0 | for (index = 0 ; index < kvlist->n_values ; index++) { |
63 | 0 | otlp_kvpair_destroy(kvlist->values[index]); |
64 | 0 | } |
65 | |
|
66 | 0 | free(kvlist->values); |
67 | 0 | } |
68 | |
|
69 | 0 | free(kvlist); |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | static inline void otlp_array_destroy(Opentelemetry__Proto__Common__V1__ArrayValue *array) |
74 | 0 | { |
75 | 0 | size_t index; |
76 | |
|
77 | 0 | if (array != NULL) { |
78 | 0 | if (array->values != NULL) { |
79 | 0 | for (index = 0 ; index < array->n_values ; index++) { |
80 | 0 | otlp_any_value_destroy(array->values[index]); |
81 | 0 | } |
82 | |
|
83 | 0 | free(array->values); |
84 | 0 | } |
85 | |
|
86 | 0 | free(array); |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | static inline void otlp_any_value_destroy(Opentelemetry__Proto__Common__V1__AnyValue *value) |
91 | 0 | { |
92 | 0 | if (value != NULL) { |
93 | 0 | if (value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) { |
94 | 0 | if (value->string_value != NULL) { |
95 | 0 | free(value->string_value); |
96 | 0 | } |
97 | 0 | } |
98 | 0 | else if (value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_ARRAY_VALUE) { |
99 | 0 | if (value->array_value != NULL) { |
100 | 0 | otlp_array_destroy(value->array_value); |
101 | 0 | } |
102 | 0 | } |
103 | 0 | else if (value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_KVLIST_VALUE) { |
104 | 0 | if (value->kvlist_value != NULL) { |
105 | 0 | otlp_kvlist_destroy(value->kvlist_value); |
106 | 0 | } |
107 | 0 | } |
108 | 0 | else if (value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BYTES_VALUE) { |
109 | 0 | if (value->bytes_value.data != NULL) { |
110 | 0 | free(value->bytes_value.data); |
111 | 0 | } |
112 | 0 | } |
113 | |
|
114 | 0 | free(value); |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | | static inline Opentelemetry__Proto__Common__V1__KeyValue **otlp_kvpair_list_initialize(size_t entry_count) |
119 | 0 | { |
120 | 0 | Opentelemetry__Proto__Common__V1__KeyValue **result; |
121 | |
|
122 | 0 | result = \ |
123 | 0 | calloc(entry_count, sizeof(Opentelemetry__Proto__Common__V1__KeyValue *)); |
124 | |
|
125 | 0 | return result; |
126 | 0 | } |
127 | | |
128 | | |
129 | | static Opentelemetry__Proto__Common__V1__ArrayValue *otlp_array_value_initialize(size_t entry_count) |
130 | 0 | { |
131 | 0 | Opentelemetry__Proto__Common__V1__ArrayValue *value; |
132 | |
|
133 | 0 | value = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__ArrayValue)); |
134 | |
|
135 | 0 | if (value != NULL) { |
136 | 0 | opentelemetry__proto__common__v1__array_value__init(value); |
137 | |
|
138 | 0 | if (entry_count > 0) { |
139 | 0 | value->values = \ |
140 | 0 | calloc(entry_count, |
141 | 0 | sizeof(Opentelemetry__Proto__Common__V1__AnyValue *)); |
142 | |
|
143 | 0 | if (value->values == NULL) { |
144 | 0 | free(value); |
145 | |
|
146 | 0 | value = NULL; |
147 | 0 | } |
148 | 0 | else { |
149 | 0 | value->n_values = entry_count; |
150 | 0 | } |
151 | 0 | } |
152 | 0 | } |
153 | |
|
154 | 0 | return value; |
155 | 0 | } |
156 | | |
157 | | static Opentelemetry__Proto__Common__V1__KeyValue *otlp_kvpair_value_initialize() |
158 | 0 | { |
159 | 0 | Opentelemetry__Proto__Common__V1__KeyValue *value; |
160 | |
|
161 | 0 | value = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__KeyValue)); |
162 | |
|
163 | 0 | if (value != NULL) { |
164 | 0 | opentelemetry__proto__common__v1__key_value__init(value); |
165 | 0 | } |
166 | |
|
167 | 0 | return value; |
168 | 0 | } |
169 | | |
170 | | static Opentelemetry__Proto__Common__V1__KeyValueList *otlp_kvlist_value_initialize(size_t entry_count) |
171 | 0 | { |
172 | 0 | Opentelemetry__Proto__Common__V1__KeyValueList *value; |
173 | |
|
174 | 0 | value = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__KeyValueList)); |
175 | |
|
176 | 0 | if (value != NULL) { |
177 | 0 | opentelemetry__proto__common__v1__key_value_list__init(value); |
178 | |
|
179 | 0 | if (entry_count > 0) { |
180 | 0 | value->values = \ |
181 | 0 | calloc(entry_count, |
182 | 0 | sizeof(Opentelemetry__Proto__Common__V1__KeyValue *)); |
183 | |
|
184 | 0 | if (value->values == NULL) { |
185 | 0 | free(value); |
186 | |
|
187 | 0 | value = NULL; |
188 | 0 | } |
189 | 0 | else { |
190 | 0 | value->n_values = entry_count; |
191 | 0 | } |
192 | 0 | } |
193 | 0 | } |
194 | |
|
195 | 0 | return value; |
196 | 0 | } |
197 | | |
198 | | static Opentelemetry__Proto__Common__V1__AnyValue *otlp_any_value_initialize(int data_type, size_t entry_count) |
199 | 0 | { |
200 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *value; |
201 | |
|
202 | 0 | value = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__AnyValue)); |
203 | |
|
204 | 0 | if (value == NULL) { |
205 | 0 | return NULL; |
206 | 0 | } |
207 | | |
208 | 0 | opentelemetry__proto__common__v1__any_value__init(value); |
209 | |
|
210 | 0 | if (data_type == CFL_VARIANT_STRING) { |
211 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE; |
212 | 0 | } |
213 | 0 | else if (data_type == CFL_VARIANT_BOOL) { |
214 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BOOL_VALUE; |
215 | 0 | } |
216 | 0 | else if (data_type == CFL_VARIANT_INT) { |
217 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_INT_VALUE; |
218 | 0 | } |
219 | 0 | else if (data_type == CFL_VARIANT_DOUBLE) { |
220 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_DOUBLE_VALUE; |
221 | 0 | } |
222 | 0 | else if (data_type == CFL_VARIANT_ARRAY) { |
223 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_ARRAY_VALUE; |
224 | |
|
225 | 0 | value->array_value = otlp_array_value_initialize(entry_count); |
226 | |
|
227 | 0 | if (value->array_value == NULL) { |
228 | 0 | free(value); |
229 | |
|
230 | 0 | value = NULL; |
231 | 0 | } |
232 | 0 | } |
233 | 0 | else if (data_type == CFL_VARIANT_KVLIST) { |
234 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_KVLIST_VALUE; |
235 | |
|
236 | 0 | value->kvlist_value = otlp_kvlist_value_initialize(entry_count); |
237 | |
|
238 | 0 | if (value->kvlist_value == NULL) { |
239 | 0 | free(value); |
240 | |
|
241 | 0 | value = NULL; |
242 | 0 | } |
243 | 0 | } |
244 | 0 | else if (data_type == CFL_VARIANT_BYTES) { |
245 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BYTES_VALUE; |
246 | 0 | } |
247 | 0 | else if (data_type == CFL_VARIANT_REFERENCE) { |
248 | 0 | value->value_case = OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE; |
249 | 0 | } |
250 | 0 | else { |
251 | 0 | free(value); |
252 | |
|
253 | 0 | value = NULL; |
254 | 0 | } |
255 | |
|
256 | 0 | return value; |
257 | 0 | } |
258 | | |
259 | | static inline Opentelemetry__Proto__Common__V1__KeyValue *cfl_variant_kvpair_to_otlp_kvpair(struct cfl_kvpair *input_pair) |
260 | 0 | { |
261 | 0 | Opentelemetry__Proto__Common__V1__KeyValue *pair; |
262 | |
|
263 | 0 | pair = otlp_kvpair_value_initialize(); |
264 | |
|
265 | 0 | if (pair != NULL) { |
266 | 0 | pair->key = strdup(input_pair->key); |
267 | |
|
268 | 0 | if (pair->key != NULL) { |
269 | 0 | pair->value = cfl_variant_to_otlp_any_value(input_pair->val); |
270 | |
|
271 | 0 | if (pair->value == NULL) { |
272 | 0 | free(pair->key); |
273 | |
|
274 | 0 | pair->key = NULL; |
275 | 0 | } |
276 | 0 | } |
277 | |
|
278 | 0 | if (pair->key == NULL) { |
279 | 0 | free(pair); |
280 | |
|
281 | 0 | pair = NULL; |
282 | 0 | } |
283 | 0 | } |
284 | |
|
285 | 0 | return pair; |
286 | 0 | } |
287 | | |
288 | | static inline void otlp_kvpair_list_destroy(Opentelemetry__Proto__Common__V1__KeyValue **pair_list, size_t entry_count) |
289 | 0 | { |
290 | 0 | size_t index; |
291 | |
|
292 | 0 | if (pair_list != NULL) { |
293 | 0 | for (index = 0 ; index < entry_count ; index++) { |
294 | 0 | otlp_kvpair_destroy(pair_list[index]); |
295 | 0 | } |
296 | |
|
297 | 0 | free(pair_list); |
298 | 0 | } |
299 | 0 | } |
300 | | |
301 | | static inline Opentelemetry__Proto__Common__V1__KeyValue **cfl_kvlist_to_otlp_kvpair_list(struct cfl_kvlist *kvlist) |
302 | 0 | { |
303 | 0 | size_t entry_count; |
304 | 0 | Opentelemetry__Proto__Common__V1__KeyValue *keyvalue; |
305 | 0 | struct cfl_list *iterator; |
306 | 0 | Opentelemetry__Proto__Common__V1__KeyValue **result; |
307 | 0 | struct cfl_kvpair *kvpair; |
308 | 0 | size_t index; |
309 | |
|
310 | 0 | entry_count = cfl_kvlist_count(kvlist); |
311 | |
|
312 | 0 | result = otlp_kvpair_list_initialize(entry_count + 1); |
313 | |
|
314 | 0 | if (result != NULL) { |
315 | 0 | index = 0; |
316 | |
|
317 | 0 | cfl_list_foreach(iterator, &kvlist->list) { |
318 | 0 | kvpair = cfl_list_entry(iterator, struct cfl_kvpair, _head); |
319 | |
|
320 | 0 | keyvalue = cfl_variant_kvpair_to_otlp_kvpair(kvpair); |
321 | |
|
322 | 0 | if (keyvalue == NULL) { |
323 | 0 | otlp_kvpair_list_destroy(result, entry_count); |
324 | |
|
325 | 0 | result = NULL; |
326 | |
|
327 | 0 | break; |
328 | 0 | } |
329 | | |
330 | 0 | result[index++] = keyvalue; |
331 | 0 | } |
332 | 0 | } |
333 | |
|
334 | 0 | return result; |
335 | 0 | } |
336 | | |
337 | | |
338 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_kvlist_to_otlp_any_value(struct cfl_variant *value) |
339 | 0 | { |
340 | 0 | size_t entry_count; |
341 | 0 | Opentelemetry__Proto__Common__V1__KeyValue *keyvalue; |
342 | 0 | struct cfl_list *iterator; |
343 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
344 | 0 | struct cfl_kvpair *kvpair; |
345 | 0 | struct cfl_kvlist *kvlist; |
346 | 0 | size_t index; |
347 | | |
348 | |
|
349 | 0 | kvlist = value->data.as_kvlist; |
350 | |
|
351 | 0 | entry_count = cfl_kvlist_count(kvlist); |
352 | |
|
353 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_KVLIST, entry_count); |
354 | |
|
355 | 0 | if (result != NULL) { |
356 | 0 | index = 0; |
357 | |
|
358 | 0 | cfl_list_foreach(iterator, &kvlist->list) { |
359 | 0 | kvpair = cfl_list_entry(iterator, struct cfl_kvpair, _head); |
360 | |
|
361 | 0 | keyvalue = cfl_variant_kvpair_to_otlp_kvpair(kvpair); |
362 | |
|
363 | 0 | if (keyvalue == NULL) { |
364 | 0 | otlp_any_value_destroy(result); |
365 | |
|
366 | 0 | result = NULL; |
367 | |
|
368 | 0 | break; |
369 | 0 | } |
370 | | |
371 | 0 | result->kvlist_value->values[index++] = keyvalue; |
372 | 0 | } |
373 | 0 | } |
374 | |
|
375 | 0 | return result; |
376 | 0 | } |
377 | | |
378 | | |
379 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_array_to_otlp_any_value(struct cfl_variant *value) |
380 | 0 | { |
381 | 0 | size_t entry_count; |
382 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *entry_value; |
383 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
384 | 0 | struct cfl_array *array; |
385 | 0 | size_t index; |
386 | |
|
387 | 0 | array = value->data.as_array; |
388 | |
|
389 | 0 | entry_count = array->entry_count; |
390 | |
|
391 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_ARRAY, entry_count); |
392 | |
|
393 | 0 | if (result != NULL) { |
394 | 0 | index = 0; |
395 | |
|
396 | 0 | for (index = 0 ; index < entry_count ; index++) { |
397 | 0 | entry_value = cfl_variant_to_otlp_any_value(cfl_array_fetch_by_index(array, index)); |
398 | |
|
399 | 0 | if (entry_value == NULL) { |
400 | 0 | otlp_any_value_destroy(result); |
401 | |
|
402 | 0 | result = NULL; |
403 | |
|
404 | 0 | break; |
405 | 0 | } |
406 | | |
407 | 0 | result->array_value->values[index] = entry_value; |
408 | 0 | } |
409 | 0 | } |
410 | |
|
411 | 0 | return result; |
412 | 0 | } |
413 | | |
414 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_string_to_otlp_any_value(struct cfl_variant *value) |
415 | 0 | { |
416 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
417 | |
|
418 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_STRING, 0); |
419 | |
|
420 | 0 | if (result != NULL) { |
421 | 0 | result->string_value = strdup(value->data.as_string); |
422 | |
|
423 | 0 | if (result->string_value == NULL) { |
424 | 0 | otlp_any_value_destroy(result); |
425 | |
|
426 | 0 | result = NULL; |
427 | 0 | } |
428 | 0 | } |
429 | |
|
430 | 0 | return result; |
431 | 0 | } |
432 | | |
433 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_boolean_to_otlp_any_value(struct cfl_variant *value) |
434 | 0 | { |
435 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
436 | |
|
437 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_BOOL, 0); |
438 | |
|
439 | 0 | if (result != NULL) { |
440 | 0 | result->bool_value = value->data.as_bool; |
441 | 0 | } |
442 | |
|
443 | 0 | return result; |
444 | 0 | } |
445 | | |
446 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_int64_to_otlp_any_value(struct cfl_variant *value) |
447 | 0 | { |
448 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
449 | |
|
450 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_INT, 0); |
451 | |
|
452 | 0 | if (result != NULL) { |
453 | 0 | result->int_value = value->data.as_int64; |
454 | 0 | } |
455 | |
|
456 | 0 | return result; |
457 | 0 | } |
458 | | |
459 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_double_to_otlp_any_value(struct cfl_variant *value) |
460 | 0 | { |
461 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
462 | |
|
463 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_DOUBLE, 0); |
464 | |
|
465 | 0 | if (result != NULL) { |
466 | 0 | result->double_value = value->data.as_double; |
467 | 0 | } |
468 | |
|
469 | 0 | return result; |
470 | 0 | } |
471 | | |
472 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_binary_to_otlp_any_value(struct cfl_variant *value) |
473 | 0 | { |
474 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
475 | |
|
476 | 0 | result = otlp_any_value_initialize(CFL_VARIANT_BYTES, 0); |
477 | |
|
478 | 0 | if (result != NULL) { |
479 | 0 | result->bytes_value.len = cfl_sds_len(value->data.as_bytes); |
480 | 0 | result->bytes_value.data = calloc(result->bytes_value.len, sizeof(char)); |
481 | |
|
482 | 0 | if (result->bytes_value.data) { |
483 | 0 | memcpy(result->bytes_value.data, value->data.as_bytes, result->bytes_value.len); |
484 | 0 | } |
485 | 0 | else { |
486 | 0 | otlp_any_value_destroy(result); |
487 | 0 | result = NULL; |
488 | 0 | } |
489 | 0 | } |
490 | |
|
491 | 0 | return result; |
492 | 0 | } |
493 | | |
494 | | static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_to_otlp_any_value(struct cfl_variant *value) |
495 | 0 | { |
496 | 0 | Opentelemetry__Proto__Common__V1__AnyValue *result; |
497 | |
|
498 | 0 | if (value->type == CFL_VARIANT_STRING) { |
499 | 0 | result = cfl_variant_string_to_otlp_any_value(value); |
500 | 0 | } |
501 | 0 | else if (value->type == CFL_VARIANT_BOOL) { |
502 | 0 | result = cfl_variant_boolean_to_otlp_any_value(value); |
503 | 0 | } |
504 | 0 | else if (value->type == CFL_VARIANT_INT) { |
505 | 0 | result = cfl_variant_int64_to_otlp_any_value(value); |
506 | 0 | } |
507 | 0 | else if (value->type == CFL_VARIANT_DOUBLE) { |
508 | 0 | result = cfl_variant_double_to_otlp_any_value(value); |
509 | 0 | } |
510 | 0 | else if (value->type == CFL_VARIANT_ARRAY) { |
511 | 0 | result = cfl_variant_array_to_otlp_any_value(value); |
512 | 0 | } |
513 | 0 | else if (value->type == CFL_VARIANT_KVLIST) { |
514 | 0 | result = cfl_variant_kvlist_to_otlp_any_value(value); |
515 | 0 | } |
516 | 0 | else if (value->type == CFL_VARIANT_BYTES) { |
517 | 0 | result = cfl_variant_binary_to_otlp_any_value(value); |
518 | 0 | } |
519 | 0 | else if (value->type == CFL_VARIANT_REFERENCE) { |
520 | 0 | result = cfl_variant_string_to_otlp_any_value(value); |
521 | 0 | } |
522 | 0 | else { |
523 | 0 | result = NULL; |
524 | 0 | } |
525 | |
|
526 | 0 | return result; |
527 | 0 | } |
528 | | |
529 | | |
530 | | |
531 | | |
532 | | |
533 | | |
534 | | |
535 | | static void destroy_attribute( |
536 | | Opentelemetry__Proto__Common__V1__KeyValue *attribute); |
537 | | |
538 | | static void destroy_attribute_list( |
539 | | Opentelemetry__Proto__Common__V1__KeyValue **attribute_list); |
540 | | |
541 | | static Opentelemetry__Proto__Common__V1__KeyValue ** |
542 | | initialize_attribute_list( |
543 | | size_t element_count); |
544 | | |
545 | | static void destroy_attribute(Opentelemetry__Proto__Common__V1__KeyValue *attribute) |
546 | 0 | { |
547 | 0 | if (attribute != NULL) { |
548 | 0 | if (attribute->value != NULL) { |
549 | 0 | if (attribute->value->value_case == \ |
550 | 0 | OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) { |
551 | 0 | if (is_string_releaseable(attribute->value->string_value)) { |
552 | 0 | free(attribute->value->string_value); |
553 | 0 | } |
554 | 0 | } |
555 | |
|
556 | 0 | free(attribute->value); |
557 | 0 | } |
558 | |
|
559 | 0 | if (is_string_releaseable(attribute->key)) { |
560 | 0 | free(attribute->key); |
561 | 0 | } |
562 | |
|
563 | 0 | free(attribute); |
564 | 0 | } |
565 | 0 | } |
566 | | |
567 | | static void destroy_attribute_list( |
568 | | Opentelemetry__Proto__Common__V1__KeyValue **attribute_list) |
569 | 0 | { |
570 | 0 | size_t element_index; |
571 | |
|
572 | 0 | if (attribute_list != NULL) { |
573 | 0 | for (element_index = 0 ; |
574 | 0 | attribute_list[element_index] != NULL ; |
575 | 0 | element_index++) { |
576 | 0 | destroy_attribute(attribute_list[element_index]); |
577 | |
|
578 | 0 | attribute_list[element_index] = NULL; |
579 | 0 | } |
580 | |
|
581 | 0 | free(attribute_list); |
582 | 0 | } |
583 | 0 | } |
584 | | |
585 | | static Opentelemetry__Proto__Common__V1__KeyValue ** |
586 | | initialize_attribute_list( |
587 | | size_t element_count) |
588 | 0 | { |
589 | 0 | Opentelemetry__Proto__Common__V1__KeyValue **attribute_list; |
590 | |
|
591 | 0 | attribute_list = calloc(element_count + 1, |
592 | 0 | sizeof(Opentelemetry__Proto__Common__V1__KeyValue *)); |
593 | |
|
594 | 0 | return attribute_list; |
595 | 0 | } |
596 | | |
597 | | |
598 | | |
599 | | |
600 | | |
601 | | static void destroy_value_type( |
602 | | Opentelemetry__Proto__Profiles__V1development__ValueType * |
603 | | instance) |
604 | 0 | { |
605 | 0 | if (instance != NULL) { |
606 | 0 | free(instance); |
607 | 0 | } |
608 | 0 | } |
609 | | |
610 | | static void destroy_sample( |
611 | | Opentelemetry__Proto__Profiles__V1development__Sample * |
612 | | instance) |
613 | 0 | { |
614 | 0 | if (instance != NULL) { |
615 | 0 | if (instance->location_index != NULL) { |
616 | 0 | free(instance->location_index); |
617 | 0 | } |
618 | |
|
619 | 0 | if (instance->value != NULL) { |
620 | 0 | free(instance->value); |
621 | 0 | } |
622 | |
|
623 | 0 | if (instance->attributes != NULL) { |
624 | 0 | free(instance->attributes); |
625 | 0 | } |
626 | |
|
627 | 0 | if (instance->timestamps_unix_nano != NULL) { |
628 | 0 | free(instance->timestamps_unix_nano); |
629 | 0 | } |
630 | |
|
631 | 0 | free(instance); |
632 | 0 | } |
633 | 0 | } |
634 | | |
635 | | |
636 | | static void destroy_mapping( |
637 | | Opentelemetry__Proto__Profiles__V1development__Mapping * |
638 | | instance) |
639 | 0 | { |
640 | 0 | if (instance != NULL) { |
641 | 0 | if (instance->attributes != NULL) { |
642 | 0 | free(instance->attributes); |
643 | 0 | } |
644 | |
|
645 | 0 | free(instance); |
646 | 0 | } |
647 | 0 | } |
648 | | |
649 | | |
650 | | static void destroy_resource( |
651 | | Opentelemetry__Proto__Resource__V1__Resource * |
652 | | instance) |
653 | 0 | { |
654 | 0 | if (instance != NULL) { |
655 | 0 | destroy_attribute_list(instance->attributes); |
656 | |
|
657 | 0 | free(instance); |
658 | 0 | } |
659 | 0 | } |
660 | | |
661 | | static void destroy_line( |
662 | | Opentelemetry__Proto__Profiles__V1development__Line * |
663 | | instance) |
664 | 0 | { |
665 | 0 | if (instance != NULL) { |
666 | 0 | free(instance); |
667 | 0 | } |
668 | 0 | } |
669 | | |
670 | | static void destroy_link( |
671 | | Opentelemetry__Proto__Profiles__V1development__Link * |
672 | | instance) |
673 | 0 | { |
674 | 0 | if (instance != NULL) { |
675 | 0 | if (instance->trace_id.data != NULL) { |
676 | 0 | if (is_string_releaseable((cfl_sds_t) instance->trace_id.data)) { |
677 | 0 | cfl_sds_destroy((cfl_sds_t) instance->trace_id.data); |
678 | 0 | } |
679 | 0 | } |
680 | |
|
681 | 0 | if (instance->span_id.data != NULL) { |
682 | 0 | if (is_string_releaseable((cfl_sds_t) instance->span_id.data)) { |
683 | 0 | cfl_sds_destroy((cfl_sds_t) instance->span_id.data); |
684 | 0 | } |
685 | 0 | } |
686 | |
|
687 | 0 | free(instance); |
688 | 0 | } |
689 | 0 | } |
690 | | |
691 | | |
692 | | static void destroy_location( |
693 | | Opentelemetry__Proto__Profiles__V1development__Location * |
694 | | instance) |
695 | 0 | { |
696 | 0 | size_t index; |
697 | |
|
698 | 0 | if (instance != NULL) { |
699 | 0 | if (instance->line != NULL) { |
700 | 0 | for (index = 0 ; index < instance->n_line ; index++) { |
701 | 0 | destroy_line(instance->line[index]); |
702 | 0 | } |
703 | |
|
704 | 0 | free(instance->line); |
705 | 0 | } |
706 | |
|
707 | 0 | if (instance->attributes != NULL) { |
708 | 0 | free(instance->attributes); |
709 | 0 | } |
710 | |
|
711 | 0 | free(instance); |
712 | 0 | } |
713 | 0 | } |
714 | | |
715 | | static void destroy_attribute_unit( |
716 | | Opentelemetry__Proto__Profiles__V1development__AttributeUnit * |
717 | | instance) |
718 | 0 | { |
719 | 0 | if (instance != NULL) { |
720 | 0 | free(instance); |
721 | 0 | } |
722 | 0 | } |
723 | | |
724 | | static void destroy_function( |
725 | | Opentelemetry__Proto__Profiles__V1development__Function * |
726 | | instance) |
727 | 0 | { |
728 | 0 | if (instance != NULL) { |
729 | 0 | free(instance); |
730 | 0 | } |
731 | 0 | } |
732 | | |
733 | | static void destroy_instrumentation_scope( |
734 | | Opentelemetry__Proto__Common__V1__InstrumentationScope * |
735 | | instance) |
736 | 0 | { |
737 | 0 | if (instance != NULL) { |
738 | 0 | destroy_attribute_list(instance->attributes); |
739 | |
|
740 | 0 | if (instance->name != NULL) { |
741 | 0 | if (is_string_releaseable(instance->name)) { |
742 | 0 | cfl_sds_destroy(instance->name); |
743 | 0 | } |
744 | 0 | } |
745 | |
|
746 | 0 | if (instance->version != NULL) { |
747 | 0 | if (is_string_releaseable(instance->version)) { |
748 | 0 | cfl_sds_destroy(instance->version); |
749 | 0 | } |
750 | 0 | } |
751 | |
|
752 | 0 | free(instance); |
753 | 0 | } |
754 | 0 | } |
755 | | |
756 | | static void destroy_profile( |
757 | | Opentelemetry__Proto__Profiles__V1development__Profile * |
758 | | instance) |
759 | 0 | { |
760 | 0 | size_t index; |
761 | |
|
762 | 0 | if (instance != NULL) { |
763 | 0 | if (instance->sample_type != NULL) { |
764 | 0 | for (index = 0 ; index < instance->n_sample_type ; index++) { |
765 | 0 | destroy_value_type(instance->sample_type[index]); |
766 | 0 | } |
767 | |
|
768 | 0 | free(instance->sample_type); |
769 | 0 | } |
770 | |
|
771 | 0 | if (instance->sample != NULL) { |
772 | 0 | for (index = 0 ; index < instance->n_sample ; index++) { |
773 | 0 | destroy_sample(instance->sample[index]); |
774 | 0 | } |
775 | |
|
776 | 0 | free(instance->sample); |
777 | 0 | } |
778 | |
|
779 | 0 | if (instance->mapping != NULL) { |
780 | 0 | for (index = 0 ; index < instance->n_mapping ; index++) { |
781 | 0 | destroy_mapping(instance->mapping[index]); |
782 | 0 | } |
783 | |
|
784 | 0 | free(instance->mapping); |
785 | 0 | } |
786 | |
|
787 | 0 | if (instance->location != NULL) { |
788 | 0 | for (index = 0 ; index < instance->n_location ; index++) { |
789 | 0 | destroy_location(instance->location[index]); |
790 | 0 | } |
791 | |
|
792 | 0 | free(instance->location); |
793 | 0 | } |
794 | |
|
795 | 0 | if (instance->location_indices != NULL) { |
796 | 0 | free(instance->location_indices); |
797 | 0 | } |
798 | |
|
799 | 0 | if (instance->function != NULL) { |
800 | 0 | for (index = 0 ; index < instance->n_function ; index++) { |
801 | 0 | destroy_function(instance->function[index]); |
802 | 0 | } |
803 | |
|
804 | 0 | free(instance->function); |
805 | 0 | } |
806 | |
|
807 | 0 | if (instance->attribute_table != NULL) { |
808 | 0 | destroy_attribute_list(instance->attribute_table); |
809 | 0 | } |
810 | |
|
811 | 0 | for (index = 0 ; index < instance->n_attribute_units ; index++) { |
812 | 0 | destroy_attribute_unit(instance->attribute_units[index]); |
813 | 0 | } |
814 | |
|
815 | 0 | if (instance->link_table != NULL) { |
816 | 0 | for (index = 0 ; index < instance->n_link_table ; index++) { |
817 | 0 | destroy_link(instance->link_table[index]); |
818 | 0 | } |
819 | |
|
820 | 0 | free(instance->link_table); |
821 | 0 | } |
822 | |
|
823 | 0 | if (instance->string_table != NULL) { |
824 | 0 | for (index = 0 ; index < instance->n_string_table ; index++) { |
825 | 0 | if (is_string_releaseable(instance->string_table[index])) { |
826 | 0 | cfl_sds_destroy(instance->string_table[index]); |
827 | 0 | } |
828 | 0 | } |
829 | |
|
830 | 0 | free(instance->string_table); |
831 | 0 | } |
832 | |
|
833 | 0 | if (instance->period_type != NULL) { |
834 | 0 | destroy_value_type(instance->period_type); |
835 | 0 | } |
836 | |
|
837 | 0 | if (instance->comment != NULL) { |
838 | 0 | free(instance->comment); |
839 | 0 | } |
840 | |
|
841 | 0 | free(instance); |
842 | 0 | } |
843 | 0 | } |
844 | | |
845 | | static void destroy_profile_container( |
846 | | Opentelemetry__Proto__Profiles__V1development__ProfileContainer * |
847 | | instance) |
848 | 0 | { |
849 | 0 | if (instance != NULL) { |
850 | 0 | if (instance->profile_id.data != NULL) { |
851 | 0 | if (is_string_releaseable((cfl_sds_t) instance->profile_id.data)) { |
852 | 0 | cfl_sds_destroy((cfl_sds_t) instance->profile_id.data); |
853 | 0 | } |
854 | 0 | } |
855 | |
|
856 | 0 | destroy_attribute_list(instance->attributes); |
857 | |
|
858 | 0 | if (instance->original_payload_format != NULL) { |
859 | 0 | if (is_string_releaseable(instance->original_payload_format)) { |
860 | 0 | cfl_sds_destroy(instance->original_payload_format); |
861 | 0 | } |
862 | 0 | } |
863 | |
|
864 | 0 | if (instance->original_payload.data != NULL) { |
865 | 0 | if (is_string_releaseable((cfl_sds_t) instance->original_payload.data)) { |
866 | 0 | cfl_sds_destroy((cfl_sds_t) instance->original_payload.data); |
867 | 0 | } |
868 | 0 | } |
869 | |
|
870 | 0 | destroy_profile(instance->profile); |
871 | |
|
872 | 0 | free(instance); |
873 | 0 | } |
874 | 0 | } |
875 | | |
876 | | static void destroy_scope_profiles( |
877 | | Opentelemetry__Proto__Profiles__V1development__ScopeProfiles * |
878 | | instance) |
879 | 0 | { |
880 | 0 | size_t index; |
881 | |
|
882 | 0 | if (instance != NULL) { |
883 | 0 | if (instance->scope != NULL) { |
884 | 0 | destroy_instrumentation_scope(instance->scope); |
885 | 0 | } |
886 | |
|
887 | 0 | if (instance->profiles != NULL) { |
888 | 0 | for (index = 0 ; index < instance->n_profiles ; index++) { |
889 | 0 | destroy_profile_container(instance->profiles[index]); |
890 | 0 | } |
891 | |
|
892 | 0 | free(instance->profiles); |
893 | 0 | } |
894 | |
|
895 | 0 | if (instance->schema_url != NULL) { |
896 | 0 | if (is_string_releaseable(instance->schema_url)) { |
897 | 0 | cfl_sds_destroy(instance->schema_url); |
898 | 0 | } |
899 | 0 | } |
900 | |
|
901 | 0 | free(instance); |
902 | 0 | } |
903 | 0 | } |
904 | | static void destroy_resource_profiles( |
905 | | Opentelemetry__Proto__Profiles__V1development__ResourceProfiles * |
906 | | instance) |
907 | 0 | { |
908 | 0 | size_t index; |
909 | |
|
910 | 0 | if (instance != NULL) { |
911 | 0 | if (instance->resource != NULL) { |
912 | 0 | destroy_resource(instance->resource); |
913 | 0 | } |
914 | |
|
915 | 0 | if (instance->scope_profiles != NULL) { |
916 | 0 | for (index = 0 ; index < instance->n_scope_profiles ; index++) { |
917 | 0 | destroy_scope_profiles(instance->scope_profiles[index]); |
918 | 0 | } |
919 | |
|
920 | 0 | free(instance->scope_profiles); |
921 | 0 | } |
922 | |
|
923 | 0 | if (instance->schema_url != NULL) { |
924 | 0 | if (is_string_releaseable(instance->schema_url)) { |
925 | 0 | cfl_sds_destroy(instance->schema_url); |
926 | 0 | } |
927 | 0 | } |
928 | |
|
929 | 0 | free(instance); |
930 | 0 | } |
931 | 0 | } |
932 | | |
933 | | static void destroy_export_profiles_service_request( |
934 | | Opentelemetry__Proto__Collector__Profiles__V1development__ExportProfilesServiceRequest * |
935 | | instance) |
936 | 0 | { |
937 | 0 | size_t index; |
938 | |
|
939 | 0 | if (instance != NULL) { |
940 | 0 | if (instance->resource_profiles != NULL) { |
941 | 0 | for (index = 0 ; index < instance->n_resource_profiles ; index++) { |
942 | 0 | destroy_resource_profiles(instance->resource_profiles[index]); |
943 | 0 | } |
944 | |
|
945 | 0 | free(instance->resource_profiles); |
946 | 0 | } |
947 | |
|
948 | 0 | free(instance); |
949 | 0 | } |
950 | 0 | } |
951 | | |
952 | | |
953 | | |
954 | | |
955 | | static |
956 | | Opentelemetry__Proto__Profiles__V1development__ValueType * |
957 | 0 | initialize_value_type() { |
958 | 0 | Opentelemetry__Proto__Profiles__V1development__ValueType *instance; |
959 | |
|
960 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__ValueType)); |
961 | |
|
962 | 0 | if (instance == NULL) { |
963 | 0 | return NULL; |
964 | 0 | } |
965 | | |
966 | 0 | opentelemetry__proto__profiles__v1development__value_type__init(instance); |
967 | |
|
968 | 0 | return instance; |
969 | 0 | } |
970 | | |
971 | | |
972 | | |
973 | | static |
974 | | Opentelemetry__Proto__Profiles__V1development__Sample * |
975 | | initialize_sample( |
976 | | size_t location_index_count, |
977 | | size_t value_count, |
978 | | size_t attributes_count, |
979 | 0 | size_t timestamps_count) { |
980 | 0 | Opentelemetry__Proto__Profiles__V1development__Sample *instance; |
981 | |
|
982 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Sample)); |
983 | |
|
984 | 0 | if (instance == NULL) { |
985 | 0 | return NULL; |
986 | 0 | } |
987 | | |
988 | 0 | opentelemetry__proto__profiles__v1development__sample__init(instance); |
989 | |
|
990 | 0 | if (location_index_count > 0) { |
991 | 0 | instance->location_index = calloc(location_index_count, sizeof(uint64_t)); |
992 | |
|
993 | 0 | if (instance->location_index == NULL) { |
994 | 0 | destroy_sample(instance); |
995 | |
|
996 | 0 | return NULL; |
997 | 0 | } |
998 | | |
999 | 0 | instance->n_location_index = location_index_count; |
1000 | 0 | } |
1001 | | |
1002 | 0 | if (value_count > 0) { |
1003 | 0 | instance->value = calloc(value_count, sizeof(int64_t)); |
1004 | |
|
1005 | 0 | if (instance->value == NULL) { |
1006 | 0 | destroy_sample(instance); |
1007 | |
|
1008 | 0 | return NULL; |
1009 | 0 | } |
1010 | | |
1011 | 0 | instance->n_value = value_count; |
1012 | 0 | } |
1013 | | |
1014 | 0 | if (attributes_count > 0) { |
1015 | 0 | instance->attributes = calloc(attributes_count, sizeof(uint64_t)); |
1016 | |
|
1017 | 0 | if (instance->attributes == NULL) { |
1018 | 0 | destroy_sample(instance); |
1019 | |
|
1020 | 0 | return NULL; |
1021 | 0 | } |
1022 | | |
1023 | 0 | instance->n_attributes = attributes_count; |
1024 | 0 | } |
1025 | | |
1026 | 0 | if (timestamps_count > 0) { |
1027 | 0 | instance->timestamps_unix_nano = calloc(timestamps_count, sizeof(uint64_t)); |
1028 | |
|
1029 | 0 | if (instance->timestamps_unix_nano == NULL) { |
1030 | 0 | destroy_sample(instance); |
1031 | |
|
1032 | 0 | return NULL; |
1033 | 0 | } |
1034 | | |
1035 | 0 | instance->n_timestamps_unix_nano = timestamps_count; |
1036 | 0 | } |
1037 | | |
1038 | 0 | return instance; |
1039 | 0 | } |
1040 | | |
1041 | | |
1042 | | |
1043 | | |
1044 | | |
1045 | | |
1046 | | static |
1047 | | Opentelemetry__Proto__Resource__V1__Resource * |
1048 | 0 | initialize_resource(size_t attribute_count) { |
1049 | 0 | Opentelemetry__Proto__Resource__V1__Resource *instance; |
1050 | |
|
1051 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Resource__V1__Resource)); |
1052 | |
|
1053 | 0 | if (instance == NULL) { |
1054 | 0 | return NULL; |
1055 | 0 | } |
1056 | | |
1057 | 0 | opentelemetry__proto__resource__v1__resource__init(instance); |
1058 | |
|
1059 | 0 | if (attribute_count > 0) { |
1060 | 0 | instance->attributes = initialize_attribute_list(attribute_count); |
1061 | |
|
1062 | 0 | if (instance->attributes == NULL) { |
1063 | 0 | free(instance); |
1064 | |
|
1065 | 0 | return NULL; |
1066 | 0 | } |
1067 | 0 | } |
1068 | | |
1069 | 0 | instance->n_attributes = attribute_count; |
1070 | |
|
1071 | 0 | return instance; |
1072 | 0 | } |
1073 | | |
1074 | | static |
1075 | | Opentelemetry__Proto__Profiles__V1development__AttributeUnit * |
1076 | 0 | initialize_attribute_unit() { |
1077 | 0 | Opentelemetry__Proto__Profiles__V1development__AttributeUnit *instance; |
1078 | |
|
1079 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__AttributeUnit)); |
1080 | |
|
1081 | 0 | if (instance == NULL) { |
1082 | 0 | return NULL; |
1083 | 0 | } |
1084 | | |
1085 | 0 | opentelemetry__proto__profiles__v1development__attribute_unit__init(instance); |
1086 | |
|
1087 | 0 | return instance; |
1088 | 0 | } |
1089 | | |
1090 | | static |
1091 | | Opentelemetry__Proto__Profiles__V1development__Line * |
1092 | 0 | initialize_line() { |
1093 | 0 | Opentelemetry__Proto__Profiles__V1development__Line *instance; |
1094 | |
|
1095 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Line)); |
1096 | |
|
1097 | 0 | if (instance == NULL) { |
1098 | 0 | return NULL; |
1099 | 0 | } |
1100 | | |
1101 | 0 | opentelemetry__proto__profiles__v1development__line__init(instance); |
1102 | |
|
1103 | 0 | return instance; |
1104 | 0 | } |
1105 | | |
1106 | | static |
1107 | | Opentelemetry__Proto__Profiles__V1development__Link * |
1108 | 0 | initialize_link() { |
1109 | 0 | Opentelemetry__Proto__Profiles__V1development__Link *instance; |
1110 | |
|
1111 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Link)); |
1112 | |
|
1113 | 0 | if (instance == NULL) { |
1114 | 0 | return NULL; |
1115 | 0 | } |
1116 | | |
1117 | 0 | opentelemetry__proto__profiles__v1development__link__init(instance); |
1118 | |
|
1119 | 0 | return instance; |
1120 | 0 | } |
1121 | | |
1122 | | static |
1123 | | Opentelemetry__Proto__Profiles__V1development__Location * |
1124 | 0 | initialize_location(size_t line_count, size_t attribute_count) { |
1125 | 0 | Opentelemetry__Proto__Profiles__V1development__Location *instance; |
1126 | |
|
1127 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Location)); |
1128 | |
|
1129 | 0 | if (instance == NULL) { |
1130 | 0 | return NULL; |
1131 | 0 | } |
1132 | | |
1133 | 0 | opentelemetry__proto__profiles__v1development__location__init(instance); |
1134 | |
|
1135 | 0 | if (line_count > 0) { |
1136 | 0 | instance->line = calloc(line_count, sizeof(void *)); |
1137 | |
|
1138 | 0 | if (instance->line == NULL) { |
1139 | 0 | destroy_location(instance); |
1140 | |
|
1141 | 0 | return NULL; |
1142 | 0 | } |
1143 | | |
1144 | 0 | instance->n_line = line_count; |
1145 | 0 | } |
1146 | | |
1147 | 0 | if (attribute_count > 0) { |
1148 | 0 | instance->attributes = calloc(attribute_count, sizeof(uint64_t)); |
1149 | |
|
1150 | 0 | if (instance->attributes == NULL) { |
1151 | 0 | destroy_location(instance); |
1152 | |
|
1153 | 0 | return NULL; |
1154 | 0 | } |
1155 | | |
1156 | 0 | instance->n_attributes = attribute_count; |
1157 | 0 | } |
1158 | | |
1159 | 0 | return instance; |
1160 | 0 | } |
1161 | | |
1162 | | static |
1163 | | Opentelemetry__Proto__Profiles__V1development__Function * |
1164 | 0 | initialize_function() { |
1165 | 0 | Opentelemetry__Proto__Profiles__V1development__Function *instance; |
1166 | |
|
1167 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Function)); |
1168 | |
|
1169 | 0 | if (instance == NULL) { |
1170 | 0 | return NULL; |
1171 | 0 | } |
1172 | | |
1173 | 0 | opentelemetry__proto__profiles__v1development__function__init(instance); |
1174 | |
|
1175 | 0 | return instance; |
1176 | 0 | } |
1177 | | |
1178 | | static |
1179 | | Opentelemetry__Proto__Profiles__V1development__Mapping * |
1180 | 0 | initialize_mapping(size_t attribute_count) { |
1181 | 0 | Opentelemetry__Proto__Profiles__V1development__Mapping *instance; |
1182 | |
|
1183 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Mapping)); |
1184 | |
|
1185 | 0 | if (instance == NULL) { |
1186 | 0 | return NULL; |
1187 | 0 | } |
1188 | | |
1189 | 0 | opentelemetry__proto__profiles__v1development__mapping__init(instance); |
1190 | |
|
1191 | 0 | if (attribute_count > 0) { |
1192 | 0 | instance->attributes = calloc(attribute_count, sizeof(uint64_t)); |
1193 | |
|
1194 | 0 | if (instance->attributes == NULL) { |
1195 | 0 | destroy_mapping(instance); |
1196 | |
|
1197 | 0 | return NULL; |
1198 | 0 | } |
1199 | | |
1200 | 0 | instance->n_attributes = attribute_count; |
1201 | 0 | } |
1202 | | |
1203 | 0 | return instance; |
1204 | 0 | } |
1205 | | |
1206 | | static |
1207 | | Opentelemetry__Proto__Common__V1__InstrumentationScope * |
1208 | 0 | initialize_instrumentation_scope(size_t attribute_count) { |
1209 | 0 | Opentelemetry__Proto__Common__V1__InstrumentationScope *instance; |
1210 | |
|
1211 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__InstrumentationScope)); |
1212 | |
|
1213 | 0 | if (instance == NULL) { |
1214 | 0 | return NULL; |
1215 | 0 | } |
1216 | | |
1217 | 0 | opentelemetry__proto__common__v1__instrumentation_scope__init(instance); |
1218 | |
|
1219 | 0 | if (attribute_count > 0) { |
1220 | 0 | instance->attributes = initialize_attribute_list(attribute_count); |
1221 | |
|
1222 | 0 | if (instance->attributes == NULL) { |
1223 | 0 | free(instance); |
1224 | |
|
1225 | 0 | return NULL; |
1226 | 0 | } |
1227 | 0 | } |
1228 | | |
1229 | 0 | instance->n_attributes = attribute_count; |
1230 | |
|
1231 | 0 | return instance; |
1232 | 0 | } |
1233 | | |
1234 | | static |
1235 | | Opentelemetry__Proto__Profiles__V1development__Profile * |
1236 | | initialize_profile( |
1237 | | size_t sample_type_count, |
1238 | | size_t sample_count, |
1239 | | size_t mapping_count, |
1240 | | size_t location_count, |
1241 | | size_t location_index_count, |
1242 | | size_t function_count, |
1243 | | size_t attribute_count, |
1244 | | size_t attribute_unit_count, |
1245 | | size_t link_count, |
1246 | | size_t string_count, |
1247 | 0 | size_t comment_count) { |
1248 | 0 | Opentelemetry__Proto__Profiles__V1development__Profile *instance; |
1249 | |
|
1250 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__Profile)); |
1251 | |
|
1252 | 0 | if (instance == NULL) { |
1253 | 0 | return NULL; |
1254 | 0 | } |
1255 | | |
1256 | 0 | opentelemetry__proto__profiles__v1development__profile__init(instance); |
1257 | |
|
1258 | 0 | if (sample_type_count > 0) { |
1259 | 0 | instance->sample_type = calloc(sample_type_count, sizeof(void *)); |
1260 | |
|
1261 | 0 | if (instance->sample_type == NULL) { |
1262 | 0 | destroy_profile(instance); |
1263 | |
|
1264 | 0 | return NULL; |
1265 | 0 | } |
1266 | | |
1267 | 0 | instance->n_sample_type = sample_type_count; |
1268 | 0 | } |
1269 | | |
1270 | 0 | if (sample_count > 0) { |
1271 | 0 | instance->sample = calloc(sample_count, sizeof(void *)); |
1272 | |
|
1273 | 0 | if (instance->sample == NULL) { |
1274 | 0 | destroy_profile(instance); |
1275 | |
|
1276 | 0 | return NULL; |
1277 | 0 | } |
1278 | | |
1279 | 0 | instance->n_sample = sample_count; |
1280 | 0 | } |
1281 | | |
1282 | 0 | if (mapping_count > 0) { |
1283 | 0 | instance->mapping = calloc(mapping_count, sizeof(void *)); |
1284 | |
|
1285 | 0 | if (instance->mapping == NULL) { |
1286 | 0 | destroy_profile(instance); |
1287 | |
|
1288 | 0 | return NULL; |
1289 | 0 | } |
1290 | | |
1291 | 0 | instance->n_mapping = mapping_count; |
1292 | 0 | } |
1293 | | |
1294 | 0 | if (location_count > 0) { |
1295 | 0 | instance->location = calloc(location_count, sizeof(void *)); |
1296 | |
|
1297 | 0 | if (instance->location == NULL) { |
1298 | 0 | destroy_profile(instance); |
1299 | |
|
1300 | 0 | return NULL; |
1301 | 0 | } |
1302 | | |
1303 | 0 | instance->n_location = location_count; |
1304 | 0 | } |
1305 | | |
1306 | 0 | if (location_index_count > 0) { |
1307 | 0 | instance->location_indices = calloc(location_index_count, sizeof(uint64_t)); |
1308 | |
|
1309 | 0 | if (instance->location_indices == NULL) { |
1310 | 0 | destroy_profile(instance); |
1311 | |
|
1312 | 0 | return NULL; |
1313 | 0 | } |
1314 | | |
1315 | 0 | instance->n_location_indices = location_index_count; |
1316 | 0 | } |
1317 | | |
1318 | 0 | if (function_count > 0) { |
1319 | 0 | instance->function = calloc(function_count, sizeof(void *)); |
1320 | |
|
1321 | 0 | if (instance->function == NULL) { |
1322 | 0 | destroy_profile(instance); |
1323 | |
|
1324 | 0 | return NULL; |
1325 | 0 | } |
1326 | | |
1327 | 0 | instance->n_function = function_count; |
1328 | 0 | } |
1329 | | |
1330 | 0 | if (attribute_count > 0) { |
1331 | 0 | instance->attribute_table = calloc(attribute_count, sizeof(void *)); |
1332 | |
|
1333 | 0 | if (instance->attribute_table == NULL) { |
1334 | 0 | destroy_profile(instance); |
1335 | |
|
1336 | 0 | return NULL; |
1337 | 0 | } |
1338 | | |
1339 | 0 | instance->n_attribute_table = attribute_count; |
1340 | 0 | } |
1341 | | |
1342 | 0 | if (attribute_unit_count > 0) { |
1343 | 0 | instance->attribute_units = calloc(attribute_unit_count, sizeof(void *)); |
1344 | |
|
1345 | 0 | if (instance->attribute_units == NULL) { |
1346 | 0 | destroy_profile(instance); |
1347 | |
|
1348 | 0 | return NULL; |
1349 | 0 | } |
1350 | | |
1351 | 0 | instance->n_attribute_units = attribute_unit_count; |
1352 | 0 | } |
1353 | | |
1354 | 0 | if (link_count > 0) { |
1355 | 0 | instance->link_table = calloc(link_count, sizeof(void *)); |
1356 | |
|
1357 | 0 | if (instance->link_table == NULL) { |
1358 | 0 | destroy_profile(instance); |
1359 | |
|
1360 | 0 | return NULL; |
1361 | 0 | } |
1362 | | |
1363 | 0 | instance->n_link_table = link_count; |
1364 | 0 | } |
1365 | | |
1366 | 0 | if (string_count > 0) { |
1367 | 0 | instance->string_table = calloc(string_count, sizeof(void *)); |
1368 | |
|
1369 | 0 | if (instance->string_table == NULL) { |
1370 | 0 | destroy_profile(instance); |
1371 | |
|
1372 | 0 | return NULL; |
1373 | 0 | } |
1374 | | |
1375 | 0 | instance->n_string_table = string_count; |
1376 | 0 | } |
1377 | | |
1378 | 0 | if (comment_count > 0) { |
1379 | 0 | instance->comment = calloc(comment_count, sizeof(void *)); |
1380 | |
|
1381 | 0 | if (instance->comment == NULL) { |
1382 | 0 | destroy_profile(instance); |
1383 | |
|
1384 | 0 | return NULL; |
1385 | 0 | } |
1386 | | |
1387 | 0 | instance->n_comment = comment_count; |
1388 | 0 | } |
1389 | | |
1390 | 0 | return instance; |
1391 | 0 | } |
1392 | | |
1393 | | |
1394 | | static |
1395 | | Opentelemetry__Proto__Profiles__V1development__ProfileContainer * |
1396 | 0 | initialize_profile_container(size_t attribute_count) { |
1397 | 0 | Opentelemetry__Proto__Profiles__V1development__ProfileContainer *instance; |
1398 | |
|
1399 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__ProfileContainer)); |
1400 | |
|
1401 | 0 | if (instance == NULL) { |
1402 | 0 | return NULL; |
1403 | 0 | } |
1404 | | |
1405 | 0 | opentelemetry__proto__profiles__v1development__profile_container__init(instance); |
1406 | |
|
1407 | 0 | if (attribute_count > 0) { |
1408 | 0 | instance->attributes = initialize_attribute_list(attribute_count); |
1409 | |
|
1410 | 0 | if (instance->attributes == NULL) { |
1411 | 0 | free(instance); |
1412 | |
|
1413 | 0 | return NULL; |
1414 | 0 | } |
1415 | 0 | } |
1416 | | |
1417 | 0 | instance->n_attributes = attribute_count; |
1418 | |
|
1419 | 0 | return instance; |
1420 | 0 | } |
1421 | | |
1422 | | static |
1423 | | Opentelemetry__Proto__Profiles__V1development__ScopeProfiles * |
1424 | 0 | initialize_scope_profiles(size_t profiles_count) { |
1425 | 0 | Opentelemetry__Proto__Profiles__V1development__ScopeProfiles *instance; |
1426 | |
|
1427 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__ScopeProfiles)); |
1428 | |
|
1429 | 0 | if (instance == NULL) { |
1430 | 0 | return NULL; |
1431 | 0 | } |
1432 | | |
1433 | 0 | opentelemetry__proto__profiles__v1development__scope_profiles__init(instance); |
1434 | |
|
1435 | 0 | instance->profiles = calloc(profiles_count, sizeof(void *)); |
1436 | |
|
1437 | 0 | if (instance->profiles == NULL) { |
1438 | 0 | free(instance); |
1439 | |
|
1440 | 0 | return NULL; |
1441 | 0 | } |
1442 | | |
1443 | 0 | instance->n_profiles = profiles_count; |
1444 | |
|
1445 | 0 | return instance; |
1446 | 0 | } |
1447 | | |
1448 | | static |
1449 | | Opentelemetry__Proto__Profiles__V1development__ResourceProfiles * |
1450 | 0 | initialize_resource_profiles(size_t scope_profiles_count) { |
1451 | 0 | Opentelemetry__Proto__Profiles__V1development__ResourceProfiles *instance; |
1452 | |
|
1453 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Profiles__V1development__ResourceProfiles)); |
1454 | |
|
1455 | 0 | if (instance == NULL) { |
1456 | 0 | return NULL; |
1457 | 0 | } |
1458 | | |
1459 | 0 | opentelemetry__proto__profiles__v1development__resource_profiles__init(instance); |
1460 | |
|
1461 | 0 | instance->scope_profiles = calloc(scope_profiles_count, sizeof(void *)); |
1462 | |
|
1463 | 0 | if (instance->scope_profiles == NULL) { |
1464 | 0 | free(instance); |
1465 | |
|
1466 | 0 | return NULL; |
1467 | 0 | } |
1468 | | |
1469 | 0 | instance->n_scope_profiles = scope_profiles_count; |
1470 | |
|
1471 | 0 | return instance; |
1472 | 0 | } |
1473 | | |
1474 | | |
1475 | | static |
1476 | | Opentelemetry__Proto__Collector__Profiles__V1development__ExportProfilesServiceRequest * |
1477 | 0 | initialize_export_profiles_service_request(size_t resource_profiles_count) { |
1478 | 0 | Opentelemetry__Proto__Collector__Profiles__V1development__ExportProfilesServiceRequest *instance; |
1479 | |
|
1480 | 0 | instance = calloc(1, sizeof(Opentelemetry__Proto__Collector__Profiles__V1development__ExportProfilesServiceRequest)); |
1481 | |
|
1482 | 0 | if (instance == NULL) { |
1483 | 0 | return NULL; |
1484 | 0 | } |
1485 | | |
1486 | 0 | opentelemetry__proto__collector__profiles__v1development__export_profiles_service_request__init(instance); |
1487 | |
|
1488 | 0 | instance->resource_profiles = calloc(resource_profiles_count, sizeof(void *)); |
1489 | |
|
1490 | 0 | if (instance->resource_profiles == NULL) { |
1491 | 0 | free(instance); |
1492 | |
|
1493 | 0 | return NULL; |
1494 | 0 | } |
1495 | | |
1496 | 0 | instance->n_resource_profiles = resource_profiles_count; |
1497 | |
|
1498 | 0 | return instance; |
1499 | 0 | } |
1500 | | |
1501 | | |
1502 | | |
1503 | | |
1504 | | |
1505 | | static int pack_cprof_resource( |
1506 | | Opentelemetry__Proto__Resource__V1__Resource **output_instance, |
1507 | | struct cprof_resource *input_instance) |
1508 | 0 | { |
1509 | 0 | Opentelemetry__Proto__Resource__V1__Resource *otlp_resource; |
1510 | |
|
1511 | 0 | if (input_instance != NULL) { |
1512 | 0 | otlp_resource = initialize_resource(0); |
1513 | |
|
1514 | 0 | if (otlp_resource == NULL) { |
1515 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1516 | 0 | } |
1517 | | |
1518 | 0 | otlp_resource->attributes = cfl_kvlist_to_otlp_kvpair_list(input_instance->attributes); |
1519 | |
|
1520 | 0 | if (otlp_resource->attributes == NULL) { |
1521 | 0 | destroy_resource(otlp_resource); |
1522 | |
|
1523 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1524 | 0 | } |
1525 | | |
1526 | 0 | otlp_resource->n_attributes = cfl_kvlist_count(input_instance->attributes); |
1527 | |
|
1528 | 0 | otlp_resource->dropped_attributes_count = \ |
1529 | 0 | input_instance->dropped_attributes_count; |
1530 | |
|
1531 | 0 | *output_instance = otlp_resource; |
1532 | 0 | } |
1533 | | |
1534 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1535 | 0 | } |
1536 | | |
1537 | | static int pack_cprof_instrumentation_scope( |
1538 | | Opentelemetry__Proto__Common__V1__InstrumentationScope **output_instance, |
1539 | | struct cprof_instrumentation_scope *input_instance) |
1540 | 0 | { |
1541 | 0 | Opentelemetry__Proto__Common__V1__InstrumentationScope *otlp_instrumentation_scope; |
1542 | |
|
1543 | 0 | if (input_instance != NULL) { |
1544 | 0 | otlp_instrumentation_scope = initialize_instrumentation_scope(0); |
1545 | |
|
1546 | 0 | if (otlp_instrumentation_scope == NULL) { |
1547 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1548 | 0 | } |
1549 | | |
1550 | 0 | otlp_instrumentation_scope->attributes = cfl_kvlist_to_otlp_kvpair_list(input_instance->attributes); |
1551 | |
|
1552 | 0 | if (otlp_instrumentation_scope->attributes == NULL) { |
1553 | 0 | destroy_instrumentation_scope(otlp_instrumentation_scope); |
1554 | |
|
1555 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1556 | 0 | } |
1557 | | |
1558 | 0 | otlp_instrumentation_scope->n_attributes = cfl_kvlist_count(input_instance->attributes); |
1559 | |
|
1560 | 0 | if (input_instance->name != NULL) { |
1561 | 0 | otlp_instrumentation_scope->name = cfl_sds_create(input_instance->name); |
1562 | |
|
1563 | 0 | if (otlp_instrumentation_scope->name == NULL) { |
1564 | 0 | destroy_instrumentation_scope(otlp_instrumentation_scope); |
1565 | |
|
1566 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1567 | 0 | } |
1568 | 0 | } |
1569 | | |
1570 | 0 | if (input_instance->version != NULL) { |
1571 | 0 | otlp_instrumentation_scope->version = cfl_sds_create(input_instance->version); |
1572 | |
|
1573 | 0 | if (otlp_instrumentation_scope->version == NULL) { |
1574 | 0 | destroy_instrumentation_scope(otlp_instrumentation_scope); |
1575 | |
|
1576 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1577 | 0 | } |
1578 | 0 | } |
1579 | | |
1580 | 0 | otlp_instrumentation_scope->dropped_attributes_count = \ |
1581 | 0 | input_instance->dropped_attributes_count; |
1582 | |
|
1583 | 0 | *output_instance = otlp_instrumentation_scope; |
1584 | 0 | } |
1585 | | |
1586 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1587 | 0 | } |
1588 | | |
1589 | | static int pack_cprof_value_type( |
1590 | | Opentelemetry__Proto__Profiles__V1development__ValueType **output_instance, |
1591 | | struct cprof_value_type *input_instance) |
1592 | 0 | { |
1593 | 0 | Opentelemetry__Proto__Profiles__V1development__ValueType *otlp_value_type; |
1594 | |
|
1595 | 0 | otlp_value_type = initialize_value_type(); |
1596 | |
|
1597 | 0 | if (otlp_value_type == NULL) { |
1598 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1599 | 0 | } |
1600 | | |
1601 | 0 | otlp_value_type->type = input_instance->type; |
1602 | 0 | otlp_value_type->unit = input_instance->unit; |
1603 | 0 | otlp_value_type->aggregation_temporality = input_instance->aggregation_temporality; |
1604 | |
|
1605 | 0 | *output_instance = otlp_value_type; |
1606 | |
|
1607 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1608 | 0 | } |
1609 | | |
1610 | | static int pack_cprof_sample( |
1611 | | Opentelemetry__Proto__Profiles__V1development__Sample **output_instance, |
1612 | | struct cprof_sample *input_instance) |
1613 | 0 | { |
1614 | 0 | Opentelemetry__Proto__Profiles__V1development__Sample *otlp_sample; |
1615 | 0 | size_t index; |
1616 | |
|
1617 | 0 | otlp_sample = initialize_sample(input_instance->location_index_count, |
1618 | 0 | input_instance->value_count, |
1619 | 0 | input_instance->attributes_count, |
1620 | 0 | input_instance->timestamps_count); |
1621 | |
|
1622 | 0 | if (otlp_sample == NULL) { |
1623 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1624 | 0 | } |
1625 | | |
1626 | 0 | for (index = 0 ; |
1627 | 0 | index < input_instance->location_index_count ; |
1628 | 0 | index++) { |
1629 | 0 | otlp_sample->location_index[index] = input_instance->location_index[index]; |
1630 | 0 | } |
1631 | |
|
1632 | 0 | otlp_sample->locations_start_index = input_instance->locations_start_index; |
1633 | 0 | otlp_sample->locations_length = input_instance->locations_length; |
1634 | |
|
1635 | 0 | for (index = 0 ; |
1636 | 0 | index < input_instance->value_count ; |
1637 | 0 | index++) { |
1638 | 0 | otlp_sample->value[index] = input_instance->values[index]; |
1639 | 0 | } |
1640 | |
|
1641 | 0 | for (index = 0 ; |
1642 | 0 | index < input_instance->attributes_count ; |
1643 | 0 | index++) { |
1644 | 0 | otlp_sample->attributes[index] = input_instance->attributes[index]; |
1645 | 0 | } |
1646 | |
|
1647 | 0 | otlp_sample->link = input_instance->link; |
1648 | |
|
1649 | 0 | for (index = 0 ; |
1650 | 0 | index < input_instance->timestamps_count ; |
1651 | 0 | index++) { |
1652 | 0 | otlp_sample->timestamps_unix_nano[index] = input_instance->timestamps_unix_nano[index]; |
1653 | 0 | } |
1654 | |
|
1655 | 0 | *output_instance = otlp_sample; |
1656 | |
|
1657 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1658 | 0 | } |
1659 | | |
1660 | | |
1661 | | static int pack_cprof_mapping( |
1662 | | Opentelemetry__Proto__Profiles__V1development__Mapping **output_instance, |
1663 | | struct cprof_mapping *input_instance) |
1664 | 0 | { |
1665 | 0 | Opentelemetry__Proto__Profiles__V1development__Mapping *otlp_mapping; |
1666 | 0 | size_t index; |
1667 | |
|
1668 | 0 | otlp_mapping = initialize_mapping(input_instance->attributes_count); |
1669 | |
|
1670 | 0 | if (otlp_mapping == NULL) { |
1671 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1672 | 0 | } |
1673 | | |
1674 | 0 | otlp_mapping->id = input_instance->id; |
1675 | 0 | otlp_mapping->memory_start = input_instance->memory_start; |
1676 | 0 | otlp_mapping->memory_limit = input_instance->memory_limit; |
1677 | 0 | otlp_mapping->file_offset = input_instance->file_offset; |
1678 | 0 | otlp_mapping->filename = input_instance->filename; |
1679 | |
|
1680 | 0 | for (index = 0 ; |
1681 | 0 | index < input_instance->attributes_count ; |
1682 | 0 | index++) { |
1683 | 0 | otlp_mapping->attributes[index] = input_instance->attributes[index]; |
1684 | 0 | } |
1685 | |
|
1686 | 0 | otlp_mapping->has_functions = input_instance->has_functions; |
1687 | 0 | otlp_mapping->has_filenames = input_instance->has_filenames; |
1688 | 0 | otlp_mapping->has_line_numbers = input_instance->has_line_numbers; |
1689 | 0 | otlp_mapping->has_inline_frames = input_instance->has_inline_frames; |
1690 | |
|
1691 | 0 | *output_instance = otlp_mapping; |
1692 | |
|
1693 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1694 | 0 | } |
1695 | | |
1696 | | |
1697 | | |
1698 | | static int pack_cprof_line( |
1699 | | Opentelemetry__Proto__Profiles__V1development__Line **output_instance, |
1700 | | struct cprof_line *input_instance) |
1701 | 0 | { |
1702 | 0 | Opentelemetry__Proto__Profiles__V1development__Line *otlp_line; |
1703 | |
|
1704 | 0 | otlp_line = initialize_line(); |
1705 | |
|
1706 | 0 | if (otlp_line == NULL) { |
1707 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1708 | 0 | } |
1709 | | |
1710 | 0 | otlp_line->function_index = input_instance->function_index; |
1711 | 0 | otlp_line->line = input_instance->line; |
1712 | 0 | otlp_line->column = input_instance->column; |
1713 | |
|
1714 | 0 | *output_instance = otlp_line; |
1715 | |
|
1716 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1717 | 0 | } |
1718 | | |
1719 | | static int pack_cprof_location( |
1720 | | Opentelemetry__Proto__Profiles__V1development__Location **output_instance, |
1721 | | struct cprof_location *input_instance) |
1722 | 0 | { |
1723 | 0 | Opentelemetry__Proto__Profiles__V1development__Location *otlp_location; |
1724 | 0 | struct cfl_list *iterator; |
1725 | 0 | int result; |
1726 | 0 | struct cprof_line *line; |
1727 | 0 | size_t index; |
1728 | |
|
1729 | 0 | otlp_location = initialize_location(cfl_list_size(&input_instance->lines), |
1730 | 0 | input_instance->attributes_count); |
1731 | |
|
1732 | 0 | if (otlp_location == NULL) { |
1733 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1734 | 0 | } |
1735 | | |
1736 | 0 | otlp_location->id = input_instance->id; |
1737 | 0 | otlp_location->mapping_index = input_instance->mapping_index; |
1738 | 0 | otlp_location->address = input_instance->address; |
1739 | | |
1740 | |
|
1741 | 0 | index = 0; |
1742 | 0 | cfl_list_foreach(iterator, |
1743 | 0 | &input_instance->lines) { |
1744 | 0 | line = cfl_list_entry( |
1745 | 0 | iterator, |
1746 | 0 | struct cprof_line, _head); |
1747 | |
|
1748 | 0 | result = pack_cprof_line( |
1749 | 0 | &otlp_location->line[index], |
1750 | 0 | line); |
1751 | |
|
1752 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
1753 | 0 | destroy_location(otlp_location); |
1754 | |
|
1755 | 0 | return result; |
1756 | 0 | } |
1757 | | |
1758 | 0 | index++; |
1759 | 0 | } |
1760 | | |
1761 | 0 | otlp_location->is_folded = input_instance->is_folded; |
1762 | |
|
1763 | 0 | for (index = 0 ; |
1764 | 0 | index < input_instance->attributes_count ; |
1765 | 0 | index++) { |
1766 | 0 | otlp_location->attributes[index] = input_instance->attributes[index]; |
1767 | 0 | } |
1768 | |
|
1769 | 0 | *output_instance = otlp_location; |
1770 | |
|
1771 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1772 | 0 | } |
1773 | | |
1774 | | static int pack_cprof_function( |
1775 | | Opentelemetry__Proto__Profiles__V1development__Function **output_instance, |
1776 | | struct cprof_function *input_instance) |
1777 | 0 | { |
1778 | 0 | Opentelemetry__Proto__Profiles__V1development__Function *otlp_function; |
1779 | |
|
1780 | 0 | otlp_function = initialize_function(); |
1781 | |
|
1782 | 0 | if (otlp_function == NULL) { |
1783 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1784 | 0 | } |
1785 | | |
1786 | 0 | otlp_function->id = input_instance->id; |
1787 | 0 | otlp_function->name = input_instance->name; |
1788 | 0 | otlp_function->system_name = input_instance->system_name; |
1789 | 0 | otlp_function->filename = input_instance->filename; |
1790 | 0 | otlp_function->start_line = input_instance->start_line; |
1791 | |
|
1792 | 0 | *output_instance = otlp_function; |
1793 | |
|
1794 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1795 | 0 | } |
1796 | | |
1797 | | static int pack_cprof_attribute_unit( |
1798 | | Opentelemetry__Proto__Profiles__V1development__AttributeUnit **output_instance, |
1799 | | struct cprof_attribute_unit *input_instance) |
1800 | 0 | { |
1801 | 0 | Opentelemetry__Proto__Profiles__V1development__AttributeUnit *otlp_attribute_unit; |
1802 | |
|
1803 | 0 | otlp_attribute_unit = initialize_attribute_unit(); |
1804 | |
|
1805 | 0 | if (otlp_attribute_unit == NULL) { |
1806 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1807 | 0 | } |
1808 | | |
1809 | 0 | otlp_attribute_unit->attribute_key = input_instance->attribute_key; |
1810 | 0 | otlp_attribute_unit->unit = input_instance->unit; |
1811 | |
|
1812 | 0 | *output_instance = otlp_attribute_unit; |
1813 | |
|
1814 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1815 | 0 | } |
1816 | | |
1817 | | static int pack_cprof_link( |
1818 | | Opentelemetry__Proto__Profiles__V1development__Link **output_instance, |
1819 | | struct cprof_link *input_instance) |
1820 | 0 | { |
1821 | 0 | Opentelemetry__Proto__Profiles__V1development__Link *otlp_link; |
1822 | |
|
1823 | 0 | otlp_link = initialize_link(); |
1824 | |
|
1825 | 0 | if (otlp_link == NULL) { |
1826 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1827 | 0 | } |
1828 | | |
1829 | 0 | otlp_link->trace_id.data = \ |
1830 | 0 | (uint8_t *) cfl_sds_create_len((const char *) input_instance->trace_id, |
1831 | 0 | sizeof(input_instance->trace_id)); |
1832 | |
|
1833 | 0 | if (otlp_link->trace_id.data == NULL) { |
1834 | 0 | destroy_link(otlp_link); |
1835 | |
|
1836 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1837 | 0 | } |
1838 | | |
1839 | 0 | otlp_link->trace_id.len = sizeof(input_instance->trace_id); |
1840 | | |
1841 | |
|
1842 | 0 | otlp_link->span_id.data = \ |
1843 | 0 | (uint8_t *) cfl_sds_create_len((const char *) input_instance->span_id, |
1844 | 0 | sizeof(input_instance->span_id)); |
1845 | |
|
1846 | 0 | if (otlp_link->span_id.data == NULL) { |
1847 | 0 | destroy_link(otlp_link); |
1848 | |
|
1849 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1850 | 0 | } |
1851 | | |
1852 | 0 | otlp_link->span_id.len = sizeof(input_instance->span_id); |
1853 | | |
1854 | |
|
1855 | 0 | *output_instance = otlp_link; |
1856 | |
|
1857 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
1858 | 0 | } |
1859 | | |
1860 | | static int pack_cprof_profile( |
1861 | | Opentelemetry__Proto__Profiles__V1development__Profile **output_instance, |
1862 | | struct cprof_profile *input_instance) |
1863 | 0 | { |
1864 | 0 | Opentelemetry__Proto__Profiles__V1development__Profile *otlp_profile; |
1865 | 0 | struct cfl_list *iterator; |
1866 | 0 | struct cprof_sample *sample; |
1867 | 0 | struct cprof_link *link; |
1868 | 0 | struct cprof_mapping *mapping; |
1869 | 0 | struct cprof_location *location; |
1870 | 0 | struct cprof_function *function; |
1871 | 0 | struct cprof_value_type *sample_type; |
1872 | 0 | struct cprof_attribute_unit *attribute_unit; |
1873 | 0 | int result; |
1874 | 0 | size_t index; |
1875 | |
|
1876 | 0 | otlp_profile = initialize_profile(cfl_list_size(&input_instance->sample_type), |
1877 | 0 | cfl_list_size(&input_instance->samples), |
1878 | 0 | cfl_list_size(&input_instance->mappings), |
1879 | 0 | cfl_list_size(&input_instance->locations), |
1880 | 0 | input_instance->location_indices_count, |
1881 | 0 | cfl_list_size(&input_instance->functions), |
1882 | 0 | 0, |
1883 | 0 | cfl_list_size(&input_instance->attribute_units), |
1884 | 0 | cfl_list_size(&input_instance->link_table), |
1885 | 0 | input_instance->string_table_count, |
1886 | 0 | input_instance->comments_count); |
1887 | |
|
1888 | 0 | if (otlp_profile == NULL) { |
1889 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
1890 | 0 | } |
1891 | | |
1892 | 0 | index = 0; |
1893 | 0 | cfl_list_foreach(iterator, |
1894 | 0 | &input_instance->sample_type) { |
1895 | 0 | sample_type = cfl_list_entry( |
1896 | 0 | iterator, |
1897 | 0 | struct cprof_value_type, _head); |
1898 | |
|
1899 | 0 | result = pack_cprof_value_type( |
1900 | 0 | &otlp_profile->sample_type[index], |
1901 | 0 | sample_type); |
1902 | |
|
1903 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
1904 | 0 | destroy_profile(otlp_profile); |
1905 | |
|
1906 | 0 | return result; |
1907 | 0 | } |
1908 | | |
1909 | 0 | index++; |
1910 | 0 | } |
1911 | | |
1912 | 0 | index = 0; |
1913 | 0 | cfl_list_foreach(iterator, |
1914 | 0 | &input_instance->samples) { |
1915 | 0 | sample = cfl_list_entry( |
1916 | 0 | iterator, |
1917 | 0 | struct cprof_sample, _head); |
1918 | |
|
1919 | 0 | result = pack_cprof_sample( |
1920 | 0 | &otlp_profile->sample[index], |
1921 | 0 | sample); |
1922 | |
|
1923 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
1924 | 0 | destroy_profile(otlp_profile); |
1925 | |
|
1926 | 0 | return result; |
1927 | 0 | } |
1928 | | |
1929 | 0 | index++; |
1930 | 0 | } |
1931 | | |
1932 | 0 | index = 0; |
1933 | 0 | cfl_list_foreach(iterator, |
1934 | 0 | &input_instance->mappings) { |
1935 | 0 | mapping = cfl_list_entry( |
1936 | 0 | iterator, |
1937 | 0 | struct cprof_mapping, _head); |
1938 | |
|
1939 | 0 | result = pack_cprof_mapping( |
1940 | 0 | &otlp_profile->mapping[index], |
1941 | 0 | mapping); |
1942 | |
|
1943 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
1944 | 0 | destroy_profile(otlp_profile); |
1945 | |
|
1946 | 0 | return result; |
1947 | 0 | } |
1948 | | |
1949 | 0 | index++; |
1950 | 0 | } |
1951 | | |
1952 | 0 | index = 0; |
1953 | 0 | cfl_list_foreach(iterator, |
1954 | 0 | &input_instance->locations) { |
1955 | 0 | location = cfl_list_entry( |
1956 | 0 | iterator, |
1957 | 0 | struct cprof_location, _head); |
1958 | |
|
1959 | 0 | result = pack_cprof_location( |
1960 | 0 | &otlp_profile->location[index], |
1961 | 0 | location); |
1962 | |
|
1963 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
1964 | 0 | destroy_profile(otlp_profile); |
1965 | |
|
1966 | 0 | return result; |
1967 | 0 | } |
1968 | | |
1969 | 0 | index++; |
1970 | 0 | } |
1971 | | |
1972 | 0 | for (index = 0 ; |
1973 | 0 | index < input_instance->location_indices_count ; |
1974 | 0 | index++) { |
1975 | 0 | otlp_profile->location_indices[index] = input_instance->location_indices[index]; |
1976 | 0 | } |
1977 | |
|
1978 | 0 | index = 0; |
1979 | 0 | cfl_list_foreach(iterator, |
1980 | 0 | &input_instance->functions) { |
1981 | 0 | function = cfl_list_entry( |
1982 | 0 | iterator, |
1983 | 0 | struct cprof_function, _head); |
1984 | |
|
1985 | 0 | result = pack_cprof_function( |
1986 | 0 | &otlp_profile->function[index], |
1987 | 0 | function); |
1988 | |
|
1989 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
1990 | 0 | destroy_profile(otlp_profile); |
1991 | |
|
1992 | 0 | return result; |
1993 | 0 | } |
1994 | | |
1995 | 0 | index++; |
1996 | 0 | } |
1997 | | |
1998 | 0 | if (input_instance->attribute_table != NULL) { |
1999 | 0 | otlp_profile->attribute_table = cfl_kvlist_to_otlp_kvpair_list(input_instance->attribute_table); |
2000 | |
|
2001 | 0 | if (otlp_profile->attribute_table == NULL) { |
2002 | 0 | destroy_profile(otlp_profile); |
2003 | |
|
2004 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2005 | 0 | } |
2006 | | |
2007 | 0 | otlp_profile->n_attribute_table = cfl_kvlist_count(input_instance->attribute_table); |
2008 | 0 | } |
2009 | | |
2010 | 0 | index = 0; |
2011 | 0 | cfl_list_foreach(iterator, |
2012 | 0 | &input_instance->attribute_units) { |
2013 | 0 | attribute_unit = cfl_list_entry( |
2014 | 0 | iterator, |
2015 | 0 | struct cprof_attribute_unit, _head); |
2016 | |
|
2017 | 0 | result = pack_cprof_attribute_unit( |
2018 | 0 | &otlp_profile->attribute_units[index], |
2019 | 0 | attribute_unit); |
2020 | |
|
2021 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2022 | 0 | destroy_profile(otlp_profile); |
2023 | |
|
2024 | 0 | return result; |
2025 | 0 | } |
2026 | | |
2027 | 0 | index++; |
2028 | 0 | } |
2029 | | |
2030 | 0 | index = 0; |
2031 | 0 | cfl_list_foreach(iterator, |
2032 | 0 | &input_instance->link_table) { |
2033 | 0 | link = cfl_list_entry( |
2034 | 0 | iterator, |
2035 | 0 | struct cprof_link, _head); |
2036 | |
|
2037 | 0 | result = pack_cprof_link( |
2038 | 0 | &otlp_profile->link_table[index], |
2039 | 0 | link); |
2040 | |
|
2041 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2042 | 0 | destroy_profile(otlp_profile); |
2043 | |
|
2044 | 0 | return result; |
2045 | 0 | } |
2046 | | |
2047 | 0 | index++; |
2048 | 0 | } |
2049 | | |
2050 | 0 | for (index = 0 ; |
2051 | 0 | index < input_instance->string_table_count ; |
2052 | 0 | index++) { |
2053 | 0 | otlp_profile->string_table[index] = cfl_sds_create(input_instance->string_table[index]); |
2054 | |
|
2055 | 0 | if (otlp_profile->string_table[index] == NULL) { |
2056 | 0 | destroy_profile(otlp_profile); |
2057 | |
|
2058 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2059 | 0 | } |
2060 | 0 | } |
2061 | | |
2062 | 0 | otlp_profile->drop_frames = input_instance->drop_frames; |
2063 | 0 | otlp_profile->keep_frames = input_instance->keep_frames; |
2064 | 0 | otlp_profile->time_nanos = input_instance->time_nanos; |
2065 | 0 | otlp_profile->duration_nanos = input_instance->duration_nanos; |
2066 | |
|
2067 | 0 | result = pack_cprof_value_type( |
2068 | 0 | &otlp_profile->period_type, |
2069 | 0 | &input_instance->period_type); |
2070 | |
|
2071 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2072 | 0 | destroy_profile(otlp_profile); |
2073 | |
|
2074 | 0 | return result; |
2075 | 0 | } |
2076 | | |
2077 | 0 | otlp_profile->period = input_instance->period; |
2078 | |
|
2079 | 0 | for (index = 0 ; |
2080 | 0 | index < input_instance->comments_count ; |
2081 | 0 | index++) { |
2082 | 0 | otlp_profile->comment[index] = input_instance->comments[index]; |
2083 | 0 | } |
2084 | |
|
2085 | 0 | otlp_profile->default_sample_type = input_instance->default_sample_type; |
2086 | |
|
2087 | 0 | *output_instance = otlp_profile; |
2088 | |
|
2089 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
2090 | 0 | } |
2091 | | |
2092 | | static int pack_cprof_profile_container( |
2093 | | Opentelemetry__Proto__Profiles__V1development__ProfileContainer **output_instance, |
2094 | | struct cprof_profile *input_instance) |
2095 | 0 | { |
2096 | 0 | Opentelemetry__Proto__Profiles__V1development__ProfileContainer *otlp_profile_container; |
2097 | 0 | int result; |
2098 | |
|
2099 | 0 | otlp_profile_container = initialize_profile_container(0); |
2100 | |
|
2101 | 0 | if (otlp_profile_container == NULL) { |
2102 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2103 | 0 | } |
2104 | | |
2105 | 0 | otlp_profile_container->profile_id.data = \ |
2106 | 0 | (uint8_t *) cfl_sds_create_len((const char *) input_instance->profile_id, |
2107 | 0 | sizeof(input_instance->profile_id)); |
2108 | |
|
2109 | 0 | if (otlp_profile_container->profile_id.data == NULL) { |
2110 | 0 | destroy_profile_container(otlp_profile_container); |
2111 | |
|
2112 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2113 | 0 | } |
2114 | | |
2115 | 0 | otlp_profile_container->profile_id.len = sizeof(input_instance->profile_id); |
2116 | |
|
2117 | 0 | otlp_profile_container->start_time_unix_nano = (uint64_t) input_instance->start_time_unix_nano; |
2118 | 0 | otlp_profile_container->end_time_unix_nano = (uint64_t) input_instance->end_time_unix_nano; |
2119 | |
|
2120 | 0 | otlp_profile_container->attributes = cfl_kvlist_to_otlp_kvpair_list(input_instance->attributes); |
2121 | |
|
2122 | 0 | if (otlp_profile_container->attributes == NULL) { |
2123 | 0 | destroy_profile_container(otlp_profile_container); |
2124 | |
|
2125 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2126 | 0 | } |
2127 | | |
2128 | 0 | otlp_profile_container->n_attributes = cfl_kvlist_count(input_instance->attributes); |
2129 | |
|
2130 | 0 | otlp_profile_container->dropped_attributes_count = input_instance->dropped_attributes_count; |
2131 | |
|
2132 | 0 | if (input_instance->original_payload_format != NULL) { |
2133 | 0 | otlp_profile_container->original_payload_format = \ |
2134 | 0 | cfl_sds_create(input_instance->original_payload_format); |
2135 | |
|
2136 | 0 | if (otlp_profile_container->original_payload_format == NULL) { |
2137 | 0 | destroy_profile_container(otlp_profile_container); |
2138 | |
|
2139 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2140 | 0 | } |
2141 | 0 | } |
2142 | | |
2143 | 0 | if (input_instance->original_payload != NULL) { |
2144 | 0 | otlp_profile_container->original_payload.data = \ |
2145 | 0 | (uint8_t *) cfl_sds_create_len(input_instance->original_payload, |
2146 | 0 | cfl_sds_len(input_instance->original_payload)); |
2147 | |
|
2148 | 0 | if (otlp_profile_container->original_payload.data == NULL) { |
2149 | 0 | destroy_profile_container(otlp_profile_container); |
2150 | |
|
2151 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2152 | 0 | } |
2153 | | |
2154 | 0 | otlp_profile_container->original_payload.len = cfl_sds_len(input_instance->original_payload); |
2155 | 0 | } |
2156 | | |
2157 | 0 | result = pack_cprof_profile(&otlp_profile_container->profile, input_instance); |
2158 | |
|
2159 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2160 | 0 | destroy_profile_container(otlp_profile_container); |
2161 | |
|
2162 | 0 | return result; |
2163 | 0 | } |
2164 | | |
2165 | 0 | *output_instance = otlp_profile_container; |
2166 | |
|
2167 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
2168 | 0 | } |
2169 | | |
2170 | | |
2171 | | static int pack_cprof_scope_profiles( |
2172 | | Opentelemetry__Proto__Profiles__V1development__ScopeProfiles **output_instance, |
2173 | | struct cprof_scope_profiles *input_instance) |
2174 | 0 | { |
2175 | 0 | Opentelemetry__Proto__Profiles__V1development__ScopeProfiles *otlp_scope_profiles; |
2176 | 0 | struct cfl_list *iterator; |
2177 | 0 | struct cprof_profile *profile; |
2178 | 0 | int result; |
2179 | 0 | size_t index; |
2180 | |
|
2181 | 0 | otlp_scope_profiles = initialize_scope_profiles(cfl_list_size(&input_instance->profiles)); |
2182 | |
|
2183 | 0 | if (otlp_scope_profiles == NULL) { |
2184 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2185 | 0 | } |
2186 | | |
2187 | 0 | if (input_instance->scope != NULL) { |
2188 | 0 | result = pack_cprof_instrumentation_scope(&otlp_scope_profiles->scope, input_instance->scope); |
2189 | |
|
2190 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2191 | 0 | return result; |
2192 | 0 | } |
2193 | 0 | } |
2194 | | |
2195 | 0 | index = 0; |
2196 | 0 | cfl_list_foreach(iterator, |
2197 | 0 | &input_instance->profiles) { |
2198 | 0 | profile = cfl_list_entry( |
2199 | 0 | iterator, |
2200 | 0 | struct cprof_profile, _head); |
2201 | |
|
2202 | 0 | result = pack_cprof_profile_container( |
2203 | 0 | &otlp_scope_profiles->profiles[index], |
2204 | 0 | profile); |
2205 | |
|
2206 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2207 | 0 | destroy_scope_profiles(otlp_scope_profiles); |
2208 | |
|
2209 | 0 | return result; |
2210 | 0 | } |
2211 | | |
2212 | 0 | index++; |
2213 | 0 | } |
2214 | | |
2215 | 0 | if (input_instance->schema_url != NULL) { |
2216 | 0 | otlp_scope_profiles->schema_url = cfl_sds_create(input_instance->schema_url); |
2217 | |
|
2218 | 0 | if (otlp_scope_profiles->schema_url == NULL) { |
2219 | 0 | destroy_scope_profiles(otlp_scope_profiles); |
2220 | |
|
2221 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2222 | 0 | } |
2223 | 0 | } |
2224 | | |
2225 | 0 | *output_instance = otlp_scope_profiles; |
2226 | |
|
2227 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
2228 | 0 | } |
2229 | | |
2230 | | static int pack_cprof_resource_profiles( |
2231 | | Opentelemetry__Proto__Profiles__V1development__ResourceProfiles **output_instance, |
2232 | | struct cprof_resource_profiles *input_instance) |
2233 | 0 | { |
2234 | 0 | Opentelemetry__Proto__Profiles__V1development__ResourceProfiles *otlp_resource_profiles; |
2235 | 0 | struct cprof_scope_profiles *scope_profiles; |
2236 | 0 | struct cfl_list *iterator; |
2237 | 0 | int result; |
2238 | 0 | size_t index; |
2239 | |
|
2240 | 0 | otlp_resource_profiles = initialize_resource_profiles(cfl_list_size(&input_instance->scope_profiles)); |
2241 | |
|
2242 | 0 | if (otlp_resource_profiles == NULL) { |
2243 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2244 | 0 | } |
2245 | | |
2246 | 0 | result = pack_cprof_resource(&otlp_resource_profiles->resource, input_instance->resource); |
2247 | |
|
2248 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2249 | 0 | return result; |
2250 | 0 | } |
2251 | | |
2252 | 0 | index = 0; |
2253 | 0 | cfl_list_foreach(iterator, |
2254 | 0 | &input_instance->scope_profiles) { |
2255 | 0 | scope_profiles = cfl_list_entry( |
2256 | 0 | iterator, |
2257 | 0 | struct cprof_scope_profiles, _head); |
2258 | |
|
2259 | 0 | result = pack_cprof_scope_profiles( |
2260 | 0 | &otlp_resource_profiles->scope_profiles[index], |
2261 | 0 | scope_profiles); |
2262 | |
|
2263 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2264 | 0 | destroy_resource_profiles(otlp_resource_profiles); |
2265 | |
|
2266 | 0 | return result; |
2267 | 0 | } |
2268 | | |
2269 | 0 | index++; |
2270 | 0 | } |
2271 | | |
2272 | 0 | if (input_instance->schema_url != NULL) { |
2273 | 0 | otlp_resource_profiles->schema_url = cfl_sds_create(input_instance->schema_url); |
2274 | |
|
2275 | 0 | if (otlp_resource_profiles->schema_url == NULL) { |
2276 | 0 | destroy_resource_profiles(otlp_resource_profiles); |
2277 | |
|
2278 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2279 | 0 | } |
2280 | 0 | } |
2281 | | |
2282 | 0 | *output_instance = otlp_resource_profiles; |
2283 | |
|
2284 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
2285 | 0 | } |
2286 | | |
2287 | | |
2288 | | static int pack_context_profiles( |
2289 | | struct cprof_opentelemetry_encoding_context *context, |
2290 | | struct cprof *profile) |
2291 | 0 | { |
2292 | 0 | size_t index; |
2293 | 0 | int result; |
2294 | 0 | struct cfl_list *iterator; |
2295 | 0 | struct cprof_resource_profiles *resource_profiles; |
2296 | |
|
2297 | 0 | context->export_service_request = \ |
2298 | 0 | initialize_export_profiles_service_request(cfl_list_size(&profile->profiles)); |
2299 | |
|
2300 | 0 | if (context->export_service_request == NULL) { |
2301 | 0 | return CPROF_ENCODE_OPENTELEMETRY_ALLOCATION_ERROR; |
2302 | 0 | } |
2303 | | |
2304 | 0 | index = 0; |
2305 | 0 | cfl_list_foreach(iterator, |
2306 | 0 | &profile->profiles) { |
2307 | 0 | resource_profiles = cfl_list_entry( |
2308 | 0 | iterator, |
2309 | 0 | struct cprof_resource_profiles, _head); |
2310 | |
|
2311 | 0 | result = pack_cprof_resource_profiles( |
2312 | 0 | &context->export_service_request->resource_profiles[index], |
2313 | 0 | resource_profiles); |
2314 | |
|
2315 | 0 | if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2316 | 0 | destroy_export_profiles_service_request(context->export_service_request); |
2317 | |
|
2318 | 0 | return result; |
2319 | 0 | } |
2320 | | |
2321 | 0 | index++; |
2322 | 0 | } |
2323 | | |
2324 | 0 | return CPROF_ENCODE_OPENTELEMETRY_SUCCESS; |
2325 | 0 | } |
2326 | | |
2327 | | static int pack_context( |
2328 | | struct cprof_opentelemetry_encoding_context *context, |
2329 | | struct cprof *profile) |
2330 | 0 | { |
2331 | 0 | memset(context, 0, sizeof(struct cprof_opentelemetry_encoding_context)); |
2332 | |
|
2333 | 0 | context->inner_context = profile; |
2334 | |
|
2335 | 0 | return pack_context_profiles(context, profile); |
2336 | 0 | } |
2337 | | |
2338 | | static cfl_sds_t render_opentelemetry_context_to_sds( |
2339 | | struct cprof_opentelemetry_encoding_context *context) |
2340 | 0 | { |
2341 | 0 | cfl_sds_t result_buffer; |
2342 | 0 | size_t result_size; |
2343 | |
|
2344 | 0 | result_size = opentelemetry__proto__collector__profiles__v1development__export_profiles_service_request__get_packed_size( |
2345 | 0 | context->export_service_request); |
2346 | |
|
2347 | 0 | result_buffer = cfl_sds_create_size(result_size); |
2348 | |
|
2349 | 0 | if(result_buffer != NULL) { |
2350 | 0 | opentelemetry__proto__collector__profiles__v1development__export_profiles_service_request__pack( |
2351 | 0 | context->export_service_request, |
2352 | 0 | (uint8_t *) result_buffer); |
2353 | |
|
2354 | 0 | cfl_sds_set_len(result_buffer, result_size); |
2355 | 0 | } |
2356 | |
|
2357 | 0 | return result_buffer; |
2358 | 0 | } |
2359 | | |
2360 | | int cprof_encode_opentelemetry_create(cfl_sds_t *result_buffer, |
2361 | | struct cprof *profile) |
2362 | 0 | { |
2363 | 0 | int result; |
2364 | 0 | struct cprof_opentelemetry_encoding_context context; |
2365 | |
|
2366 | 0 | *result_buffer = NULL; |
2367 | |
|
2368 | 0 | result = pack_context(&context, profile); |
2369 | |
|
2370 | 0 | if (result == CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
2371 | 0 | *result_buffer = render_opentelemetry_context_to_sds(&context); |
2372 | |
|
2373 | 0 | if (*result_buffer == NULL) { |
2374 | 0 | result = CPROF_ENCODE_OPENTELEMETRY_INTERNAL_ENCODER_ERROR; |
2375 | 0 | } |
2376 | |
|
2377 | 0 | destroy_export_profiles_service_request(context.export_service_request); |
2378 | 0 | } |
2379 | |
|
2380 | 0 | return result; |
2381 | 0 | } |
2382 | | |
2383 | | void cprof_encode_opentelemetry_destroy(cfl_sds_t instance) |
2384 | 0 | { |
2385 | 0 | if (instance != NULL) { |
2386 | 0 | cfl_sds_destroy(instance); |
2387 | 0 | } |
2388 | 0 | } |