* feat: move to ristretto based memory cache with metrics enabled * chore: fix go-deps * fix: metrics namesapces * feat: telemetrystore instrumentation hook * fix: try exporting metrics without units * fix: exporting metrics without units to avoid ratio conversion * feat: figure out operation name like bun spans * chore: minor improvements * feat: add totalCost metric for memorycache * feat: new config for memorycache and fix tests * chore: rename newTelemetry func to newMetrics * chore: add memory.cloneable and memory.cost span attributes * fix: add wait func call --------- Co-authored-by: Pandey <vibhupandey28@gmail.com> Co-authored-by: Nityananda Gohain <nityanandagohain@gmail.com> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
37 lines
625 B
Go
37 lines
625 B
Go
package telemetrystore
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
"unicode"
|
|
)
|
|
|
|
type QueryEvent struct {
|
|
Query string
|
|
QueryArgs []any
|
|
StartTime time.Time
|
|
Operation string
|
|
Err error
|
|
}
|
|
|
|
func NewQueryEvent(query string, args []any) *QueryEvent {
|
|
return &QueryEvent{
|
|
Query: query,
|
|
QueryArgs: args,
|
|
StartTime: time.Now(),
|
|
Operation: queryOperation(query),
|
|
}
|
|
}
|
|
|
|
func queryOperation(query string) string {
|
|
queryOp := strings.TrimLeftFunc(query, unicode.IsSpace)
|
|
|
|
if idx := strings.IndexByte(queryOp, ' '); idx > 0 {
|
|
queryOp = queryOp[:idx]
|
|
}
|
|
if len(queryOp) > 16 {
|
|
queryOp = queryOp[:16]
|
|
}
|
|
return queryOp
|
|
}
|