From 86e9128c6800abd90337fcf64bbea113b24827af Mon Sep 17 00:00:00 2001 From: Natalia Goc Date: Mon, 20 May 2024 17:29:00 +0200 Subject: [PATCH] add db.execution_time_ms --- pkg/attr/attr.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/attr/attr.go b/pkg/attr/attr.go index e6a1e3d..b17cffb 100644 --- a/pkg/attr/attr.go +++ b/pkg/attr/attr.go @@ -5,6 +5,7 @@ import ( "os" "runtime" "runtime/debug" + "time" "git.ma-al.com/maal-libraries/observer/pkg/level" "go.opentelemetry.io/otel/attribute" @@ -13,6 +14,8 @@ import ( ) type KeyValue = attribute.KeyValue +type Key = attribute.Key +type Value = attribute.Value type IntoTraceAttribute interface { IntoTraceAttribute() attribute.KeyValue @@ -54,6 +57,7 @@ const ( ProcessThreadsAvailableKey = attribute.Key("process.threads_available") ServiceLayerKey = attribute.Key("service.layer") ServiceLayerNameKey = attribute.Key("service.layer_name") + DBExecutionTimeMsKey = attribute.Key("db.execution_time_ms") ) type ServiceArchitectureLayer string @@ -254,3 +258,11 @@ func ServiceLayerName(name string) attribute.KeyValue { Value: attribute.StringValue(name), } } + +// Take duration as an execution time of a query measured in milisecongs. +func DBExecutionTimeMs(duration time.Duration) attribute.KeyValue { + return attribute.KeyValue{ + Key: DBExecutionTimeMsKey, + Value: attribute.Int64Value(duration.Milliseconds()), + } +}