@newrelic/apollo-server-plugin
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -103,35 +103,4 @@ /* | ||
return { | ||
/** | ||
* The document AST has been parsed so we can attempt to name the operation | ||
* and update the transaction name based on operation | ||
*/ | ||
validationDidStart(validationContext) { | ||
const operationDetails = getOperationDetails(validationContext) | ||
if (operationDetails) { | ||
const { operationName, operationType, deepestUniquePath, cleanedQuery } = | ||
operationDetails | ||
operationSegment.addAttribute(OPERATION_QUERY_ATTR, cleanedQuery) | ||
operationSegment.addAttribute(OPERATION_TYPE_ATTR, operationType) | ||
if (operationName) { | ||
operationSegment.addAttribute(OPERATION_NAME_ATTR, operationName) | ||
} | ||
const formattedName = operationName || ANON_PLACEHOLDER | ||
let formattedOperation = `${operationType}/${formattedName}` | ||
// Certain requests, such as introspection, won't hit any resolvers | ||
if (deepestUniquePath) { | ||
formattedOperation += `/${deepestUniquePath}` | ||
} | ||
const segmentName = formattedOperation | ||
const transactionName = formattedOperation | ||
setTransactionName(operationSegment.transaction, transactionName) | ||
operationSegment.name = `${OPERATION_PREFIX}/${segmentName}` | ||
} | ||
}, | ||
didResolveOperation(resolveContext) { | ||
updateOperationSegmentName(resolveContext, operationSegment) | ||
if (shouldIgnoreTransaction(resolveContext.operation, config, logger)) { | ||
@@ -195,10 +164,16 @@ const activeSegment = instrumentationApi.getActiveSegment() | ||
for (const [key, value] of Object.entries(args)) { | ||
// Require adding to attribute 'include' configuration | ||
// so as not to accidentally send senstive info to New Relic. | ||
resolverSegment.attributes.addAttribute( | ||
DESTINATIONS.NONE, | ||
`${FIELD_ARGS_ATTR}.${key}`, | ||
value | ||
) | ||
// Like our http and framework instrumentation, we add | ||
// the attributes on the operation segment. We also add | ||
// the attributes to resolver segments as they help | ||
// inform performance impacts. | ||
for (const segment of [operationSegment, resolverSegment]) { | ||
for (const [key, value] of Object.entries(args)) { | ||
// Require adding to attribute 'include' configuration | ||
// so as not to accidentally send senstive info to New Relic. | ||
segment.attributes.addAttribute( | ||
DESTINATIONS.NONE, | ||
`${FIELD_ARGS_ATTR}.${key}`, | ||
value | ||
) | ||
} | ||
} | ||
@@ -222,7 +197,10 @@ | ||
}, | ||
willSendResponse() { | ||
willSendResponse(responseContext) { | ||
// check if operation segment was never updated from default name | ||
// If so, update the transaction name to `*` | ||
// If so, try to rename before setting the transaction name to `*` | ||
if (operationSegment.name === DEFAULT_OPERATION_NAME) { | ||
setTransactionName(operationSegment.transaction, '*') | ||
const updated = updateOperationSegmentName(responseContext, operationSegment) | ||
if (!updated) { | ||
setTransactionName(operationSegment.transaction, '*') | ||
} | ||
} | ||
@@ -534,2 +512,42 @@ operationSegment.end() | ||
/** | ||
* Attempts to extract the document from the request context and | ||
* add attributes for the query, operation type, operation name and | ||
* update the transaction name based on operation name as well | ||
* | ||
* @param {Object} context apollo request context | ||
* @param {Segment} operationSegment default segment created in request start | ||
* @return {Boolean} true if document could be parsed from context | ||
*/ | ||
function updateOperationSegmentName(context, operationSegment) { | ||
const operationDetails = getOperationDetails(context) | ||
if (operationDetails) { | ||
const { operationName, operationType, deepestUniquePath, cleanedQuery } = operationDetails | ||
operationSegment.addAttribute(OPERATION_QUERY_ATTR, cleanedQuery) | ||
operationSegment.addAttribute(OPERATION_TYPE_ATTR, operationType) | ||
if (operationName) { | ||
operationSegment.addAttribute(OPERATION_NAME_ATTR, operationName) | ||
} | ||
const formattedName = operationName || ANON_PLACEHOLDER | ||
let formattedOperation = `${operationType}/${formattedName}` | ||
// Certain requests, such as introspection, won't hit any resolvers | ||
if (deepestUniquePath) { | ||
formattedOperation += `/${deepestUniquePath}` | ||
} | ||
const segmentName = formattedOperation | ||
const transactionName = formattedOperation | ||
setTransactionName(operationSegment.transaction, transactionName) | ||
operationSegment.name = `${OPERATION_PREFIX}/${segmentName}` | ||
return true | ||
} | ||
return false | ||
} | ||
module.exports = createPlugin |
{ | ||
"name": "@newrelic/apollo-server-plugin", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "Apollo Server plugin that adds New Relic Node.js agent instrumentation.", | ||
@@ -19,3 +19,3 @@ "main": "./index.js", | ||
"versioned:major": "versioned-tests --major --all -i 2 'tests/versioned/*'", | ||
"versioned:npm6": "versioned-tests --minor --samples 15 -i 2 'tests/versioned/**/!(apollo-server-koa)' && versioned-tests --minor --all -i 2 'tests/versioned/apollo-server-koa'", | ||
"versioned:npm6": "versioned-tests --minor --samples 15 -i 2 'tests/versioned/*'", | ||
"versioned:npm7": "versioned-tests --minor --all --samples 15 -i 2 'tests/versioned/*'" | ||
@@ -44,3 +44,3 @@ }, | ||
"@newrelic/newrelic-oss-cli": "^0.1.2", | ||
"@newrelic/test-utilities": "^6.1.1", | ||
"@newrelic/test-utilities": "^6.5.2", | ||
"apollo-server": "^2.18.2", | ||
@@ -58,3 +58,3 @@ "eslint": "^7.32.0", | ||
"sinon": "^11.1.2", | ||
"tap": "^15.0.6", | ||
"tap": "^16.0.1", | ||
"tsd": "^0.18.0" | ||
@@ -61,0 +61,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49036
527