File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
packages/opentelemetry-instrumentation-http Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
226226 if (
227227 component === 'https' &&
228228 typeof options === 'object' &&
229- options ?. constructor . name !== 'URL'
229+ options ?. constructor ? .name !== 'URL'
230230 ) {
231231 options = Object . assign ( { } , options ) ;
232232 instrumentation . _setDefaultOptions ( options ) ;
Original file line number Diff line number Diff line change @@ -515,6 +515,32 @@ describe('HttpsInstrumentation', () => {
515515 }
516516 } ) ;
517517
518+ it ( 'should have 2 ended spans when provided "options" are an object without a constructor' , async ( ) => {
519+ // Related issue: https://github.com/open-telemetry/opentelemetry-js/issues/2008
520+ const testPath = '/outgoing/test' ;
521+ const options = Object . create ( null ) ;
522+ options . hostname = hostname ;
523+ options . port = serverPort ;
524+ options . path = pathname ;
525+ options . method = 'GET' ;
526+
527+ doNock ( hostname , testPath , 200 , 'Ok' ) ;
528+
529+ const promiseRequest = new Promise ( ( resolve , _reject ) => {
530+ const req = https . request ( options , ( resp : http . IncomingMessage ) => {
531+ resp . on ( 'data' , ( ) => { } ) ;
532+ resp . on ( 'end' , ( ) => {
533+ resolve ( { } ) ;
534+ } ) ;
535+ } ) ;
536+ return req . end ( ) ;
537+ } ) ;
538+
539+ await promiseRequest ;
540+ const spans = memoryExporter . getFinishedSpans ( ) ;
541+ assert . strictEqual ( spans . length , 2 ) ;
542+ } ) ;
543+
518544 it ( 'should have 1 ended span when response.end throw an exception' , async ( ) => {
519545 const testPath = '/outgoing/rootSpan/childs/1' ;
520546 doNock ( hostname , testPath , 400 , 'Not Ok' ) ;
You can’t perform that action at this time.
0 commit comments