@@ -1874,3 +1874,110 @@ func (c alwaysIncreasingClock) Now() time.Time {
1874
1874
c .Clock .(* clockwork.FakeClock ).Advance (time .Millisecond )
1875
1875
return c .Clock .Now ()
1876
1876
}
1877
+
1878
+ func TestBuildAttributes_InstrumentationScope (t * testing.T ) {
1879
+ tests := []struct {
1880
+ name string
1881
+ instrumentationScope pcommon.InstrumentationScope
1882
+ config Config
1883
+ want map [string ]string
1884
+ }{
1885
+ {
1886
+ name : "with instrumentation scope name and version" ,
1887
+ instrumentationScope : func () pcommon.InstrumentationScope {
1888
+ scope := pcommon .NewInstrumentationScope ()
1889
+ scope .SetName ("express" )
1890
+ scope .SetVersion ("1.0.0" )
1891
+ return scope
1892
+ }(),
1893
+ config : Config {
1894
+ IncludeInstrumentationScope : []string {"express" },
1895
+ },
1896
+ want : map [string ]string {
1897
+ serviceNameKey : "test_service" ,
1898
+ spanNameKey : "test_span" ,
1899
+ spanKindKey : "SPAN_KIND_INTERNAL" ,
1900
+ statusCodeKey : "STATUS_CODE_UNSET" ,
1901
+ instrumentationScopeNameKey : "express" ,
1902
+ instrumentationScopeVersionKey : "1.0.0" ,
1903
+ },
1904
+ },
1905
+ {
1906
+ name : "with instrumentation scope but not included" ,
1907
+ instrumentationScope : func () pcommon.InstrumentationScope {
1908
+ scope := pcommon .NewInstrumentationScope ()
1909
+ scope .SetName ("express" )
1910
+ scope .SetVersion ("1.0.0" )
1911
+ return scope
1912
+ }(),
1913
+ config : Config {},
1914
+ want : map [string ]string {
1915
+ serviceNameKey : "test_service" ,
1916
+ spanNameKey : "test_span" ,
1917
+ spanKindKey : "SPAN_KIND_INTERNAL" ,
1918
+ statusCodeKey : "STATUS_CODE_UNSET" ,
1919
+ },
1920
+ },
1921
+ {
1922
+ name : "without instrumentation scope but version and included in config" ,
1923
+ instrumentationScope : func () pcommon.InstrumentationScope {
1924
+ scope := pcommon .NewInstrumentationScope ()
1925
+ scope .SetVersion ("1.0.0" )
1926
+ return scope
1927
+ }(),
1928
+ config : Config {
1929
+ IncludeInstrumentationScope : []string {"express" },
1930
+ },
1931
+ want : map [string ]string {
1932
+ serviceNameKey : "test_service" ,
1933
+ spanNameKey : "test_span" ,
1934
+ spanKindKey : "SPAN_KIND_INTERNAL" ,
1935
+ statusCodeKey : "STATUS_CODE_UNSET" ,
1936
+ },
1937
+ },
1938
+
1939
+ {
1940
+ name : "with instrumentation scope and instrumentation scope name but no version and included in config" ,
1941
+ instrumentationScope : func () pcommon.InstrumentationScope {
1942
+ scope := pcommon .NewInstrumentationScope ()
1943
+ scope .SetName ("express" )
1944
+ return scope
1945
+ }(),
1946
+ config : Config {
1947
+ IncludeInstrumentationScope : []string {"express" },
1948
+ },
1949
+ want : map [string ]string {
1950
+ serviceNameKey : "test_service" ,
1951
+ spanNameKey : "test_span" ,
1952
+ spanKindKey : "SPAN_KIND_INTERNAL" ,
1953
+ statusCodeKey : "STATUS_CODE_UNSET" ,
1954
+ instrumentationScopeNameKey : "express" ,
1955
+ },
1956
+ },
1957
+ }
1958
+
1959
+ for _ , tt := range tests {
1960
+ t .Run (tt .name , func (t * testing.T ) {
1961
+ // Create connector
1962
+ p := & connectorImp {
1963
+ config : tt .config ,
1964
+ }
1965
+
1966
+ // Create basic span
1967
+ span := ptrace .NewSpan ()
1968
+ span .SetName ("test_span" )
1969
+ span .SetKind (ptrace .SpanKindInternal )
1970
+
1971
+ // Build attributes
1972
+ attrs := p .buildAttributes ("test_service" , span , pcommon .NewMap (), nil , tt .instrumentationScope )
1973
+
1974
+ // Verify results
1975
+ assert .Equal (t , len (tt .want ), attrs .Len ())
1976
+ for k , v := range tt .want {
1977
+ val , ok := attrs .Get (k )
1978
+ assert .True (t , ok )
1979
+ assert .Equal (t , v , val .Str ())
1980
+ }
1981
+ })
1982
+ }
1983
+ }
0 commit comments