mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Add username to datasource plugin logging (#59893)
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
28
pkg/infra/log/requestTiming.go
Normal file
28
pkg/infra/log/requestTiming.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user