@@ -479,89 +479,14 @@ func TestTransportUsesFormatter(t *testing.T) {
479479 require .NoError (t , res .Body .Close ())
480480
481481 spans := spanRecorder .Ended ()
482+ require .NotEmpty (t , spans )
482483 spanName := spans [0 ].Name ()
483484 expectedName := "HTTP GET"
484485 if spanName != expectedName {
485486 t .Fatalf ("unexpected name: got %s, expected %s" , spanName , expectedName )
486487 }
487488}
488489
489- func TestTransportWithSemConvStabilityOptIn (t * testing.T ) {
490- tests := []struct {
491- name string
492- semConvStabilityOptInValue string
493- expected func (host string , port int ) []attribute.KeyValue
494- }{
495- {
496- name : "without opt-in" ,
497- semConvStabilityOptInValue : "" ,
498- expected : func (host string , port int ) []attribute.KeyValue {
499- return []attribute.KeyValue {
500- attribute .String ("http.request.method" , "GET" ),
501- attribute .String ("url.full" , fmt .Sprintf ("http://%s:%d" , host , port )),
502- attribute .String ("server.address" , host ),
503- attribute .Int ("server.port" , port ),
504- attribute .String ("network.protocol.version" , "1.1" ),
505- attribute .Int ("http.response.status_code" , 200 ),
506- }
507- },
508- },
509- {
510- name : "with http/dup opt-in" ,
511- semConvStabilityOptInValue : "http/dup" ,
512- expected : func (host string , port int ) []attribute.KeyValue {
513- return []attribute.KeyValue {
514- // New semantic conventions
515- attribute .String ("http.request.method" , "GET" ),
516- attribute .String ("url.full" , fmt .Sprintf ("http://%s:%d" , host , port )),
517- attribute .String ("server.address" , host ),
518- attribute .Int ("server.port" , port ),
519- attribute .String ("network.protocol.version" , "1.1" ),
520- // Old semantic conventions
521- attribute .String ("http.method" , "GET" ),
522- attribute .String ("http.url" , fmt .Sprintf ("http://%s:%d" , host , port )),
523- attribute .String ("net.peer.name" , host ),
524- attribute .Int ("net.peer.port" , port ),
525- attribute .Int ("http.response.status_code" , 200 ),
526- attribute .Int ("http.status_code" , 200 ),
527- }
528- },
529- },
530- }
531- for _ , tt := range tests {
532- t .Run (tt .name , func (t * testing.T ) {
533- t .Setenv ("OTEL_SEMCONV_STABILITY_OPT_IN" , tt .semConvStabilityOptInValue )
534- spanRecorder := tracetest .NewSpanRecorder ()
535- provider := sdktrace .NewTracerProvider (sdktrace .WithSpanProcessor (spanRecorder ))
536- ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
537- w .WriteHeader (http .StatusOK )
538- }))
539- defer ts .Close ()
540-
541- r , err := http .NewRequest (http .MethodGet , ts .URL , nil )
542- require .NoError (t , err )
543-
544- host , portStr , err := net .SplitHostPort (strings .TrimPrefix (ts .URL , "http://" ))
545- require .NoError (t , err )
546- port , err := strconv .Atoi (portStr )
547- require .NoError (t , err )
548-
549- c := http.Client {Transport : NewTransport (
550- http .DefaultTransport ,
551- WithTracerProvider (provider ),
552- )}
553- resp , err := c .Do (r )
554- require .NoError (t , err )
555- _ = resp .Body .Close ()
556-
557- spans := spanRecorder .Ended ()
558- require .Len (t , spans , 1 )
559- attrs := spans [0 ].Attributes ()
560- assert .ElementsMatch (t , attrs , tt .expected (host , port ))
561- })
562- }
563- }
564-
565490func TestTransportErrorStatus (t * testing.T ) {
566491 // Prepare tracing stuff.
567492 spanRecorder := tracetest .NewSpanRecorder ()
@@ -931,134 +856,6 @@ func TestTransportMetrics(t *testing.T) {
931856 )
932857 assertClientScopeMetrics (t , rm .ScopeMetrics [0 ], attrs )
933858 })
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- })
1062859}
1063860
1064861func assertClientScopeMetrics (t * testing.T , sm metricdata.ScopeMetrics , attrs attribute.Set ) {
0 commit comments