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()), + } +}