UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

82 lines (66 loc) 1.97 kB
'use strict' function extractErrorIntoSpanEvent (config, span, exc) { const attributes = {} if (exc.name) { attributes.type = exc.name } // graphql-js validation errors carry a lazy `.stack` accessor; reading it // here is the only consumer in the pipeline and pays full V8 symbolisation. const isValidationOnly = exc.locations && !exc.path && !exc.originalError?.stack if (!isValidationOnly && exc.stack) { attributes.stacktrace = exc.stack } if (exc.locations) { attributes.locations = [] for (const location of exc.locations) { attributes.locations.push(`${location.line}:${location.column}`) } } if (exc.path) { attributes.path = exc.path.map(String) } if (exc.message) { attributes.message = exc.message } if (config.DD_TRACE_GRAPHQL_ERROR_EXTENSIONS) { for (const ext of config.DD_TRACE_GRAPHQL_ERROR_EXTENSIONS) { if (exc.extensions?.[ext]) { const value = exc.extensions[ext] // We should only stringify the value if it is not of type number or boolean if (typeof value === 'number' || typeof value === 'boolean') { attributes[`extensions.${ext}`] = value } else { attributes[`extensions.${ext}`] = String(value) } } } } span.addEvent('dd.graphql.query.error', attributes, Date.now()) } let tools function getSignature (document, operationName, operationType, calculate) { if (calculate !== false && tools !== false) { try { try { tools ||= require('./tools') } catch (e) { tools = false throw e } return tools.defaultEngineReportingSignature(document, operationName) } catch { // safety net } } if (operationType) { if (operationName) { return `${operationType} ${operationName}` } return operationType } return operationName ?? '' } module.exports = { extractErrorIntoSpanEvent, getSignature, }