The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/infra/log/requestTiming.go

28 lines
640 B

package log
import (
"context"
"time"
)
type requestStartTimeContextKey struct{}
var requestStartTime = requestStartTimeContextKey{}
// InitCounter creates a pointer on the context that can be incremented later
func InitstartTime(ctx context.Context, now time.Time) context.Context {
return context.WithValue(ctx, requestStartTime, now)
}
// TimeSinceStart returns time spend since the request started in grafana
func TimeSinceStart(ctx context.Context, now time.Time) time.Duration {
val := ctx.Value(requestStartTime)
if val != nil {
startTime, ok := val.(time.Time)
if ok {
return now.Sub(startTime)
}
}
return 0
}