add db.execution_time_ms

This commit is contained in:
Natalia Goc 2024-05-20 17:29:00 +02:00
parent 16dbdeec3e
commit 86e9128c68

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
"time"
"git.ma-al.com/maal-libraries/observer/pkg/level" "git.ma-al.com/maal-libraries/observer/pkg/level"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
@ -13,6 +14,8 @@ import (
) )
type KeyValue = attribute.KeyValue type KeyValue = attribute.KeyValue
type Key = attribute.Key
type Value = attribute.Value
type IntoTraceAttribute interface { type IntoTraceAttribute interface {
IntoTraceAttribute() attribute.KeyValue IntoTraceAttribute() attribute.KeyValue
@ -54,6 +57,7 @@ const (
ProcessThreadsAvailableKey = attribute.Key("process.threads_available") ProcessThreadsAvailableKey = attribute.Key("process.threads_available")
ServiceLayerKey = attribute.Key("service.layer") ServiceLayerKey = attribute.Key("service.layer")
ServiceLayerNameKey = attribute.Key("service.layer_name") ServiceLayerNameKey = attribute.Key("service.layer_name")
DBExecutionTimeMsKey = attribute.Key("db.execution_time_ms")
) )
type ServiceArchitectureLayer string type ServiceArchitectureLayer string
@ -254,3 +258,11 @@ func ServiceLayerName(name string) attribute.KeyValue {
Value: attribute.StringValue(name), 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()),
}
}