@@ -931,6 +931,134 @@ func TestTransportMetrics(t *testing.T) {
931931 )
932932 assertClientScopeMetrics (t , rm .ScopeMetrics [0 ], attrs )
933933 })
934+
935+ t .Run ("make http request with http/dup opt-in and check both new and old metrics" , func (t * testing.T ) {
936+ t .Setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , "http/dup" )
937+ reader := sdkmetric .NewManualReader ()
938+ meterProvider := sdkmetric .NewMeterProvider (sdkmetric .WithReader (reader ))
939+
940+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
941+ w .WriteHeader (http .StatusOK )
942+ _ , err := w .Write (responseBody )
943+ assert .NoError (t , err )
944+ }))
945+ defer ts .Close ()
946+
947+ tr := NewTransport (
948+ http .DefaultTransport ,
949+ WithMeterProvider (meterProvider ),
950+ )
951+ c := http.Client {Transport : tr }
952+ r , err := http .NewRequest (http .MethodGet , ts .URL , bytes .NewReader (requestBody ))
953+ require .NoError (t , err )
954+ res , err := c .Do (r )
955+ require .NoError (t , err )
956+ _ , err = io .ReadAll (res .Body )
957+ require .NoError (t , err )
958+ require .NoError (t , res .Body .Close ())
959+ host , portStr , err := net .SplitHostPort (r .Host )
960+ require .NoError (t , err )
961+ port , err := strconv .Atoi (portStr )
962+ require .NoError (t , err )
963+
964+ attrsNew := attribute .NewSet (
965+ attribute .String ("http.request.method" , "GET" ),
966+ attribute .Int ("http.response.status_code" , 200 ),
967+ attribute .String ("server.address" , host ),
968+ attribute .Int ("server.port" , port ),
969+ attribute .String ("url.scheme" , "http" ),
970+ attribute .String ("network.protocol.name" , "http" ),
971+ attribute .String ("network.protocol.version" , "1.1" ),
972+ )
973+ attrsOld := attribute .NewSet (
974+ attribute .String ("http.method" , "GET" ),
975+ attribute .Int ("http.status_code" , 200 ),
976+ attribute .String ("net.peer.name" , host ),
977+ attribute .Int ("net.peer.port" , port ),
978+ )
979+
980+ rm := metricdata.ResourceMetrics {}
981+ err = reader .Collect (context .Background (), & rm )
982+ require .NoError (t , err )
983+ require .Len (t , rm .ScopeMetrics , 1 )
984+
985+ expected := metricdata.ScopeMetrics {
986+ Scope : instrumentation.Scope {
987+ Name : ScopeName ,
988+ Version : Version (),
989+ },
990+ Metrics : []metricdata.Metrics {
991+ {
992+ Name : "http.client.request.body.size" ,
993+ Description : "Size of HTTP client request bodies." ,
994+ Unit : "By" ,
995+ Data : metricdata.Histogram [int64 ]{
996+ Temporality : metricdata .CumulativeTemporality ,
997+ DataPoints : []metricdata.HistogramDataPoint [int64 ]{
998+ {
999+ Attributes : attrsNew ,
1000+ },
1001+ },
1002+ },
1003+ },
1004+ {
1005+ Name : "http.client.request.duration" ,
1006+ Description : "Duration of HTTP client requests." ,
1007+ Unit : "s" ,
1008+ Data : metricdata.Histogram [float64 ]{
1009+ Temporality : metricdata .CumulativeTemporality ,
1010+ DataPoints : []metricdata.HistogramDataPoint [float64 ]{
1011+ {
1012+ Attributes : attrsNew ,
1013+ },
1014+ },
1015+ },
1016+ },
1017+ {
1018+ Name : "http.client.request.size" ,
1019+ Description : "Measures the size of HTTP request messages." ,
1020+ Unit : "By" ,
1021+ Data : metricdata.Sum [int64 ]{
1022+ Temporality : metricdata .CumulativeTemporality ,
1023+ IsMonotonic : true ,
1024+ DataPoints : []metricdata.DataPoint [int64 ]{
1025+ {
1026+ Attributes : attrsOld ,
1027+ },
1028+ },
1029+ },
1030+ },
1031+ {
1032+ Name : "http.client.response.size" ,
1033+ Description : "Measures the size of HTTP response messages." ,
1034+ Unit : "By" ,
1035+ Data : metricdata.Sum [int64 ]{
1036+ Temporality : metricdata .CumulativeTemporality ,
1037+ IsMonotonic : true ,
1038+ DataPoints : []metricdata.DataPoint [int64 ]{
1039+ {
1040+ Attributes : attrsOld ,
1041+ },
1042+ },
1043+ },
1044+ },
1045+ {
1046+ Name : "http.client.duration" ,
1047+ Description : "Measures the duration of outbound HTTP requests." ,
1048+ Unit : "ms" ,
1049+ Data : metricdata.Histogram [float64 ]{
1050+ Temporality : metricdata .CumulativeTemporality ,
1051+ DataPoints : []metricdata.HistogramDataPoint [float64 ]{
1052+ {
1053+ Attributes : attrsOld ,
1054+ },
1055+ },
1056+ },
1057+ },
1058+ },
1059+ }
1060+ metricdatatest .AssertEqual (t , expected , rm .ScopeMetrics [0 ], metricdatatest .IgnoreTimestamp (), metricdatatest .IgnoreValue ())
1061+ })
9341062}
9351063
9361064func assertClientScopeMetrics (t * testing.T , sm metricdata.ScopeMetrics , attrs attribute.Set ) {
0 commit comments