Skip to content

Commit

Permalink
jsonpath-plus different signature
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Jun 4, 2024
1 parent 4fb072e commit aa6cfc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
22 changes: 6 additions & 16 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -310,14 +300,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,
Expand Down
8 changes: 4 additions & 4 deletions packages/dd-trace/src/payload-tagging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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)
Expand All @@ -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)
}
}

Expand All @@ -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')
}
}

Expand Down

0 comments on commit aa6cfc5

Please sign in to comment.