Skip to content

Commit

Permalink
Active tracing configuration (#3928)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Hunter II <[email protected]>
Co-authored-by: Igor Unanua <[email protected]>
Co-authored-by: simon-id <[email protected]>
Co-authored-by: Attila Szegedi <[email protected]>
  • Loading branch information
5 people authored and uurien committed Mar 7, 2024
1 parent 0f9190b commit d5a4d0b
Show file tree
Hide file tree
Showing 18 changed files with 758 additions and 518 deletions.
11 changes: 11 additions & 0 deletions packages/datadog-core/src/utils/src/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

module.exports = (object, path) => {
const pathArr = path.split('.')
let val = object
for (const p of pathArr) {
if (val === undefined) return val
val = val[p]
}
return val
}
14 changes: 14 additions & 0 deletions packages/datadog-core/src/utils/src/has.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

module.exports = (object, path) => {
const pathArr = path.split('.')
let property = object
for (const n of pathArr) {
if (property.hasOwnProperty(n)) {
property = property[n]
} else {
return false
}
}
return true
}
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions packages/datadog-core/src/utils/src/set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

module.exports = (object, path, value) => {
const pathArr = path.split('.')
let property = object
let i
for (i = 0; i < pathArr.length - 1; i++) {
const n = pathArr[i]
if (property.hasOwnProperty(n)) {
property = property[n]
} else {
property[n] = property = {}
}
}
property[pathArr[i]] = value
}
File renamed without changes.
22 changes: 22 additions & 0 deletions packages/datadog-core/test/utils/src/get.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

require('../../../../dd-trace/test/setup/tap')

const { expect } = require('chai')
const get = require('../../../src/utils/src/get')

describe('get', () => {
const obj = {
'a': {
'b': 'c'
}
}

it('should return value at path', () => {
expect(get(obj, 'a.b')).to.be.equal('c')
})

it('should return undefined if path does not exist', () => {
expect(get(obj, 'd')).to.be.undefined
})
})
22 changes: 22 additions & 0 deletions packages/datadog-core/test/utils/src/has.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

require('../../../../dd-trace/test/setup/tap')

const { expect } = require('chai')
const has = require('../../../src/utils/src/has')

describe('has', () => {
const obj = {
'a': {
'b': 'c'
}
}

it('should true if path exists', () => {
expect(has(obj, 'a.b')).to.be.true
})

it('should return false if path does not exist', () => {
expect(has(obj, 'd')).to.be.false
})
})
15 changes: 15 additions & 0 deletions packages/datadog-core/test/utils/src/set.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

require('../../../../dd-trace/test/setup/tap')

const { expect } = require('chai')
const set = require('../../../src/utils/src/set')

describe('set', () => {
const obj = {}

it('should set value at path', () => {
set(obj, 'a.b', 'c')
expect(obj.a.b).to.be.equal('c')
})
})
2 changes: 1 addition & 1 deletion packages/datadog-instrumentations/src/amqplib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
addHook,
AsyncResource
} = require('./helpers/instrument')
const kebabCase = require('../../utils/src/kebabcase')
const kebabCase = require('../../datadog-core/src/utils/src/kebabcase')
const shimmer = require('../../datadog-shimmer')

const startCh = channel('apm:amqplib:command:start')
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-graphql/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const pick = require('../../utils/src/pick')
const pick = require('../../datadog-core/src/utils/src/pick')
const CompositePlugin = require('../../dd-trace/src/plugins/composite')
const log = require('../../dd-trace/src/log')
const GraphQLExecutePlugin = require('./execute')
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-grpc/src/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const pick = require('../../utils/src/pick')
const pick = require('../../datadog-core/src/utils/src/pick')
const log = require('../../dd-trace/src/log')

module.exports = {
Expand Down
Loading

0 comments on commit d5a4d0b

Please sign in to comment.