/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/infra/log/requestTiming.go
28 строк
640 B
Carl Bergquist
Plugins: Add username to datasource plugin logging (#59893)
07 дек 2022, 15:15
Не верифицирован
07 дек 2022, 15:15
a5ace56
Код
Авторство
О чём код?
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 }