diff --git a/packages/dd-trace/src/config.js b/packages/dd-trace/src/config.js index f6ac65eb204..5363367d1ed 100644 --- a/packages/dd-trace/src/config.js +++ b/packages/dd-trace/src/config.js @@ -1,7 +1,6 @@ 'use strict' const fs = require('fs') -const jp = require('jsonpath-plus') const os = require('os') const uuid = require('crypto-randomuuid') // we need to keep the old uuid dep because of cypress const URL = require('url').URL @@ -122,23 +121,14 @@ function validateNamingVersion (versionString) { } /** - * Given a string of comma-separated paths, return the array of paths if - * all paths are valid JSON paths, or undefined if any path is invalid. + * Given a string of comma-separated paths, return the array of paths. * * @param {string} input - * @returns {[string] | undefined} + * @returns {[string]} */ -function validJSONPathsOrUndef (input) { +function splitJSONPathRules (input) { if (input === 'all') return [] - const rules = input.split(',') - for (const rule of rules) { - try { - jp.parse(rule) - } catch (e) { - return undefined - } - } - return rules + return input.split(',') } // Shallow clone with property name remapping @@ -309,14 +299,14 @@ class Config { null ) - const DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING = validJSONPathsOrUndef( + const DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING = splitJSONPathRules( coalesce( process.env.DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING, options.cloudPayloadTagging?.request, '' )) - const DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING = validJSONPathsOrUndef( + const DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING = splitJSONPathRules( coalesce( process.env.DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING, options.cloudPayloadTagging?.response, diff --git a/packages/dd-trace/src/payload-tagging/index.js b/packages/dd-trace/src/payload-tagging/index.js index 86a12c049b7..06ccea604db 100644 --- a/packages/dd-trace/src/payload-tagging/index.js +++ b/packages/dd-trace/src/payload-tagging/index.js @@ -5,7 +5,7 @@ const { PAYLOAD_TAG_RESPONSE_PREFIX } = require('../constants') -const jsonpath = require('jsonpath-plus') +const jsonpath = require('jsonpath-plus').JSONPath const { tagsFromObject } = require('./tagging') @@ -15,7 +15,7 @@ const { tagsFromObject } = require('./tagging') * @param {any} value * @returns {any} the parsed object if parsing was successful, the input if not */ -function expandValue (value) { +function maybeJSONParseValue (value) { if (typeof value === 'string') { try { return JSON.parse(value) @@ -34,7 +34,7 @@ function expandValue (value) { */ function expand (object, expansionRules) { for (const rule of expansionRules) { - jsonpath.apply(object, rule, expandValue) + jsonpath(rule, object, maybeJSONParseValue) } } @@ -46,7 +46,7 @@ function expand (object, expansionRules) { */ function redact (object, redactionRules) { for (const rule of redactionRules) { - jsonpath.apply(object, rule, () => 'redacted') + jsonpath(rule, object, () => 'redacted') } }