@@ -43,6 +43,7 @@ module.exports = function requestDidStart({ api, shim, logger, config }, request
43
43
logger . trace ( 'Begin requestDidStart' )
44
44
45
45
const requestParent = shim . getActiveSegment ( )
46
+ const transaction = shim . tracer . getTransaction ( )
46
47
47
48
if ( ! requestParent ) {
48
49
logger . trace ( 'No active segment found at query start. Not recording.' )
@@ -60,10 +61,10 @@ module.exports = function requestDidStart({ api, shim, logger, config }, request
60
61
61
62
return {
62
63
didResolveOperation : didResolveOperation . bind ( null , {
63
- shim,
64
64
config,
65
65
logger,
66
- operationSegment
66
+ operationSegment,
67
+ transaction
67
68
} ) ,
68
69
didEncounterErrors : didEncounterErrors . bind ( null , { shim, operationSegment } ) ,
69
70
executionDidStart ( ) {
@@ -79,7 +80,8 @@ module.exports = function requestDidStart({ api, shim, logger, config }, request
79
80
config,
80
81
logger,
81
82
operationSegment,
82
- requestContext
83
+ requestContext,
84
+ transaction
83
85
} )
84
86
}
85
87
} ,
@@ -88,7 +90,8 @@ module.exports = function requestDidStart({ api, shim, logger, config }, request
88
90
shim,
89
91
config,
90
92
logger,
91
- operationSegment
93
+ operationSegment,
94
+ transaction
92
95
} )
93
96
}
94
97
}
@@ -104,14 +107,10 @@ module.exports = function requestDidStart({ api, shim, logger, config }, request
104
107
* @param {TraceSegment } params.operationSegment the segment capturing the operation
105
108
* @param {GraphQLRequestContext } requestContext context on operation resolution
106
109
*/
107
- function didResolveOperation ( { shim , config, logger, operationSegment } , requestContext ) {
108
- updateOperationSegmentName ( requestContext , operationSegment )
110
+ function didResolveOperation ( { config, logger, operationSegment, transaction } , requestContext ) {
111
+ updateOperationSegmentName ( requestContext , operationSegment , transaction )
109
112
if ( shouldIgnoreTransaction ( requestContext . operation , config , logger ) ) {
110
- const activeSegment = shim . getActiveSegment ( )
111
- if ( activeSegment ) {
112
- const transaction = activeSegment . transaction
113
- transaction . setForceIgnore ( true )
114
- }
113
+ transaction . setForceIgnore ( true )
115
114
}
116
115
}
117
116
@@ -146,15 +145,15 @@ function didEncounterErrors({ shim, operationSegment }, requestContext) {
146
145
* @returns {Function } handler once field resolves, used to handle errors
147
146
*/
148
147
function willResolveField (
149
- { api, shim, logger, config, operationSegment, requestContext } ,
148
+ { api, shim, logger, config, operationSegment, requestContext, transaction } ,
150
149
resolverContext
151
150
) {
152
151
const { info, args } = resolverContext
153
152
const pathArray = flattenToArray ( info . path )
154
153
const formattedPath = pathArray . reverse ( ) . join ( '.' )
155
154
const flattenedArgs = flattenArgs ( { obj : args } )
156
155
157
- maybeCaptureFieldMetrics ( { operationSegment , info, args : flattenedArgs , config } )
156
+ maybeCaptureFieldMetrics ( { transaction , info, args : flattenedArgs , config } )
158
157
159
158
if ( ! config . captureScalars && ! isTopLevelField ( info ) && isScalar ( info ) ) {
160
159
return null
@@ -237,13 +236,16 @@ function fieldResolver({ shim, requestContext, resolverSegment, currentSegment }
237
236
* @param {TraceSegment } params.operationSegment the segment capturing the operation
238
237
* @param {GraphQLRequestContext } requestContext context on operation resolution
239
238
*/
240
- function willSendResponse ( { api, shim, config, logger, operationSegment } , requestContext ) {
239
+ function willSendResponse (
240
+ { api, shim, config, logger, operationSegment, transaction } ,
241
+ requestContext
242
+ ) {
241
243
// check if operation segment was never updated from default name
242
244
// If so, try to rename before setting the transaction name to `*`
243
245
if ( operationSegment . name === DEFAULT_OPERATION_NAME ) {
244
- const updated = updateOperationSegmentName ( requestContext , operationSegment )
246
+ const updated = updateOperationSegmentName ( requestContext , operationSegment , transaction )
245
247
if ( ! updated ) {
246
- setTransactionName ( operationSegment . transaction , '*' )
248
+ setTransactionName ( transaction , '*' )
247
249
}
248
250
}
249
251
0 commit comments