@@ -56,10 +56,18 @@ fn collect_json_from_any_value(
56
56
if value. array_val . is_some ( ) {
57
57
let array_val = value. array_val . as_ref ( ) . unwrap ( ) ;
58
58
let values = & array_val. values ;
59
-
60
59
for value in values {
61
- let value = & value. value ;
62
- value_json = collect_json_from_any_value ( key, value. clone ( ) ) ;
60
+ let array_value_json = collect_json_from_any_value ( key, value. clone ( ) ) ;
61
+ for key in array_value_json. keys ( ) {
62
+ value_json. insert (
63
+ format ! (
64
+ "{}_{}" ,
65
+ key. to_owned( ) ,
66
+ value_to_string( array_value_json[ key] . to_owned( ) )
67
+ ) ,
68
+ array_value_json[ key] . to_owned ( ) ,
69
+ ) ;
70
+ }
63
71
}
64
72
}
65
73
@@ -69,7 +77,22 @@ fn collect_json_from_any_value(
69
77
let kv_list_val = value. kv_list_val . unwrap ( ) ;
70
78
for key_value in kv_list_val. values {
71
79
let value = key_value. value ;
72
- value_json = collect_json_from_values ( & value, key) ;
80
+ if value. is_some ( ) {
81
+ let value = value. unwrap ( ) ;
82
+ let key_value_json = collect_json_from_any_value ( key, value) ;
83
+
84
+ for key in key_value_json. keys ( ) {
85
+ value_json. insert (
86
+ format ! (
87
+ "{}_{}_{}" ,
88
+ key. to_owned( ) ,
89
+ key_value. key,
90
+ value_to_string( key_value_json[ key] . to_owned( ) )
91
+ ) ,
92
+ key_value_json[ key] . to_owned ( ) ,
93
+ ) ;
94
+ }
95
+ }
73
96
}
74
97
}
75
98
if value. bytes_val . is_some ( ) {
@@ -96,6 +119,14 @@ fn collect_json_from_values(
96
119
value_json
97
120
}
98
121
122
+ fn value_to_string ( value : serde_json:: Value ) -> String {
123
+ match value. clone ( ) {
124
+ e @ Value :: Number ( _) | e @ Value :: Bool ( _) => e. to_string ( ) ,
125
+ Value :: String ( s) => s,
126
+ _ => "" . to_string ( ) ,
127
+ }
128
+ }
129
+
99
130
pub fn flatten_otel_logs ( body : & Bytes ) -> Vec < BTreeMap < String , Value > > {
100
131
let mut vec_otel_json: Vec < BTreeMap < String , Value > > = Vec :: new ( ) ;
101
132
let body_str = std:: str:: from_utf8 ( body) . unwrap ( ) ;
@@ -117,27 +148,33 @@ pub fn flatten_otel_logs(body: &Bytes) -> Vec<BTreeMap<String, Value>> {
117
148
}
118
149
}
119
150
}
120
- if resource. dropped_attributes_count > 0 {
151
+ if resource. dropped_attributes_count . is_some ( ) {
121
152
otel_json. insert (
122
153
"resource_dropped_attributes_count" . to_string ( ) ,
123
- Value :: Number ( serde_json:: Number :: from ( resource. dropped_attributes_count ) ) ,
154
+ Value :: Number ( serde_json:: Number :: from (
155
+ resource. dropped_attributes_count . unwrap ( ) ,
156
+ ) ) ,
124
157
) ;
125
158
}
126
159
}
127
160
128
161
for scope_logs in record. scope_logs . iter ( ) {
129
162
for scope_log in scope_logs. iter ( ) {
130
163
for instrumentation_scope in scope_log. scope . iter ( ) {
131
- if ! instrumentation_scope. name . is_empty ( ) {
164
+ if instrumentation_scope. name . is_some ( ) {
132
165
otel_json. insert (
133
166
"instrumentation_scope_name" . to_string ( ) ,
134
- Value :: String ( instrumentation_scope. name . to_string ( ) ) ,
167
+ Value :: String (
168
+ instrumentation_scope. name . as_ref ( ) . unwrap ( ) . to_string ( ) ,
169
+ ) ,
135
170
) ;
136
171
}
137
- if ! instrumentation_scope. version . is_empty ( ) {
172
+ if instrumentation_scope. version . is_some ( ) {
138
173
otel_json. insert (
139
174
"instrumentation_scope_version" . to_string ( ) ,
140
- Value :: String ( instrumentation_scope. version . to_string ( ) ) ,
175
+ Value :: String (
176
+ instrumentation_scope. version . as_ref ( ) . unwrap ( ) . to_string ( ) ,
177
+ ) ,
141
178
) ;
142
179
}
143
180
let attributes = & instrumentation_scope. attributes ;
@@ -154,37 +191,45 @@ pub fn flatten_otel_logs(body: &Bytes) -> Vec<BTreeMap<String, Value>> {
154
191
}
155
192
}
156
193
}
157
- if instrumentation_scope. dropped_attributes_count > 0 {
194
+ if instrumentation_scope. dropped_attributes_count . is_some ( ) {
158
195
otel_json. insert (
159
196
"instrumentation_scope_dropped_attributes_count" . to_string ( ) ,
160
197
Value :: Number ( serde_json:: Number :: from (
161
- instrumentation_scope. dropped_attributes_count ,
198
+ instrumentation_scope. dropped_attributes_count . unwrap ( ) ,
162
199
) ) ,
163
200
) ;
164
201
}
165
202
}
166
203
167
204
for log_record in scope_log. log_records . iter ( ) {
168
205
let mut log_record_json: BTreeMap < String , Value > = BTreeMap :: new ( ) ;
169
- if ! log_record. time_unix_nano > 0 {
206
+ if log_record. time_unix_nano . is_some ( ) {
170
207
log_record_json. insert (
171
208
"time_unix_nano" . to_string ( ) ,
172
- Value :: String ( log_record. time_unix_nano . to_string ( ) ) ,
209
+ Value :: String (
210
+ log_record. time_unix_nano . as_ref ( ) . unwrap ( ) . to_string ( ) ,
211
+ ) ,
173
212
) ;
174
213
}
175
- if ! log_record. observed_time_unix_nano > 0 {
214
+ if log_record. observed_time_unix_nano . is_some ( ) {
176
215
log_record_json. insert (
177
216
"observed_time_unix_nano" . to_string ( ) ,
178
- Value :: String ( log_record. observed_time_unix_nano . to_string ( ) ) ,
217
+ Value :: String (
218
+ log_record
219
+ . observed_time_unix_nano
220
+ . as_ref ( )
221
+ . unwrap ( )
222
+ . to_string ( ) ,
223
+ ) ,
179
224
) ;
180
225
}
181
- if log_record. severity_number > 0 {
182
- let severity_number: i32 = log_record. severity_number ;
226
+ if log_record. severity_number . is_some ( ) {
227
+ let severity_number: i32 = log_record. severity_number . unwrap ( ) ;
183
228
log_record_json. insert (
184
229
"severity_number" . to_string ( ) ,
185
230
Value :: Number ( serde_json:: Number :: from ( severity_number) ) ,
186
231
) ;
187
- if log_record. severity_text . is_empty ( ) {
232
+ if log_record. severity_text . is_none ( ) {
188
233
log_record_json. insert (
189
234
"severity_text" . to_string ( ) ,
190
235
Value :: String (
@@ -193,10 +238,12 @@ pub fn flatten_otel_logs(body: &Bytes) -> Vec<BTreeMap<String, Value>> {
193
238
) ;
194
239
}
195
240
}
196
- if ! log_record. severity_text . is_empty ( ) {
241
+ if log_record. severity_text . is_some ( ) {
197
242
log_record_json. insert (
198
243
"severity_text" . to_string ( ) ,
199
- Value :: String ( log_record. severity_text . to_string ( ) ) ,
244
+ Value :: String (
245
+ log_record. severity_text . as_ref ( ) . unwrap ( ) . to_string ( ) ,
246
+ ) ,
200
247
) ;
201
248
}
202
249
@@ -221,17 +268,17 @@ pub fn flatten_otel_logs(body: &Bytes) -> Vec<BTreeMap<String, Value>> {
221
268
}
222
269
}
223
270
224
- if log_record. dropped_attributes_count > 0 {
271
+ if log_record. dropped_attributes_count . is_some ( ) {
225
272
log_record_json. insert (
226
273
"log_record_dropped_attributes_count" . to_string ( ) ,
227
274
Value :: Number ( serde_json:: Number :: from (
228
- log_record. dropped_attributes_count ,
275
+ log_record. dropped_attributes_count . unwrap ( ) ,
229
276
) ) ,
230
277
) ;
231
278
}
232
279
233
- if log_record. flags > 0 {
234
- let flags: u32 = log_record. flags ;
280
+ if log_record. flags . is_some ( ) {
281
+ let flags: u32 = log_record. flags . unwrap ( ) ;
235
282
log_record_json. insert (
236
283
"flags_number" . to_string ( ) ,
237
284
Value :: Number ( serde_json:: Number :: from ( flags) ) ,
@@ -242,17 +289,17 @@ pub fn flatten_otel_logs(body: &Bytes) -> Vec<BTreeMap<String, Value>> {
242
289
) ;
243
290
}
244
291
245
- if ! log_record. span_id . is_empty ( ) {
292
+ if log_record. span_id . is_some ( ) {
246
293
log_record_json. insert (
247
294
"span_id" . to_string ( ) ,
248
- Value :: String ( log_record. span_id . to_string ( ) ) ,
295
+ Value :: String ( log_record. span_id . as_ref ( ) . unwrap ( ) . to_string ( ) ) ,
249
296
) ;
250
297
}
251
298
252
- if ! log_record. trace_id . is_empty ( ) {
299
+ if log_record. trace_id . is_some ( ) {
253
300
log_record_json. insert (
254
301
"trace_id" . to_string ( ) ,
255
- Value :: String ( log_record. trace_id . to_string ( ) ) ,
302
+ Value :: String ( log_record. trace_id . as_ref ( ) . unwrap ( ) . to_string ( ) ) ,
256
303
) ;
257
304
}
258
305
for key in log_record_json. keys ( ) {
@@ -261,18 +308,18 @@ pub fn flatten_otel_logs(body: &Bytes) -> Vec<BTreeMap<String, Value>> {
261
308
vec_otel_json. push ( otel_json. clone ( ) ) ;
262
309
}
263
310
264
- if ! scope_log. schema_url . is_empty ( ) {
311
+ if scope_log. schema_url . is_some ( ) {
265
312
otel_json. insert (
266
313
"scope_log_schema_url" . to_string ( ) ,
267
- Value :: String ( scope_log. schema_url . to_string ( ) ) ,
314
+ Value :: String ( scope_log. schema_url . as_ref ( ) . unwrap ( ) . to_string ( ) ) ,
268
315
) ;
269
316
}
270
317
}
271
318
}
272
- if ! record. schema_url . is_empty ( ) {
319
+ if record. schema_url . is_some ( ) {
273
320
otel_json. insert (
274
321
"resource_schema_url" . to_string ( ) ,
275
- Value :: String ( record. schema_url . to_string ( ) ) ,
322
+ Value :: String ( record. schema_url . as_ref ( ) . unwrap ( ) . to_string ( ) ) ,
276
323
) ;
277
324
}
278
325
}
0 commit comments