UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

50 lines (39 loc) 1.12 kB
'use strict' function extractErrorIntoSpanEvent (config, span, exc) { const attributes = {} if (exc.name) { attributes.type = exc.name } if (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.graphqlErrorExtensions) { for (const ext of config.graphqlErrorExtensions) { 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()) } module.exports = { extractErrorIntoSpanEvent }