diff --git a/pkg/ottl/ottlfuncs/func_useragent.go b/pkg/ottl/ottlfuncs/func_useragent.go index 0ba1d1d9f346..87b6c8581e22 100644 --- a/pkg/ottl/ottlfuncs/func_useragent.go +++ b/pkg/ottl/ottlfuncs/func_useragent.go @@ -38,10 +38,13 @@ func userAgent[K any](userAgentSource ottl.StringGetter[K]) ottl.ExprFunc[K] { / return nil, err } parsedUserAgent := parser.ParseUserAgent(userAgentString) + parsedOS := parser.ParseOs(userAgentString) return map[string]any{ semconv.AttributeUserAgentName: parsedUserAgent.Family, semconv.AttributeUserAgentOriginal: userAgentString, semconv.AttributeUserAgentVersion: parsedUserAgent.ToVersionString(), + semconv.AttributeOSName: parsedOS.Family, + semconv.AttributeOSVersion: parsedOS.ToVersionString(), }, nil } } diff --git a/pkg/ottl/ottlfuncs/func_useragent_test.go b/pkg/ottl/ottlfuncs/func_useragent_test.go index f5ce22b7a07a..e3b472513ed0 100644 --- a/pkg/ottl/ottlfuncs/func_useragent_test.go +++ b/pkg/ottl/ottlfuncs/func_useragent_test.go @@ -19,6 +19,17 @@ func TestUserAgentParser(t *testing.T) { UAString string ExpectedMap map[string]any }{ + { + Name: "Firefox-Android", + UAString: "Mozilla/5.0 (Linux; Android 4.1.1; SPH-L710 Build/JRO03L) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19", + ExpectedMap: map[string]any{ + semconv.AttributeUserAgentOriginal: "Mozilla/5.0 (Linux; Android 4.1.1; SPH-L710 Build/JRO03L) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19", + semconv.AttributeUserAgentName: "Chrome Mobile", + semconv.AttributeUserAgentVersion: "18.0.1025", + semconv.AttributeOSName: "Android", + semconv.AttributeOSVersion: "4.1.1", + }, + }, { Name: "Firefox", UAString: "Mozilla/5.0 (X11; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0", @@ -26,6 +37,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "Mozilla/5.0 (X11; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0", semconv.AttributeUserAgentName: "Firefox", semconv.AttributeUserAgentVersion: "126.0", + semconv.AttributeOSName: "Linux", + semconv.AttributeOSVersion: "", }, }, { @@ -35,6 +48,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36", semconv.AttributeUserAgentName: "Chrome", semconv.AttributeUserAgentVersion: "51.0.2704", + semconv.AttributeOSName: "Linux", + semconv.AttributeOSVersion: "", }, }, { @@ -44,6 +59,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1", semconv.AttributeUserAgentName: "Mobile Safari", semconv.AttributeUserAgentVersion: "13.1.1", + semconv.AttributeOSName: "iOS", + semconv.AttributeOSVersion: "13.5.1", }, }, { @@ -53,6 +70,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59", semconv.AttributeUserAgentName: "Edge", semconv.AttributeUserAgentVersion: "91.0.864", + semconv.AttributeOSName: "Windows", + semconv.AttributeOSVersion: "10", }, }, { @@ -62,6 +81,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41", semconv.AttributeUserAgentName: "Opera", semconv.AttributeUserAgentVersion: "38.0.2220", + semconv.AttributeOSName: "Linux", + semconv.AttributeOSVersion: "", }, }, { @@ -71,6 +92,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "curl/7.81.0", semconv.AttributeUserAgentName: "curl", semconv.AttributeUserAgentVersion: "7.81.0", + semconv.AttributeOSName: "Other", + semconv.AttributeOSVersion: "", }, }, { @@ -80,6 +103,8 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "foobar/1.2.3 (foo; bar baz)", semconv.AttributeUserAgentName: "Other", semconv.AttributeUserAgentVersion: "", + semconv.AttributeOSName: "Other", + semconv.AttributeOSVersion: "", }, }, { @@ -89,6 +114,30 @@ func TestUserAgentParser(t *testing.T) { semconv.AttributeUserAgentOriginal: "OpenTelemetry Collector Contrib/0.106.1 (linux/amd64)", semconv.AttributeUserAgentName: "Other", semconv.AttributeUserAgentVersion: "", + semconv.AttributeOSName: "Linux", + semconv.AttributeOSVersion: "", + }, + }, + { + Name: "ViaFree iOS", + UAString: "ViaFree-DK/3.8.3 (com.MTGx.ViaFree.dk; build:7383; iOS 12.1.0) Alamofire/4.7.0", + ExpectedMap: map[string]any{ + semconv.AttributeUserAgentOriginal: "ViaFree-DK/3.8.3 (com.MTGx.ViaFree.dk; build:7383; iOS 12.1.0) Alamofire/4.7.0", + semconv.AttributeUserAgentName: "ViaFree", + semconv.AttributeUserAgentVersion: "3.8.3", + semconv.AttributeOSName: "iOS", + semconv.AttributeOSVersion: "12.1.0", + }, + }, + { + Name: "Java SDK Linux", + UAString: "ibm-cos-sdk-java/2.3.0 Linux/4.9.0-8-amd64 Java_HotSpot(TM)_64-Bit_Server_VM/9.0.4+11/9.0.4'", + ExpectedMap: map[string]any{ + semconv.AttributeUserAgentOriginal: "ibm-cos-sdk-java/2.3.0 Linux/4.9.0-8-amd64 Java_HotSpot(TM)_64-Bit_Server_VM/9.0.4+11/9.0.4'", + semconv.AttributeUserAgentName: "ibm-cos-sdk-java", + semconv.AttributeUserAgentVersion: "2.3.0", + semconv.AttributeOSName: "Linux", + semconv.AttributeOSVersion: "4.9.0", }, }, }