mirror of
https://github.com/alibaba/higress.git
synced 2026-05-08 04:17:27 +08:00
add trace_span_key & as_seperate_log_field configuration for ai-statistics (#2488)
This commit is contained in:
@@ -566,7 +566,7 @@ func (ctx *CommonHttpCtx[PluginConfig]) WriteUserAttributeToLogWithKey(key strin
|
||||
newAttributeMap := map[string]interface{}{}
|
||||
if string(preMarshalledJsonLogStr) != "" {
|
||||
// e.g. {"field1":"value1","field2":"value2"}
|
||||
preJsonLogStr := unmarshalStr(fmt.Sprintf(`"%s"`, string(preMarshalledJsonLogStr)))
|
||||
preJsonLogStr := UnmarshalStr(fmt.Sprintf(`"%s"`, string(preMarshalledJsonLogStr)))
|
||||
err := json.Unmarshal([]byte(preJsonLogStr), &newAttributeMap)
|
||||
if err != nil {
|
||||
ctx.plugin.vm.log.Warnf("Unmarshal failed, will overwrite %s, pre value is: %s", key, string(preMarshalledJsonLogStr))
|
||||
@@ -580,7 +580,7 @@ func (ctx *CommonHttpCtx[PluginConfig]) WriteUserAttributeToLogWithKey(key strin
|
||||
// e.g. {"field1":"value1","field2":2,"field3":"value3"}
|
||||
jsonStr, _ := json.Marshal(newAttributeMap)
|
||||
// e.g. {\"field1\":\"value1\",\"field2\":2,\"field3\":\"value3\"}
|
||||
marshalledJsonStr := marshalStr(string(jsonStr))
|
||||
marshalledJsonStr := MarshalStr(string(jsonStr))
|
||||
if err := proxywasm.SetProperty([]string{key}, []byte(marshalledJsonStr)); err != nil {
|
||||
ctx.plugin.vm.log.Warnf("failed to set %s in filter state, raw is %s, err is %v", key, marshalledJsonStr, err)
|
||||
return err
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func unmarshalStr(marshalledJsonStr string) string {
|
||||
func UnmarshalStr(marshalledJsonStr string) string {
|
||||
// e.g. "{\"field1\":\"value1\",\"field2\":\"value2\"}"
|
||||
var jsonStr string
|
||||
err := json.Unmarshal([]byte(marshalledJsonStr), &jsonStr)
|
||||
@@ -19,7 +19,7 @@ func unmarshalStr(marshalledJsonStr string) string {
|
||||
return jsonStr
|
||||
}
|
||||
|
||||
func marshalStr(raw string) string {
|
||||
func MarshalStr(raw string) string {
|
||||
// e.g. {"field1":"value1","field2":"value2"}
|
||||
helper := map[string]string{
|
||||
"placeholder": raw,
|
||||
|
||||
Reference in New Issue
Block a user