mirror of
https://github.com/alibaba/higress.git
synced 2026-05-31 16:17:28 +08:00
support default value (#1873)
This commit is contained in:
@@ -64,12 +64,13 @@ const (
|
||||
|
||||
// TracingSpan is the tracing span configuration.
|
||||
type Attribute struct {
|
||||
Key string `json:"key"`
|
||||
ValueSource string `json:"value_source"`
|
||||
Value string `json:"value"`
|
||||
Rule string `json:"rule,omitempty"`
|
||||
ApplyToLog bool `json:"apply_to_log,omitempty"`
|
||||
ApplyToSpan bool `json:"apply_to_span,omitempty"`
|
||||
Key string `json:"key"`
|
||||
ValueSource string `json:"value_source"`
|
||||
Value string `json:"value"`
|
||||
DefaultValue string `json:"default_value,omitempty"`
|
||||
Rule string `json:"rule,omitempty"`
|
||||
ApplyToLog bool `json:"apply_to_log,omitempty"`
|
||||
ApplyToSpan bool `json:"apply_to_span,omitempty"`
|
||||
}
|
||||
|
||||
type AIStatisticsConfig struct {
|
||||
@@ -294,10 +295,14 @@ func getUsage(data []byte) (model string, inputTokenUsage int64, outputTokenUsag
|
||||
continue
|
||||
}
|
||||
modelObj := gjson.GetBytes(chunk, "model")
|
||||
if modelObj.Exists() {
|
||||
model = modelObj.String()
|
||||
} else {
|
||||
model = "unknown"
|
||||
}
|
||||
inputTokenObj := gjson.GetBytes(chunk, "usage.prompt_tokens")
|
||||
outputTokenObj := gjson.GetBytes(chunk, "usage.completion_tokens")
|
||||
if modelObj.Exists() && inputTokenObj.Exists() && outputTokenObj.Exists() {
|
||||
model = modelObj.String()
|
||||
if inputTokenObj.Exists() && outputTokenObj.Exists() {
|
||||
inputTokenUsage = inputTokenObj.Int()
|
||||
outputTokenUsage = outputTokenObj.Int()
|
||||
ok = true
|
||||
@@ -329,6 +334,9 @@ func setAttributeBySource(ctx wrapper.HttpContext, config AIStatisticsConfig, so
|
||||
value = gjson.GetBytes(body, attribute.Value).Value()
|
||||
default:
|
||||
}
|
||||
if (value == nil || value == "") && attribute.DefaultValue != "" {
|
||||
value = attribute.DefaultValue
|
||||
}
|
||||
log.Debugf("[attribute] source type: %s, key: %s, value: %+v", source, key, value)
|
||||
if attribute.ApplyToLog {
|
||||
ctx.SetUserAttribute(key, value)
|
||||
|
||||
Reference in New Issue
Block a user