Capture traces

This commit is contained in:
2024-01-25 14:46:43 +08:00
parent b906edc022
commit 4bdddf72e9
7 changed files with 69 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package navi
import (
"github.com/spf13/viper"
"io"
"os"
"path/filepath"
@ -13,6 +14,7 @@ var R *RoadApp
func ReadInConfig(root string) error {
instance := &RoadApp{
Regions: make([]*Region, 0),
Traces: make([]RoadTrace, 0, viper.GetInt("performance.traces_limit")),
}
if err := filepath.Walk(root, func(fp string, info os.FileInfo, _ error) error {

25
pkg/navi/metrics.go Normal file
View File

@ -0,0 +1,25 @@
package navi
import "github.com/spf13/viper"
type RoadTrace struct {
Region string `json:"region"`
Location string `json:"location"`
Destination string `json:"destination"`
Uri string `json:"uri"`
IpAddress string `json:"ip_address"`
UserAgent string `json:"user_agent"`
Error RoadTraceError `json:"error"`
}
type RoadTraceError struct {
IsNull bool `json:"is_null"`
Message string `json:"message"`
}
func (v *RoadApp) AddTrace(trace RoadTrace) {
v.Traces = append(v.Traces, trace)
if len(v.Traces) > viper.GetInt("performance.traces_limit") {
v.Traces = v.Traces[1:]
}
}

View File

@ -7,7 +7,8 @@ import (
)
type RoadApp struct {
Regions []*Region `json:"regions"`
Regions []*Region `json:"regions"`
Traces []RoadTrace `json:"traces"`
}
func (v *RoadApp) Forward(ctx *fiber.Ctx, dest *Destination) error {