@newrelic/apollo-server-plugin
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -15,3 +15,2 @@ /* | ||
const ANON_PLACEHOLDER = '<anonymous>' | ||
const UNKNOWN_OPERATION = '<unknown>' | ||
@@ -24,2 +23,4 @@ const CATEGORY = 'GraphQL' | ||
const DEFAULT_OPERATION_NAME = `${OPERATION_PREFIX}/<unknown>` | ||
const FIELD_NAME_ATTR = 'graphql.field.name' | ||
@@ -91,3 +92,3 @@ const RETURN_TYPE_ATTR = 'graphql.field.returnType' | ||
const operationSegment = instrumentationApi.createSegment( | ||
UNKNOWN_OPERATION, | ||
DEFAULT_OPERATION_NAME, | ||
recordOperationSegment, | ||
@@ -105,2 +106,34 @@ requestParent | ||
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) { | ||
@@ -191,35 +224,8 @@ if (shouldIgnoreTransaction(resolveContext.operation, config, logger)) { | ||
}, | ||
willSendResponse(responseContext) { | ||
// default. only used if failed to parse | ||
let transactionName = '*' | ||
let segmentName = UNKNOWN_OPERATION | ||
const operationDetails = getOperationDetails(responseContext) | ||
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}` | ||
} | ||
segmentName = formattedOperation | ||
transactionName = formattedOperation | ||
willSendResponse() { | ||
// check if operation segment was never updated from default name | ||
// If so, update the transaction name to `*` | ||
if (operationSegment.name === DEFAULT_OPERATION_NAME) { | ||
setTransactionName(operationSegment.transaction, '*') | ||
} | ||
setTransactionName(operationSegment.transaction, transactionName) | ||
operationSegment.name = `${OPERATION_PREFIX}/${segmentName}` | ||
operationSegment.end() | ||
@@ -226,0 +232,0 @@ |
@@ -32,2 +32,3 @@ /* | ||
noticeError(instrumentationApi, error) { | ||
error = error.originalError || error | ||
const activeSegment = instrumentationApi.getActiveSegment() | ||
@@ -34,0 +35,0 @@ const transaction = activeSegment && activeSegment.transaction |
{ | ||
"name": "@newrelic/apollo-server-plugin", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Apollo Server plugin that adds New Relic Node.js agent instrumentation.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
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
48414
510