in lib/instrumentation/modules/graphql.js [134:205]
function wrapExecute(orig) {
return function wrappedExecute(args) {
agent.logger.debug('intercepted call to graphql.execute');
const span = ins.createSpan(
'GraphQL: Unknown Query',
'db',
'graphql',
'execute',
);
if (!span) {
agent.logger.debug(
'no active transaction found - skipping graphql tracing',
);
return orig.apply(this, arguments);
}
let document;
let operationName;
const singleArgForm =
onlySupportsSingleArg ||
(!onlySupportsPositionalArgs && arguments.length === 1);
if (singleArgForm) {
document = args.document;
operationName = args.operationName;
} else {
document = arguments[1];
operationName = arguments[5];
}
var details = extractDetails(document, operationName);
var queries = details.queries;
operationName =
operationName ||
(details.operation &&
details.operation.name &&
details.operation.name.value);
if (queries.length > 0) {
span.name =
'GraphQL: ' +
(operationName ? operationName + ' ' : '') +
queries.join(', ');
}
// `_graphqlRoute` is a boolean, set in instrumentations of other modules
// that specify 'graphql' in peerDependencies (e.g. '@apollo/server') to
// indicate that this transaction is for a GraphQL request.
const trans = span.transaction;
if (trans._graphqlRoute) {
var name =
queries.length > 0 ? queries.join(', ') : 'Unknown GraphQL query';
if (trans.req) var path = getPathFromRequest(trans.req, true);
var defaultName = name;
defaultName = path ? defaultName + ' (' + path + ')' : defaultName;
defaultName = operationName
? operationName + ' ' + defaultName
: defaultName;
trans.setDefaultName(defaultName);
trans.type = 'graphql';
}
const spanRunContext = ins.currRunContext().enterSpan(span);
const p = ins.withRunContext(spanRunContext, orig, this, ...arguments);
if (typeof p.then === 'function') {
p.then(function () {
span.end();
});
} else {
span.end();
}
return p;
};
}