@@ -9,12 +9,12 @@ const Transaction = require('../../transaction')
9
9
const httpRecorder = require ( '../../metrics/recorders/http' )
10
10
const urltils = require ( '../../util/urltils' )
11
11
const url = require ( 'node:url' )
12
+ const { NODEJS , ACTION_DELIMITER } = require ( '../../metrics/names' )
12
13
13
14
const DESTINATION = Transaction . DESTINATIONS . TRANS_COMMON
14
15
const {
15
16
ATTR_HTTP_METHOD ,
16
17
ATTR_HTTP_REQUEST_METHOD ,
17
- ATTR_HTTP_ROUTE ,
18
18
ATTR_HTTP_URL ,
19
19
ATTR_RPC_METHOD ,
20
20
ATTR_RPC_SERVICE ,
@@ -24,15 +24,15 @@ const {
24
24
module . exports = function createServerSegment ( agent , otelSpan ) {
25
25
const transaction = new Transaction ( agent )
26
26
transaction . type = 'web'
27
+ transaction . nameState . setPrefix ( NODEJS . PREFIX )
28
+ transaction . nameState . setPrefix ( ACTION_DELIMITER )
27
29
const rpcSystem = otelSpan . attributes [ ATTR_RPC_SYSTEM ]
28
30
const httpMethod = otelSpan . attributes [ ATTR_HTTP_METHOD ] ?? otelSpan . attributes [ ATTR_HTTP_REQUEST_METHOD ]
29
31
let segment
30
32
if ( rpcSystem ) {
31
33
segment = rpcSegment ( { agent, otelSpan, transaction, rpcSystem } )
32
- } else if ( httpMethod ) {
33
- segment = httpSegment ( { agent, otelSpan, transaction, httpMethod } )
34
34
} else {
35
- segment = genericHttpSegment ( { agent, transaction } )
35
+ segment = httpSegment ( { agent, otelSpan , transaction, httpMethod } )
36
36
}
37
37
transaction . baseSegment = segment
38
38
return { segment, transaction }
@@ -41,11 +41,12 @@ module.exports = function createServerSegment(agent, otelSpan) {
41
41
function rpcSegment ( { agent, otelSpan, transaction, rpcSystem } ) {
42
42
const rpcService = otelSpan . attributes [ ATTR_RPC_SERVICE ] || 'Unknown'
43
43
const rpcMethod = otelSpan . attributes [ ATTR_RPC_METHOD ] || 'Unknown'
44
- const name = `WebTransaction/WebFrameworkUri/${ rpcSystem } /${ rpcService } .${ rpcMethod } `
45
- transaction . name = name
46
- transaction . trace . attributes . addAttribute ( DESTINATION , 'request.method' , rpcMethod )
47
- transaction . trace . attributes . addAttribute ( DESTINATION , 'request.uri' , name )
44
+ const name = `${ rpcService } /${ rpcMethod } `
48
45
transaction . url = name
46
+ transaction . trace . attributes . addAttribute ( DESTINATION , 'request.method' , rpcMethod )
47
+ transaction . trace . attributes . addAttribute ( DESTINATION , 'request.uri' , transaction . url )
48
+ transaction . nameState . setPrefix ( rpcSystem )
49
+ transaction . nameState . appendPath ( transaction . url )
49
50
const segment = agent . tracer . createSegment ( {
50
51
name,
51
52
recorder : httpRecorder ,
@@ -56,34 +57,22 @@ function rpcSegment({ agent, otelSpan, transaction, rpcSystem }) {
56
57
return segment
57
58
}
58
59
59
- // most instrumentation will hit this case
60
- // I find that if the request is in a web framework, the web framework instrumentation
61
- // sets `http.route` and when the span closes it pulls that attribute in
62
- // we'll most likely need to wire up some naming reconciliation
63
- // to handle this use case.
64
60
function httpSegment ( { agent, otelSpan, transaction, httpMethod } ) {
65
- const httpRoute = otelSpan . attributes [ ATTR_HTTP_ROUTE ] || 'Unknown'
66
61
const httpUrl = otelSpan . attributes [ ATTR_HTTP_URL ] || '/Unknown'
62
+ transaction . nameState . setVerb ( httpMethod )
67
63
const requestUrl = url . parse ( httpUrl , true )
68
- const name = `WebTransaction/Nodejs/${ httpMethod } /${ httpRoute } `
69
- transaction . name = name
64
+ transaction . parsedUrl = requestUrl
70
65
transaction . url = urltils . obfuscatePath ( agent . config , requestUrl . pathname )
71
66
transaction . trace . attributes . addAttribute ( DESTINATION , 'request.uri' , transaction . url )
72
- transaction . trace . attributes . addAttribute ( DESTINATION , 'request.method' , httpMethod )
73
- return agent . tracer . createSegment ( {
74
- name,
75
- recorder : httpRecorder ,
76
- parent : transaction . trace . root ,
77
- transaction
78
- } )
79
- }
80
-
81
- function genericHttpSegment ( { agent, transaction } ) {
82
- const name = 'WebTransaction/NormalizedUri/*'
83
- transaction . name = name
67
+ if ( httpMethod ) {
68
+ transaction . trace . attributes . addAttribute ( DESTINATION , 'request.method' , httpMethod )
69
+ }
70
+ transaction . applyUserNamingRules ( requestUrl . pathname )
71
+ // accept dt headers?
72
+ // synthetics.assignHeadersToTransaction(agent.config, transaction, )
84
73
return agent . tracer . createSegment ( {
85
- name,
86
74
recorder : httpRecorder ,
75
+ name : requestUrl . pathname ,
87
76
parent : transaction . trace . root ,
88
77
transaction
89
78
} )
0 commit comments