File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import (
1010 "code.gitea.io/gitea/modules/gtprof"
1111 "code.gitea.io/gitea/modules/log"
1212 "code.gitea.io/gitea/modules/setting"
13+ "github.com/prometheus/client_golang/prometheus"
14+ "github.com/prometheus/client_golang/prometheus/promauto"
1315
1416 "xorm.io/xorm/contexts"
1517)
@@ -21,12 +23,22 @@ type EngineHook struct {
2123
2224var _ contexts.Hook = (* EngineHook )(nil )
2325
26+ // follows: https://opentelemetry.io/docs/specs/semconv/database/database-metrics/#metric-dbclientoperationduration
27+ var durationHistogram = promauto .NewHistogram (prometheus.HistogramOpts {
28+ Namespace : "db" ,
29+ Subsystem : "client" ,
30+ Name : "operation.duration" ,
31+ Help : "Duration of database client operations." ,
32+ // ConstLabels: prometheus.Labels{"db.system.name": BuilderDialect()}, //TODO: add type of database per spec.
33+ })
34+
2435func (* EngineHook ) BeforeProcess (c * contexts.ContextHook ) (context.Context , error ) {
2536 ctx , _ := gtprof .GetTracer ().Start (c .Ctx , gtprof .TraceSpanDatabase )
2637 return ctx , nil
2738}
2839
2940func (h * EngineHook ) AfterProcess (c * contexts.ContextHook ) error {
41+ durationHistogram .Observe (c .ExecuteTime .Seconds ())
3042 span := gtprof .GetContextSpan (c .Ctx )
3143 if span != nil {
3244 // Do not record SQL parameters here:
You can’t perform that action at this time.
0 commit comments