File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
plugins/node/instrumentation-undici Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,14 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta
188188 }
189189
190190 const startTime = hrTime ( ) ;
191- const requestUrl = new URL ( request . origin + request . path ) ;
191+ let requestUrl ;
192+ try {
193+ requestUrl = new URL ( request . path , request . origin ) ;
194+ } catch ( err ) {
195+ this . _diag . warn ( 'could not determine url.full:' , err ) ;
196+ // Skip instrumenting this request.
197+ return ;
198+ }
192199 const urlScheme = requestUrl . protocol . replace ( ':' , '' ) ;
193200 const requestMethod = this . getRequestMethod ( request . method ) ;
194201 const attributes : Attributes = {
Original file line number Diff line number Diff line change @@ -831,5 +831,33 @@ describe('UndiciInstrumentation `undici` tests', function () {
831831 'user-agent is undefined'
832832 ) ;
833833 } ) ;
834+
835+ it ( 'should create valid span if request.path is a full URL' , async function ( ) {
836+ let spans = memoryExporter . getFinishedSpans ( ) ;
837+ assert . strictEqual ( spans . length , 0 ) ;
838+
839+ const origin = `${ protocol } ://${ hostname } :${ mockServer . port } ` ;
840+ const fullUrl = `${ origin } /?query=test` ;
841+ const client = new undici . Client ( origin ) ;
842+ const res = await client . request ( {
843+ path : fullUrl ,
844+ method : 'GET' ,
845+ } ) ;
846+ await consumeResponseBody ( res . body ) ;
847+
848+ spans = memoryExporter . getFinishedSpans ( ) ;
849+ const span = spans [ 0 ] ;
850+ assert . ok ( span , 'a span is present' ) ;
851+ assert . strictEqual ( spans . length , 1 ) ;
852+ assertSpan ( span , {
853+ hostname : 'localhost' ,
854+ httpStatusCode : res . statusCode ,
855+ httpMethod : 'GET' ,
856+ path : '/' ,
857+ query : '?query=test' ,
858+ resHeaders : res . headers ,
859+ } ) ;
860+ assert . strictEqual ( span . attributes [ 'url.full' ] , fullUrl ) ;
861+ } ) ;
834862 } ) ;
835863} ) ;
You can’t perform that action at this time.
0 commit comments