File tree 2 files changed +25
-10
lines changed
packages/tracer/src/provider
2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ import { addUserAgentMiddleware } from '@aws-lambda-powertools/commons';
28
28
import type { DiagnosticsChannel } from 'undici-types' ;
29
29
import {
30
30
findHeaderAndDecode ,
31
- getOriginURL ,
31
+ getRequestURL ,
32
32
isHttpSubsegment ,
33
33
} from './utilities.js' ;
34
34
@@ -107,16 +107,18 @@ class ProviderService implements ProviderServiceInterface {
107
107
const { request } = message as DiagnosticsChannel . RequestCreateMessage ;
108
108
109
109
const parentSubsegment = this . getSegment ( ) ;
110
- if ( parentSubsegment && request . origin ) {
111
- const origin = getOriginURL ( request . origin ) ;
110
+ const requestURL = getRequestURL ( request ) ;
111
+ if ( parentSubsegment && requestURL ) {
112
112
const method = request . method ;
113
113
114
- const subsegment = parentSubsegment . addNewSubsegment ( origin . hostname ) ;
114
+ const subsegment = parentSubsegment . addNewSubsegment (
115
+ requestURL . hostname
116
+ ) ;
115
117
subsegment . addAttribute ( 'namespace' , 'remote' ) ;
116
118
117
119
( subsegment as HttpSubsegment ) . http = {
118
120
request : {
119
- url : origin . hostname ,
121
+ url : ` ${ requestURL . protocol } // ${ requestURL . hostname } ${ requestURL . pathname } ` ,
120
122
method,
121
123
} ,
122
124
} ;
Original file line number Diff line number Diff line change 1
1
import { URL } from 'node:url' ;
2
2
import type { Segment , Subsegment } from 'aws-xray-sdk-core' ;
3
+ import type { DiagnosticsChannel } from 'undici-types' ;
3
4
import type { HttpSubsegment } from '../types/ProviderService.js' ;
4
5
5
6
const decoder = new TextDecoder ( ) ;
@@ -52,12 +53,24 @@ const isHttpSubsegment = (
52
53
} ;
53
54
54
55
/**
55
- * Convert the origin url to a URL object when it is a string
56
+ * Convert the origin url to a URL object when it is a string and append the path if provided
56
57
*
57
- * @param origin The origin url
58
+ * @param origin The request object containing the origin url and path
58
59
*/
59
- const getOriginURL = ( origin : string | URL ) : URL => {
60
- return origin instanceof URL ? origin : new URL ( origin ) ;
60
+ const getRequestURL = (
61
+ request : DiagnosticsChannel . Request
62
+ ) : URL | undefined => {
63
+ if ( typeof request . origin === 'string' ) {
64
+ return new URL ( `${ request . origin } ${ request . path || '' } ` ) ;
65
+ }
66
+
67
+ if ( request . origin instanceof URL ) {
68
+ request . origin . pathname = request . path || '' ;
69
+
70
+ return request . origin ;
71
+ }
72
+
73
+ return undefined ;
61
74
} ;
62
75
63
- export { findHeaderAndDecode , isHttpSubsegment , getOriginURL } ;
76
+ export { findHeaderAndDecode , isHttpSubsegment , getRequestURL } ;
You can’t perform that action at this time.
0 commit comments