package resource
import (
"context"
"strings"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
)
type osDescriptionProvider func () (string , error )
var defaultOSDescriptionProvider osDescriptionProvider = platformOSDescription
var osDescription = defaultOSDescriptionProvider
func setDefaultOSDescriptionProvider() {
setOSDescriptionProvider (defaultOSDescriptionProvider )
}
func setOSDescriptionProvider(osDescriptionProvider osDescriptionProvider ) {
osDescription = osDescriptionProvider
}
type (
osTypeDetector struct {}
osDescriptionDetector struct {}
)
func (osTypeDetector ) Detect (context .Context ) (*Resource , error ) {
osType := runtimeOS ()
osTypeAttribute := mapRuntimeOSToSemconvOSType (osType )
return NewWithAttributes (
semconv .SchemaURL ,
osTypeAttribute ,
), nil
}
func (osDescriptionDetector ) Detect (context .Context ) (*Resource , error ) {
description , err := osDescription ()
if err != nil {
return nil , err
}
return NewWithAttributes (
semconv .SchemaURL ,
semconv .OSDescription (description ),
), nil
}
func mapRuntimeOSToSemconvOSType(osType string ) attribute .KeyValue {
osTypeAttributeMap := map [string ]attribute .KeyValue {
"aix" : semconv .OSTypeAIX ,
"darwin" : semconv .OSTypeDarwin ,
"dragonfly" : semconv .OSTypeDragonflyBSD ,
"freebsd" : semconv .OSTypeFreeBSD ,
"linux" : semconv .OSTypeLinux ,
"netbsd" : semconv .OSTypeNetBSD ,
"openbsd" : semconv .OSTypeOpenBSD ,
"solaris" : semconv .OSTypeSolaris ,
"windows" : semconv .OSTypeWindows ,
"zos" : semconv .OSTypeZOS ,
}
var osTypeAttribute attribute .KeyValue
if attr , ok := osTypeAttributeMap [osType ]; ok {
osTypeAttribute = attr
} else {
osTypeAttribute = semconv .OSTypeKey .String (strings .ToLower (osType ))
}
return osTypeAttribute
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .