@@ -12,15 +12,19 @@ const { hrTimeToMilliseconds } = require('@opentelemetry/core')
12
12
13
13
const helper = require ( '../../lib/agent_helper' )
14
14
const { otelSynthesis } = require ( '../../../lib/symbols' )
15
+ const { DESTINATIONS : ATTR_DESTINATION } = require ( '../../../lib/config/attribute-filter' )
15
16
16
17
const { DESTINATIONS } = require ( '../../../lib/transaction' )
17
18
const {
18
19
ATTR_DB_NAME ,
19
20
ATTR_DB_STATEMENT ,
20
21
ATTR_DB_SYSTEM ,
21
22
ATTR_GRPC_STATUS_CODE ,
23
+ ATTR_FULL_URL ,
22
24
ATTR_HTTP_HOST ,
23
25
ATTR_HTTP_METHOD ,
26
+ ATTR_HTTP_REQUEST_METHOD ,
27
+ ATTR_HTTP_RES_STATUS_CODE ,
24
28
ATTR_HTTP_ROUTE ,
25
29
ATTR_HTTP_STATUS_CODE ,
26
30
ATTR_HTTP_STATUS_TEXT ,
@@ -40,6 +44,7 @@ const {
40
44
ATTR_SERVER_ADDRESS ,
41
45
ATTR_SERVER_PORT ,
42
46
ATTR_URL_PATH ,
47
+ ATTR_URL_QUERY ,
43
48
ATTR_URL_SCHEME ,
44
49
DB_SYSTEM_VALUES ,
45
50
MESSAGING_SYSTEM_KIND_VALUES
@@ -121,7 +126,7 @@ test('client span(http) is bridge accordingly', (t, end) => {
121
126
const { agent, tracer } = t . nr
122
127
helper . runInTransaction ( agent , ( tx ) => {
123
128
tx . name = 'http-external-test'
124
- tracer . startActiveSpan ( 'http-outbound' , { kind : otel . SpanKind . CLIENT , attributes : { [ ATTR_HTTP_HOST ] : 'newrelic.com' , [ ATTR_HTTP_METHOD ] : 'GET' } } , ( span ) => {
129
+ tracer . startActiveSpan ( 'http-outbound' , { kind : otel . SpanKind . CLIENT , attributes : { [ ATTR_HTTP_HOST ] : 'newrelic.com' , [ ATTR_NET_PEER_NAME ] : 'newrelic.com' , [ ATTR_HTTP_METHOD ] : 'GET' } } , ( span ) => {
125
130
const segment = agent . tracer . getSegment ( )
126
131
assert . equal ( segment . name , 'External/newrelic.com' )
127
132
assert . equal ( tx . traceId , span . spanContext ( ) . traceId )
@@ -141,6 +146,85 @@ test('client span(http) is bridge accordingly', (t, end) => {
141
146
} )
142
147
} )
143
148
149
+ test ( 'Http external span is bridged accordingly' , ( t , end ) => {
150
+ const attributes = {
151
+ [ ATTR_SERVER_ADDRESS ] : 'www.newrelic.com' ,
152
+ [ ATTR_HTTP_REQUEST_METHOD ] : 'GET' ,
153
+ [ ATTR_SERVER_PORT ] : 8080 ,
154
+ [ ATTR_URL_PATH ] : '/search' ,
155
+ [ ATTR_URL_QUERY ] : 'q=test' ,
156
+ [ ATTR_URL_SCHEME ] : 'https' ,
157
+ [ ATTR_HTTP_HOST ] : 'www.newrelic.com' ,
158
+ [ ATTR_FULL_URL ] : 'https://www.newrelic.com:8080/search?q=test'
159
+ }
160
+
161
+ const { agent, tracer } = t . nr
162
+ helper . runInTransaction ( agent , ( tx ) => {
163
+ tx . name = 'undici-external-test'
164
+ tracer . startActiveSpan ( 'unidic-outbound' , { kind : otel . SpanKind . CLIENT , attributes } , ( span ) => {
165
+ span . setAttribute ( ATTR_HTTP_RES_STATUS_CODE , 200 )
166
+ const segment = agent . tracer . getSegment ( )
167
+ assert . equal ( segment . name , 'External/www.newrelic.com/search' )
168
+ assert . equal ( tx . traceId , span . spanContext ( ) . traceId )
169
+ span . end ( )
170
+ const duration = hrTimeToMilliseconds ( span . duration )
171
+ assert . equal ( duration , segment . getDurationInMillis ( ) )
172
+ tx . end ( )
173
+
174
+ const attrs = segment . getAttributes ( )
175
+ const spanAttributes = segment . attributes . get ( ATTR_DESTINATION . SPAN_EVENT )
176
+ assert . equal ( attrs . procedure , attributes [ ATTR_HTTP_REQUEST_METHOD ] )
177
+ assert . equal ( attrs [ 'url.scheme' ] , attrs [ ATTR_URL_SCHEME ] )
178
+ // attributes.url shouldn't include the query
179
+ assert . equal ( attrs . url , `https://${ attributes [ ATTR_SERVER_ADDRESS ] } :8080/search` )
180
+ assert . equal ( spanAttributes [ 'http.statusCode' ] , 200 )
181
+ assert . equal ( spanAttributes . hostname , attributes [ ATTR_SERVER_ADDRESS ] )
182
+ assert . equal ( spanAttributes . port , attributes [ ATTR_SERVER_PORT ] )
183
+ assert . equal ( spanAttributes [ 'request.parameters.q' ] , 'test' )
184
+ end ( )
185
+ } )
186
+ } )
187
+ } )
188
+
189
+ test ( 'Http external span is bridged accordingly(legacy attributes test)' , ( t , end ) => {
190
+ const attributes = {
191
+ [ ATTR_NET_PEER_NAME ] : 'www.newrelic.com' ,
192
+ [ ATTR_HTTP_METHOD ] : 'GET' ,
193
+ [ ATTR_NET_PEER_PORT ] : 8080 ,
194
+ [ ATTR_URL_QUERY ] : 'q=test' ,
195
+ [ ATTR_HTTP_HOST ] : 'www.newrelic.com' ,
196
+ [ ATTR_HTTP_URL ] : 'https://www.newrelic.com:8080/search?q=test'
197
+ }
198
+
199
+ const { agent, tracer } = t . nr
200
+ helper . runInTransaction ( agent , ( tx ) => {
201
+ tx . name = 'http-external-test'
202
+ tracer . startActiveSpan ( 'http-outbound' , { kind : otel . SpanKind . CLIENT , attributes } , ( span ) => {
203
+ span . setAttribute ( ATTR_HTTP_RES_STATUS_CODE , 200 )
204
+ span . setAttribute ( ATTR_HTTP_STATUS_TEXT , 'OK' )
205
+ const segment = agent . tracer . getSegment ( )
206
+ assert . equal ( segment . name , 'External/www.newrelic.com/search' )
207
+ assert . equal ( tx . traceId , span . spanContext ( ) . traceId )
208
+ span . end ( )
209
+ const duration = hrTimeToMilliseconds ( span . duration )
210
+ assert . equal ( duration , segment . getDurationInMillis ( ) )
211
+ tx . end ( )
212
+
213
+ const attrs = segment . getAttributes ( )
214
+ const spanAttributes = segment . attributes . get ( ATTR_DESTINATION . SPAN_EVENT )
215
+ assert . equal ( attrs . procedure , attributes [ ATTR_HTTP_METHOD ] )
216
+ // attributes.url shouldn't include the query
217
+ assert . equal ( attrs . url , `https://${ attributes [ ATTR_NET_PEER_NAME ] } :8080/search` )
218
+ assert . equal ( spanAttributes [ 'http.statusCode' ] , 200 )
219
+ assert . equal ( spanAttributes [ 'http.statusText' ] , 'OK' )
220
+ assert . equal ( spanAttributes . hostname , attributes [ ATTR_NET_PEER_NAME ] )
221
+ assert . equal ( spanAttributes . port , attributes [ ATTR_NET_PEER_PORT ] )
222
+ assert . equal ( spanAttributes [ 'request.parameters.q' ] , 'test' )
223
+ end ( )
224
+ } )
225
+ } )
226
+ } )
227
+
144
228
test ( 'client span(db) is bridge accordingly(statement test)' , ( t , end ) => {
145
229
const { agent, tracer } = t . nr
146
230
const attributes = {
@@ -247,7 +331,7 @@ test('server span is bridged accordingly', (t, end) => {
247
331
tracer . startActiveSpan ( 'http-test' , { kind : otel . SpanKind . SERVER , attributes } , ( span ) => {
248
332
const tx = agent . getTransaction ( )
249
333
assert . equal ( tx . traceId , span . spanContext ( ) . traceId )
250
- span . setAttribute ( ATTR_HTTP_STATUS_CODE , 200 )
334
+ span . setAttribute ( ATTR_HTTP_RES_STATUS_CODE , 200 )
251
335
span . setAttribute ( ATTR_HTTP_STATUS_TEXT , 'OK' )
252
336
span . end ( )
253
337
assert . ok ( ! tx . isDistributedTrace )
0 commit comments