mirror of
https://github.com/hanzoai/otel-collector.git
synced 2026-10-30 18:26:25 +00:00
Follow up of https://github.com/SigNoz/signoz-otel-collector/pull/447 (please go through this first) Part of https://github.com/SigNoz/signoz/issues/5713 * Here we are writing to signoz_index_v3 , trace_v3_resource, error span table and the tag attributes table. * The billing calculation is done using the JSON representation of spanV3. * It is not integrated i.e it won't run after getting merged * We are not storing the static fields like `statusCode` in tag attributes as the query service will take care of it ( more details in later pr's of query service. The reason I am calling this V3 is because of the table name signoz_index_v3
43 lines
986 B
Go
43 lines
986 B
Go
package flatten
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// FlattenJSON flattens a nested JSON into a map[string]string.
|
|
func FlattenJSON(data map[string]interface{}, prefix string) map[string]interface{} {
|
|
result := make(map[string]interface{})
|
|
for key, value := range data {
|
|
fullKey := key
|
|
if prefix != "" {
|
|
fullKey = prefix + "." + key
|
|
}
|
|
|
|
switch value := value.(type) {
|
|
case map[string]interface{}:
|
|
subResult := FlattenJSON(value, fullKey)
|
|
for k, v := range subResult {
|
|
result[k] = v
|
|
}
|
|
case []interface{}:
|
|
for i, v := range value {
|
|
subResult := FlattenJSON(map[string]interface{}{fmt.Sprintf("%d", i): v}, fullKey)
|
|
for k, v := range subResult {
|
|
result[k] = v
|
|
}
|
|
}
|
|
case int, int32, int64:
|
|
v := reflect.ValueOf(value)
|
|
result[fullKey] = float64(v.Int())
|
|
case float32:
|
|
result[fullKey] = float64(value)
|
|
case float64, bool:
|
|
result[fullKey] = value
|
|
default:
|
|
result[fullKey] = fmt.Sprintf("%v", value)
|
|
}
|
|
}
|
|
return result
|
|
}
|