@@ -8,10 +8,11 @@ const assert = require('node:assert')
88const test = require ( 'node:test' )
99const DatastoreShim = require ( '../../../lib/shim/datastore-shim' )
1010const helper = require ( '../../lib/agent_helper' )
11- const https = require ( 'https ' )
11+ const http = require ( 'http ' )
1212const SpanEvent = require ( '../../../lib/spans/span-event' )
1313const DatastoreParameters = require ( '../../../lib/shim/specs/params/datastore' )
1414const { QuerySpec } = require ( '../../../lib/shim/specs' )
15+ const nock = require ( 'nock' )
1516
1617test ( '#constructor() should construct an empty span event' , ( ) => {
1718 const attrs = { }
@@ -43,6 +44,7 @@ test('#constructor() should construct an empty span event', () => {
4344
4445test ( 'fromSegment()' , async ( t ) => {
4546 t . beforeEach ( ( ctx ) => {
47+ nock . disableNetConnect ( )
4648 ctx . nr = { }
4749 ctx . nr . agent = helper . instrumentMockedAgent ( {
4850 distributed_tracing : {
@@ -52,6 +54,7 @@ test('fromSegment()', async (t) => {
5254 } )
5355
5456 t . afterEach ( ( ctx ) => {
57+ nock . enableNetConnect ( )
5558 helper . unloadAgent ( ctx . nr . agent )
5659 } )
5760
@@ -132,8 +135,9 @@ test('fromSegment()', async (t) => {
132135 helper . runInTransaction ( agent , ( transaction ) => {
133136 transaction . sampled = true
134137 transaction . priority = 42
138+ nock ( 'http://example.com' ) . get ( '/?foo=bar' ) . reply ( 200 )
135139
136- https . get ( 'https ://example.com?foo=bar' , ( res ) => {
140+ http . get ( 'http ://example.com?foo=bar' , ( res ) => {
137141 res . resume ( )
138142 res . on ( 'end' , ( ) => {
139143 const tx = agent . tracer . getTransaction ( )
@@ -159,7 +163,7 @@ test('fromSegment()', async (t) => {
159163 assert . equal ( span . intrinsics . name , 'External/example.com/' )
160164 assert . equal ( span . intrinsics . timestamp , segment . timer . start )
161165
162- assert . ok ( span . intrinsics . duration >= 0.01 && span . intrinsics . duration <= 2 )
166+ assert . ok ( span . intrinsics . duration > 0 && span . intrinsics . duration <= 2 )
163167
164168 // Should have type-specific intrinsics
165169 assert . equal ( span . intrinsics . component , 'http' )
@@ -169,13 +173,12 @@ test('fromSegment()', async (t) => {
169173 const attributes = span . attributes
170174
171175 // Should have (most) http properties.
172- assert . equal ( attributes [ 'http.url' ] , 'https ://example.com/' )
176+ assert . equal ( attributes [ 'http.url' ] , 'http ://example.com/' )
173177 assert . equal ( attributes [ 'server.address' ] , 'example.com' )
174- assert . equal ( attributes [ 'server.port' ] , 443 )
178+ assert . equal ( attributes [ 'server.port' ] , 80 )
175179 assert . ok ( attributes [ 'http.method' ] )
176180 assert . ok ( attributes [ 'http.request.method' ] )
177181 assert . equal ( attributes [ 'http.statusCode' ] , 200 )
178- assert . equal ( attributes [ 'http.statusText' ] , 'OK' )
179182
180183 // should nullify mapped properties
181184 assert . ok ( ! attributes . library )
@@ -353,8 +356,9 @@ test('fromSegment()', async (t) => {
353356
354357 await t . test ( 'should handle truncated http spans' , ( t , end ) => {
355358 const { agent } = t . nr
359+ nock ( 'http://www.example.com' ) . get ( '/path?foo=bar' ) . reply ( 200 )
356360 helper . runInTransaction ( agent , ( transaction ) => {
357- https . get ( 'https ://example.com?foo=bar' , ( res ) => {
361+ http . get ( 'http ://www. example.com/path ?foo=bar' , ( res ) => {
358362 transaction . end ( ) // prematurely end to truncate
359363
360364 res . resume ( )
0 commit comments