New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dd-trace

Package Overview
Dependencies
Maintainers
1
Versions
610
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dd-trace - npm Package Compare versions

Comparing version 5.35.0 to 5.36.0

packages/dd-trace/src/appsec/iast/taint-tracking/constants.js

8

package.json
{
"name": "dd-trace",
"version": "5.35.0",
"version": "5.36.0",
"description": "Datadog APM tracing client for JavaScript",

@@ -16,3 +16,3 @@ "main": "index.js",

"lint": "node scripts/check_licenses.js && eslint . && yarn audit",
"lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
"lint:fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
"release:proposal": "node scripts/release/proposal",

@@ -87,3 +87,3 @@ "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",

"@datadog/native-appsec": "8.4.0",
"@datadog/native-iast-rewriter": "2.6.1",
"@datadog/native-iast-rewriter": "2.8.0",
"@datadog/native-iast-taint-tracking": "3.2.0",

@@ -122,3 +122,3 @@ "@datadog/native-metrics": "^3.1.0",

"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.11.1",
"@eslint/js": "^8.57.1",
"@msgpack/msgpack": "^3.0.0-beta3",

@@ -125,0 +125,0 @@ "@stylistic/eslint-plugin-js": "^2.8.0",

'use strict'
const storage = require('./src/storage')
const { storage } = require('./src/storage')
module.exports = { storage }

@@ -5,29 +5,53 @@ 'use strict'

class DatadogStorage {
constructor () {
this._storage = new AsyncLocalStorage()
}
disable () {
this._storage.disable()
}
/**
* This is exactly the same as AsyncLocalStorage, with the exception that it
* uses a WeakMap to store the store object. This is because ALS stores the
* store object as a property of the resource object, which causes all sorts
* of problems with logging and memory. We substitute the `store` object with
* a "handle" object, which is used as a key in a WeakMap, where the values
* are the real store objects.
*
* @template T
*/
class DatadogStorage extends AsyncLocalStorage {
/**
*
* @param store {DatadogStorage}
*/
enterWith (store) {
const handle = {}
stores.set(handle, store)
this._storage.enterWith(handle)
super.enterWith(handle)
}
exit (callback, ...args) {
this._storage.exit(callback, ...args)
}
// TODO: Refactor the Scope class to use a span-only store and remove this.
/**
* This is method is a passthrough to the real `getStore()`, so that, when we
* need it, we can use the handle rather than our mapped store.
*
* It's only here because stores are currently used for a bunch of things,
* and we don't want to hold on to all of them in spans
* (see opentracing/span.js). Using a namespaced storage for spans would
* solve this.
*
* TODO: Refactor the Scope class to use a span-only store and remove this.
*
* @returns {{}}
*/
getHandle () {
return this._storage.getStore()
return super.getStore()
}
/**
* Here, we replicate the behavior of the original `getStore()` method by
* passing in the handle, which we retrieve by calling it on super. Handles
* retrieved through `getHandle()` can also be passed in to be used as the
* key. This is useful if you've stashed a handle somewhere and want to
* retrieve the store with it.
*
* @param handle {{}}
* @returns {T | undefined}
*/
getStore (handle) {
if (!handle) {
handle = this._storage.getStore()
handle = super.getStore()
}

@@ -38,4 +62,17 @@

/**
* Here, we replicate the behavior of the original `run()` method. We ensure
* that our `enterWith()` is called internally, so that the handle to the
* store is set. As an optimization, we use super for getStore and enterWith
* when dealing with the parent store, so that we don't have to access the
* WeakMap.
* @template R
* @template TArgs extends any[]
* @param store {DatadogStorage}
* @param fn {() => R}
* @param args {TArgs}
* @returns {void}
*/
run (store, fn, ...args) {
const prior = this._storage.getStore()
const prior = super.getStore()
this.enterWith(store)

@@ -45,3 +82,3 @@ try {

} finally {
this._storage.enterWith(prior)
super.enterWith(prior)
}

@@ -51,6 +88,23 @@ }

/**
* This is the map from handles to real stores, used in the class above.
* @template T
* @type {WeakMap<WeakKey, T>}
*/
const stores = new WeakMap()
/**
* For convenience, we use the `storage` function as a registry of namespaces
* corresponding to DatadogStorage instances. This lets us have separate
* storages for separate purposes.
* @type {Map<string, DatadogStorage>}
*/
const storages = Object.create(null)
const legacyStorage = new DatadogStorage()
const storage = function (namespace) {
/**
*
* @param namespace {string} the namespace to use
* @returns {DatadogStorage}
*/
function storage (namespace) {
if (!storages[namespace]) {

@@ -62,11 +116,2 @@ storages[namespace] = new DatadogStorage()

storage.disable = legacyStorage.disable.bind(legacyStorage)
storage.enterWith = legacyStorage.enterWith.bind(legacyStorage)
storage.exit = legacyStorage.exit.bind(legacyStorage)
storage.getHandle = legacyStorage.getHandle.bind(legacyStorage)
storage.getStore = legacyStorage.getStore.bind(legacyStorage)
storage.run = legacyStorage.run.bind(legacyStorage)
const stores = new WeakMap()
module.exports = storage
module.exports = { storage }

@@ -316,6 +316,7 @@ 'use strict'

if (status === 'fail') {
const shouldSetProbe = this.isDiEnabled && willBeRetried && numTestExecutions === 1
asyncResource.runInAsyncScope(() => {
testErrCh.publish({
error: formatJestError(event.test.errors[0]),
shouldSetProbe: this.isDiEnabled && willBeRetried && numTestExecutions === 1,
shouldSetProbe,
promises

@@ -340,4 +341,3 @@ })

testStartLine: getTestLineStart(event.test.asyncError, this.testSuite),
promises,
shouldRemoveProbe: this.isDiEnabled && !willBeRetried
promises
})

@@ -349,6 +349,2 @@ })

}
if (promises.isProbeRemoved) {
await promises.isProbeRemoved
}
}

@@ -355,0 +351,0 @@ if (event.name === 'test_skip' || event.name === 'test_todo') {

@@ -23,3 +23,3 @@ 'use strict'

const resourceName = commandName.slice(0, commandName.indexOf('Command'))
const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store ? store.span : null

@@ -26,0 +26,0 @@ const meta = getMeta(resourceName, commandArgs)

@@ -13,3 +13,3 @@ 'use strict'

bindStart (ctx) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store ? store.span : null

@@ -16,0 +16,0 @@

@@ -28,3 +28,3 @@ 'use strict'

this.addSub('apm:apollo:gateway:general:error', (ctx) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -31,0 +31,0 @@ if (!span) return

@@ -18,3 +18,3 @@ 'use strict'

bindStart (ctx) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store ? store.span : null

@@ -21,0 +21,0 @@ const spanData = {

@@ -70,3 +70,3 @@ 'use strict'

const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -77,3 +77,3 @@ this.enter(span, store)

this.addSub(`apm:aws:request:region:${this.serviceIdentifier}`, region => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store) return

@@ -87,3 +87,3 @@ const { span } = store

this.addSub(`apm:aws:request:complete:${this.serviceIdentifier}`, ({ response, cbExists = false }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store) return

@@ -90,0 +90,0 @@ const { span } = store

@@ -24,3 +24,3 @@ 'use strict'

const { request, response } = obj
const store = storage.getStore()
const store = storage('legacy').getStore()
const plugin = this

@@ -53,3 +53,3 @@

// get the stream name that should have been stored previously
const { streamName } = storage.getStore()
const { streamName } = storage('legacy').getStore()

@@ -64,3 +64,3 @@ // extract DSM context after as we might not have a parent-child but may have a DSM context

this.addSub('apm:aws:response:finish:kinesis', err => {
const { span } = storage.getStore()
const { span } = storage('legacy').getStore()
this.finish(span, null, err)

@@ -85,3 +85,3 @@ })

const streamName = params.StreamName
storage.enterWith({ ...store, streamName })
storage('legacy').enterWith({ ...store, streamName })
}

@@ -88,0 +88,0 @@

@@ -23,3 +23,3 @@ 'use strict'

const { request, response } = obj
const store = storage.getStore()
const store = storage('legacy').getStore()
const plugin = this

@@ -51,3 +51,3 @@ const contextExtraction = this.responseExtract(request.params, request.operation, response)

this.addSub('apm:aws:response:finish:sqs', err => {
const { span } = storage.getStore()
const { span } = storage('legacy').getStore()
this.finish(span, null, err)

@@ -54,0 +54,0 @@ })

@@ -27,3 +27,3 @@ 'use strict'

const { functionName, methodName } = ctx
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -30,0 +30,0 @@ const span = this.startSpan(this.operationName(), {

@@ -45,3 +45,3 @@ 'use strict'

this.addSubs('query', ({ resource, bucket, seedNodes }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = this.startSpan(

@@ -68,3 +68,3 @@ 'query', {

this.addSubs(name, ({ bucket, collection, seedNodes }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = this.startSpan(name, {}, store, { bucket, collection, seedNodes })

@@ -71,0 +71,0 @@ this.enter(span, store)

@@ -216,3 +216,3 @@ 'use strict'

}) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const testSuite = getTestSuitePath(testFileAbsolutePath, this.sourceRoot)

@@ -235,3 +235,3 @@ const testSourceFile = getTestSuitePath(testFileAbsolutePath, this.repositoryRoot)

// Time we give the breakpoint to be hit
if (promises && this.runningTestProbeId) {
if (promises && this.runningTestProbe) {
promises.hitBreakpointPromise = new Promise((resolve) => {

@@ -244,3 +244,3 @@ setTimeout(resolve, BREAKPOINT_HIT_GRACE_PERIOD_MS)

this.addSub('ci:cucumber:test:retry', ({ isFirstAttempt, error }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store.span

@@ -254,4 +254,4 @@ if (!isFirstAttempt) {

if (probeInformation) {
const { probeId, stackIndex } = probeInformation
this.runningTestProbeId = probeId
const { file, line, stackIndex } = probeInformation
this.runningTestProbe = { file, line }
this.testErrorStackIndex = stackIndex

@@ -267,3 +267,3 @@ // TODO: we're not waiting for setProbePromise to be resolved, so there might be race conditions

this.addSub('ci:cucumber:test-step:start', ({ resource }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store ? store.span : store

@@ -321,3 +321,3 @@ const span = this.tracer.startSpan('cucumber.step', {

}) => {
const span = storage.getStore().span
const span = storage('legacy').getStore().span
const statusTag = isStep ? 'step.status' : TEST_STATUS

@@ -368,5 +368,5 @@

this.activeTestSpan = null
if (this.runningTestProbeId) {
this.removeDiProbe(this.runningTestProbeId)
this.runningTestProbeId = null
if (this.runningTestProbe) {
this.removeDiProbe(this.runningTestProbe)
this.runningTestProbe = null
}

@@ -378,3 +378,3 @@ }

if (err) {
const span = storage.getStore().span
const span = storage('legacy').getStore().span
span.setTag('error', err)

@@ -381,0 +381,0 @@ }

@@ -35,3 +35,4 @@ const {

TEST_LEVEL_EVENT_TYPES,
TEST_RETRY_REASON
TEST_RETRY_REASON,
DD_TEST_IS_USER_PROVIDED_SERVICE
} = require('../../dd-trace/src/plugins/util/test')

@@ -226,2 +227,6 @@ const { isMarkedAsUnskippable } = require('../../datadog-plugin-jest/src/util')

// we have to do it here because the tracer is not initialized in the constructor
this.testEnvironmentMetadata[DD_TEST_IS_USER_PROVIDED_SERVICE] =
tracer._tracer._config.isServiceUserProvided ? 'true' : 'false'
this.libraryConfigurationPromise = getLibraryConfiguration(this.tracer, this.testConfiguration)

@@ -228,0 +233,0 @@ .then((libraryConfigurationResponse) => {

@@ -7,2 +7,6 @@ /* eslint-disable */

let earlyFlakeDetectionNumRetries = 0
// We need to grab the original window as soon as possible,
// in case the test changes the origin. If the test does change the origin,
// any call to `cy.window()` will result in a cross origin error.
let originalWindow

@@ -65,2 +69,5 @@ // If the test is using multi domain with cy.origin, trying to access

})
cy.window().then(win => {
originalWindow = win
})
})

@@ -83,7 +90,9 @@

after(() => {
cy.window().then(win => {
if (safeGetRum(win)) {
win.dispatchEvent(new Event('beforeunload'))
try {
if (safeGetRum(originalWindow)) {
originalWindow.dispatchEvent(new Event('beforeunload'))
}
})
} catch (e) {
// ignore error. It's usually a multi origin issue.
}
})

@@ -93,28 +102,26 @@

afterEach(function () {
cy.window().then(win => {
const currentTest = Cypress.mocha.getRunner().suite.ctx.currentTest
const testInfo = {
testName: currentTest.fullTitle(),
testSuite: Cypress.mocha.getRootSuite().file,
testSuiteAbsolutePath: Cypress.spec && Cypress.spec.absolute,
state: currentTest.state,
error: currentTest.err,
isNew: currentTest._ddIsNew,
isEfdRetry: currentTest._ddIsEfdRetry
}
try {
testInfo.testSourceLine = Cypress.mocha.getRunner().currentRunnable.invocationDetails.line
} catch (e) {}
const currentTest = Cypress.mocha.getRunner().suite.ctx.currentTest
const testInfo = {
testName: currentTest.fullTitle(),
testSuite: Cypress.mocha.getRootSuite().file,
testSuiteAbsolutePath: Cypress.spec && Cypress.spec.absolute,
state: currentTest.state,
error: currentTest.err,
isNew: currentTest._ddIsNew,
isEfdRetry: currentTest._ddIsEfdRetry
}
try {
testInfo.testSourceLine = Cypress.mocha.getRunner().currentRunnable.invocationDetails.line
} catch (e) {}
if (safeGetRum(win)) {
testInfo.isRUMActive = true
}
let coverage
try {
coverage = win.__coverage__
} catch (e) {
// ignore error and continue
}
cy.task('dd:afterEach', { test: testInfo, coverage })
})
if (safeGetRum(originalWindow)) {
testInfo.isRUMActive = true
}
let coverage
try {
coverage = originalWindow.__coverage__
} catch (e) {
// ignore error and continue
}
cy.task('dd:afterEach', { test: testInfo, coverage })
})

@@ -23,3 +23,3 @@ 'use strict'

bindStart (message) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const { metadata, path, type } = message

@@ -26,0 +26,0 @@ const metadataFilter = this.config.metadataFilter

@@ -30,3 +30,3 @@ 'use strict'

bindStart (message) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const { name, metadata, type } = message

@@ -33,0 +33,0 @@ const metadataFilter = this.config.metadataFilter

@@ -18,3 +18,3 @@ 'use strict'

this.addSub('apm:hapi:request:handle', ({ req }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store && store.span

@@ -21,0 +21,0 @@

@@ -24,3 +24,3 @@ 'use strict'

const { args, http = {} } = message
const store = storage.getStore()
const store = storage('legacy').getStore()
const options = args.options

@@ -27,0 +27,0 @@ const agent = options.agent || options._defaultAgent || http.globalAgent || {}

@@ -25,3 +25,3 @@ 'use strict'

start ({ req, res, abortController }) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = web.startSpan(

@@ -28,0 +28,0 @@ this.tracer,

@@ -39,3 +39,3 @@ 'use strict'

const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store && allowed ? store.span : null

@@ -89,3 +89,3 @@ const span = this.startSpan(this.operationName(), {

return storage.getStore()
return storage('legacy').getStore()
}

@@ -103,3 +103,3 @@

if (!this.config.validateStatus(status)) {
storage.run(store, () => this.addError())
storage('legacy').run(store, () => this.addError())
}

@@ -106,0 +106,0 @@

@@ -20,3 +20,3 @@ 'use strict'

start ({ req, res }) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = web.startSpan(

@@ -23,0 +23,0 @@ this.tracer,

@@ -294,2 +294,3 @@ const CiPlugin = require('../../dd-trace/src/plugins/ci_plugin')

}
this.removeAllDiProbes()
})

@@ -321,3 +322,3 @@

this.addSub('ci:jest:test:start', (test) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = this.startTestSpan(test)

@@ -329,4 +330,4 @@

this.addSub('ci:jest:test:finish', ({ status, testStartLine, promises, shouldRemoveProbe }) => {
const span = storage.getStore().span
this.addSub('ci:jest:test:finish', ({ status, testStartLine }) => {
const span = storage('legacy').getStore().span
span.setTag(TEST_STATUS, status)

@@ -352,6 +353,2 @@ if (testStartLine) {

this.activeTestSpan = null
if (shouldRemoveProbe && this.runningTestProbeId) {
promises.isProbeRemoved = withTimeout(this.removeDiProbe(this.runningTestProbeId), 2000)
this.runningTestProbeId = null
}
})

@@ -361,3 +358,3 @@

if (error) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store && store.span) {

@@ -370,5 +367,3 @@ const span = store.span

if (probeInformation) {
const { probeId, setProbePromise, stackIndex } = probeInformation
this.runningTestProbeId = probeId
this.testErrorStackIndex = stackIndex
const { setProbePromise } = probeInformation
promises.isProbeReady = withTimeout(setProbePromise, 2000)

@@ -375,0 +370,0 @@ }

@@ -64,3 +64,3 @@ 'use strict'

const store = storage.getStore() || {}
const store = storage('legacy').getStore() || {}
ctx.currentStore = { ...store, span }

@@ -67,0 +67,0 @@

@@ -16,8 +16,8 @@ 'use strict'

this.addSub(`apm:${this.component}:pool:skip`, () => {
skippedStore = storage.getStore()
storage.enterWith({ noop: true })
skippedStore = storage('legacy').getStore()
storage('legacy').enterWith({ noop: true })
})
this.addSub(`apm:${this.component}:pool:unskip`, () => {
storage.enterWith(skippedStore)
storage('legacy').enterWith(skippedStore)
skippedStore = undefined

@@ -24,0 +24,0 @@ })

@@ -158,3 +158,3 @@ 'use strict'

}
const store = storage.getStore()
const store = storage('legacy').getStore()
this.enter(testSuiteSpan, store)

@@ -165,3 +165,3 @@ this._testSuites.set(testSuite, testSuiteSpan)

this.addSub('ci:mocha:test-suite:finish', (status) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store && store.span) {

@@ -179,3 +179,3 @@ const span = store.span

this.addSub('ci:mocha:test-suite:error', (err) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store && store.span) {

@@ -189,3 +189,3 @@ const span = store.span

this.addSub('ci:mocha:test:start', (testInfo) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = this.startTestSpan(testInfo)

@@ -202,3 +202,3 @@

this.addSub('ci:mocha:test:finish', ({ status, hasBeenRetried, isLastRetry }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -227,5 +227,5 @@

this.activeTestSpan = null
if (this.di && this.libraryConfig?.isDiEnabled && this.runningTestProbeId && isLastRetry) {
this.removeDiProbe(this.runningTestProbeId)
this.runningTestProbeId = null
if (this.di && this.libraryConfig?.isDiEnabled && this.runningTestProbe && isLastRetry) {
this.removeDiProbe(this.runningTestProbe)
this.runningTestProbe = null
}

@@ -236,3 +236,3 @@ }

this.addSub('ci:mocha:test:skip', (testInfo) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
// skipped through it.skip, so the span is not created yet

@@ -247,3 +247,3 @@ // for this test

this.addSub('ci:mocha:test:error', (err) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -261,3 +261,3 @@ if (err && span) {

this.addSub('ci:mocha:test:retry', ({ isFirstAttempt, willBeRetried, err, test }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -287,4 +287,4 @@ if (span) {

if (probeInformation) {
const { probeId, stackIndex } = probeInformation
this.runningTestProbeId = probeId
const { file, line, stackIndex } = probeInformation
this.runningTestProbe = { file, line }
this.testErrorStackIndex = stackIndex

@@ -291,0 +291,0 @@ test._ddShouldWaitForHitProbe = true

@@ -23,3 +23,3 @@ 'use strict'

bindStart ({ req, res }) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store ? store.span : store

@@ -47,3 +47,3 @@ const span = this.tracer.startSpan(this.operationName(), {

if (!span) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store) return

@@ -58,3 +58,3 @@

finish ({ req, res, nextRequest = {} }) {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -91,3 +91,3 @@ if (!store) return

pageLoad ({ page, isAppPath = false, isStatic = false }) {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -94,0 +94,0 @@ if (!store) return

@@ -63,3 +63,3 @@ 'use strict'

const payload = normalizeRequestPayload(methodName, args)
const store = storage.getStore() || {}
const store = storage('legacy').getStore() || {}

@@ -66,0 +66,0 @@ const span = this.startSpan('openai.request', {

@@ -71,3 +71,3 @@ 'use strict'

this.addSub('ci:playwright:test-suite:start', (testSuiteAbsolutePath) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const testSuite = getTestSuitePath(testSuiteAbsolutePath, this.rootDir)

@@ -106,3 +106,3 @@ const testSourceFile = getTestSuitePath(testSuiteAbsolutePath, this.repositoryRoot)

this.addSub('ci:playwright:test-suite:finish', ({ status, error }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store && store.span

@@ -126,3 +126,3 @@ if (!span) return

this.addSub('ci:playwright:test:start', ({ testName, testSuiteAbsolutePath, testSourceLine, browserName }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const testSuite = getTestSuitePath(testSuiteAbsolutePath, this.rootDir)

@@ -135,3 +135,3 @@ const testSourceFile = getTestSuitePath(testSuiteAbsolutePath, this.repositoryRoot)

this.addSub('ci:playwright:test:finish', ({ testStatus, steps, error, extraTags, isNew, isEfdRetry, isRetry }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store && store.span

@@ -138,0 +138,0 @@ if (!span) return

@@ -14,3 +14,3 @@ 'use strict'

this.addTraceSub('dispatch', ({ state }) => {
const span = storage.getStore().span
const span = storage('legacy').getStore().span
span.setTag('amqp.delivery.state', state)

@@ -17,0 +17,0 @@ })

@@ -32,3 +32,3 @@ 'use strict'

const store = storage.getStore()
const store = storage('legacy').getStore()
this._storeStack.push(store)

@@ -98,3 +98,3 @@ this.enter(span, store)

_getStoreSpan () {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -101,0 +101,0 @@ return store && store.span

@@ -42,3 +42,3 @@ const CiPlugin = require('../../dd-trace/src/plugins/ci_plugin')

}) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -45,0 +45,0 @@ if (!span) {

@@ -73,3 +73,3 @@ const CiPlugin = require('../../dd-trace/src/plugins/ci_plugin')

const testSuite = getTestSuitePath(testSuiteAbsolutePath, this.repositoryRoot)
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -106,3 +106,3 @@ const extraTags = {

this.addSub('ci:vitest:test:finish-time', ({ status, task }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -119,3 +119,3 @@

this.addSub('ci:vitest:test:pass', ({ task }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -134,3 +134,3 @@

this.addSub('ci:vitest:test:error', ({ duration, error, shouldSetProbe, promises }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -142,4 +142,4 @@

if (probeInformation) {
const { probeId, stackIndex, setProbePromise } = probeInformation
this.runningTestProbeId = probeId
const { file, line, stackIndex, setProbePromise } = probeInformation
this.runningTestProbe = { file, line }
this.testErrorStackIndex = stackIndex

@@ -229,3 +229,3 @@ promises.setProbePromise = setProbePromise

this.telemetry.ciVisEvent(TELEMETRY_EVENT_CREATED, 'suite')
const store = storage.getStore()
const store = storage('legacy').getStore()
this.enter(testSuiteSpan, store)

@@ -236,3 +236,3 @@ this.testSuiteSpan = testSuiteSpan

this.addSub('ci:vitest:test-suite:finish', ({ status, onFinish }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -247,4 +247,4 @@ if (span) {

this.tracer._exporter.flush(onFinish)
if (this.runningTestProbeId) {
this.removeDiProbe(this.runningTestProbeId)
if (this.runningTestProbe) {
this.removeDiProbe(this.runningTestProbe)
}

@@ -254,3 +254,3 @@ })

this.addSub('ci:vitest:test-suite:error', ({ error }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store?.span

@@ -257,0 +257,0 @@ if (span && error) {

@@ -33,3 +33,3 @@ 'use strict'

function onGraphqlStartResolve ({ context, resolverInfo }) {
const req = storage.getStore()?.req
const req = storage('legacy').getStore()?.req

@@ -53,3 +53,3 @@ if (!req) return

function enterInApolloMiddleware (data) {
const req = data?.req || storage.getStore()?.req
const req = data?.req || storage('legacy').getStore()?.req
if (!req) return

@@ -64,3 +64,3 @@

function enterInApolloServerCoreRequest () {
const req = storage.getStore()?.req
const req = storage('legacy').getStore()?.req
if (!req) return

@@ -75,3 +75,3 @@

function exitFromApolloMiddleware (data) {
const req = data?.req || storage.getStore()?.req
const req = data?.req || storage('legacy').getStore()?.req
const requestData = graphqlRequestData.get(req)

@@ -82,3 +82,3 @@ if (requestData) requestData.inApolloMiddleware = false

function enterInApolloRequest () {
const req = storage.getStore()?.req
const req = storage('legacy').getStore()?.req

@@ -93,3 +93,3 @@ const requestData = graphqlRequestData.get(req)

function beforeWriteApolloGraphqlResponse ({ abortController, abortData }) {
const req = storage.getStore()?.req
const req = storage('legacy').getStore()?.req
if (!req) return

@@ -96,0 +96,0 @@

@@ -18,3 +18,3 @@ 'use strict'

if (!this.evalInstrumentedInc) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const iastContext = getIastContext(store)

@@ -21,0 +21,0 @@ const tags = INSTRUMENTED_SINK.formatTags(CODE_INJECTION)

@@ -41,3 +41,3 @@ 'use strict'

const onStart = ({ filters }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store && !store.nosqlAnalyzed && filters?.length) {

@@ -55,3 +55,3 @@ filters.forEach(filter => {

if (store) {
storage.enterWith({ ...store, nosqlAnalyzed: true, nosqlParentStore: store })
storage('legacy').enterWith({ ...store, nosqlAnalyzed: true, nosqlParentStore: store })
}

@@ -61,5 +61,5 @@ }

const onFinish = () => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store?.nosqlParentStore) {
storage.enterWith(store.nosqlParentStore)
storage('legacy').enterWith(store.nosqlParentStore)
}

@@ -80,3 +80,3 @@ }

this.addNotSinkSub('datadog:express-mongo-sanitize:filter:finish', ({ sanitizedProperties, req }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const iastContext = getIastContext(store)

@@ -107,3 +107,3 @@

this.addNotSinkSub('datadog:express-mongo-sanitize:sanitize:finish', ({ sanitizedObject }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const iastContext = getIastContext(store)

@@ -110,0 +110,0 @@

@@ -32,3 +32,3 @@ 'use strict'

this.addSub('apm:fs:operation:start', (obj) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const outOfReqOrChild = !store?.fs?.root

@@ -88,3 +88,3 @@

analyze (value) {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
if (!iastContext) {

@@ -91,0 +91,0 @@ return

@@ -41,7 +41,7 @@ 'use strict'

getStoreAndAnalyze (query, dialect) {
const parentStore = storage.getStore()
const parentStore = storage('legacy').getStore()
if (parentStore) {
this.analyze(query, parentStore, dialect)
storage.enterWith({ ...parentStore, sqlAnalyzed: true, sqlParentStore: parentStore })
storage('legacy').enterWith({ ...parentStore, sqlAnalyzed: true, sqlParentStore: parentStore })
}

@@ -51,5 +51,5 @@ }

returnToParentStore () {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store && store.sqlParentStore) {
storage.enterWith(store.sqlParentStore)
storage('legacy').enterWith(store.sqlParentStore)
}

@@ -64,3 +64,3 @@ }

analyze (value, store, dialect) {
store = store || storage.getStore()
store = store || storage('legacy').getStore()
if (!(store && store.sqlAnalyzed)) {

@@ -67,0 +67,0 @@ super.analyze(value, store, dialect)

@@ -94,3 +94,3 @@ 'use strict'

analyze (value, store = storage.getStore(), meta) {
analyze (value, store = storage('legacy').getStore(), meta) {
const iastContext = getIastContext(store)

@@ -103,3 +103,3 @@ if (this._isInvalidContext(store, iastContext)) return

analyzeAll (...values) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const iastContext = getIastContext(store)

@@ -106,0 +106,0 @@ if (this._isInvalidContext(store, iastContext)) return

@@ -51,3 +51,3 @@ 'use strict'

const store = storage.getStore()
const store = storage('legacy').getStore()
if (store) {

@@ -74,3 +74,3 @@ const topContext = this.getTopContext()

finishContext () {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store) {

@@ -77,0 +77,0 @@ const topContext = this.getTopContext()

@@ -65,3 +65,3 @@ 'use strict'

return () => {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
iastSub.increaseExecuted(iastContext)

@@ -71,3 +71,3 @@ }

_execHandlerAndIncMetric ({ handler, metric, tags, iastContext = getIastContext(storage.getStore()) }) {
_execHandlerAndIncMetric ({ handler, metric, tags, iastContext = getIastContext(storage('legacy').getStore()) }) {
try {

@@ -74,0 +74,0 @@ const result = handler()

@@ -60,3 +60,3 @@ const vulnerabilityReporter = require('./vulnerability-reporter')

if (data?.req) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store) {

@@ -86,3 +86,3 @@ const topContext = web.getContext(data.req)

if (data?.req) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const topContext = web.getContext(data.req)

@@ -89,0 +89,0 @@ const iastContext = iastContextFunctions.getIastContext(store, topContext)

@@ -42,3 +42,3 @@ 'use strict'

const onRequestBody = ({ req }) => {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
if (iastContext && iastContext.body !== req.body) {

@@ -74,3 +74,3 @@ this._taintTrackingHandler(HTTP_REQUEST_BODY, req, 'body', iastContext)

if (req && req.body !== null && typeof req.body === 'object') {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
if (iastContext && iastContext.body !== req.body) {

@@ -120,3 +120,3 @@ this._taintTrackingHandler(HTTP_REQUEST_BODY, req, 'body', iastContext)

(data) => {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
const source = data.context?.source

@@ -134,3 +134,3 @@ const ranges = source && getRanges(iastContext, source)

({ input, base, parsed, isURL }) => {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
let ranges

@@ -164,3 +164,3 @@

const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
if (!iastContext) return

@@ -176,3 +176,3 @@

_taintTrackingHandler (type, target, property, iastContext = getIastContext(storage.getStore())) {
_taintTrackingHandler (type, target, property, iastContext = getIastContext(storage('legacy').getStore())) {
if (!property) {

@@ -186,3 +186,3 @@ taintObject(iastContext, target, type)

_cookiesTaintTrackingHandler (target) {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())
// Prevent tainting cookie names since it leads to taint literal string with same value.

@@ -216,3 +216,3 @@ taintObject(iastContext, target, HTTP_REQUEST_COOKIE_VALUE)

_taintDatabaseResult (result, dbOrigin, iastContext = getIastContext(storage.getStore()), name) {
_taintDatabaseResult (result, dbOrigin, iastContext = getIastContext(storage('legacy').getStore()), name) {
if (!iastContext) return result

@@ -219,0 +219,0 @@

@@ -25,3 +25,3 @@ 'use strict'

taintKafkaMessage (message) {
const iastContext = getIastContext(storage.getStore())
const iastContext = getIastContext(storage('legacy').getStore())

@@ -28,0 +28,0 @@ if (iastContext && message) {

@@ -15,6 +15,3 @@ 'use strict'

const metrics = response.metrics
if (metrics && metrics.instrumentedPropagation) {
INSTRUMENTED_PROPAGATION.inc(undefined, metrics.instrumentedPropagation)
}
incrementTelemetry(response.metrics)

@@ -34,2 +31,14 @@ return response

module.exports = { getRewriteFunction }
function incrementTelemetry (metrics) {
if (metrics?.instrumentedPropagation) {
INSTRUMENTED_PROPAGATION.inc(undefined, metrics.instrumentedPropagation)
}
}
function incrementTelemetryIfNeeded (metrics) {
if (iastTelemetry.verbosity !== Verbosity.OFF) {
incrementTelemetry(metrics)
}
}
module.exports = { getRewriteFunction, incrementTelemetryIfNeeded }
'use strict'
const Module = require('module')
const { pathToFileURL } = require('url')
const { MessageChannel } = require('worker_threads')
const shimmer = require('../../../../../datadog-shimmer')

@@ -8,10 +10,13 @@ const { isPrivateModule, isNotLibraryFile } = require('./filter')

const { getName } = require('../telemetry/verbosity')
const { getRewriteFunction } = require('./rewriter-telemetry')
const { getRewriteFunction, incrementTelemetryIfNeeded } = require('./rewriter-telemetry')
const dc = require('dc-polyfill')
const log = require('../../../log')
const { isMainThread } = require('worker_threads')
const { LOG_MESSAGE, REWRITTEN_MESSAGE } = require('./constants')
const hardcodedSecretCh = dc.channel('datadog:secrets:result')
let rewriter
let getPrepareStackTrace
let getPrepareStackTrace, cacheRewrittenSourceMap
let kSymbolPrepareStackTrace
let esmRewriterEnabled = false

@@ -50,2 +55,3 @@ let getRewriterOriginalPathAndLineFromSourceMap = function (path, line, column) {

kSymbolPrepareStackTrace = iastRewriter.kSymbolPrepareStackTrace
cacheRewrittenSourceMap = iastRewriter.cacheRewrittenSourceMap

@@ -109,2 +115,20 @@ const chainSourceMap = isFlagPresent('--enable-source-maps')

function esmRewritePostProcess (rewritten, filename) {
const { literalsResult, metrics } = rewritten
if (metrics?.status === 'modified') {
if (filename.startsWith('file://')) {
filename = filename.substring(7)
}
cacheRewrittenSourceMap(filename, rewritten.content)
}
incrementTelemetryIfNeeded(metrics)
if (literalsResult && hardcodedSecretCh.hasSubscribers) {
hardcodedSecretCh.publish(literalsResult)
}
}
function enableRewriter (telemetryVerbosity) {

@@ -120,2 +144,4 @@ try {

}
enableEsmRewriter(telemetryVerbosity)
} catch (e) {

@@ -126,2 +152,54 @@ log.error('[ASM] Error enabling TaintTracking Rewriter', e)

function isEsmConfigured () {
const hasLoaderArg = isFlagPresent('--loader') || isFlagPresent('--experimental-loader')
if (hasLoaderArg) return true
const initializeLoaded = Object.keys(require.cache).find(file => file.includes('import-in-the-middle/hook.js'))
return !!initializeLoaded
}
function enableEsmRewriter (telemetryVerbosity) {
if (isMainThread && Module.register && !esmRewriterEnabled && isEsmConfigured()) {
esmRewriterEnabled = true
const { port1, port2 } = new MessageChannel()
port1.on('message', (message) => {
const { type, data } = message
switch (type) {
case LOG_MESSAGE:
log[data.level]?.(...data.messages)
break
case REWRITTEN_MESSAGE:
esmRewritePostProcess(data.rewritten, data.url)
break
}
})
port1.unref()
port2.unref()
const chainSourceMap = isFlagPresent('--enable-source-maps')
const data = {
port: port2,
csiMethods,
telemetryVerbosity,
chainSourceMap
}
try {
Module.register('./rewriter-esm.mjs', {
parentURL: pathToFileURL(__filename),
transferList: [port2],
data
})
} catch (e) {
log.error('[ASM] Error enabling ESM Rewriter', e)
port1.close()
port2.close()
}
}
}
function disableRewriter () {

@@ -128,0 +206,0 @@ shimmer.unwrap(Module.prototype, '_compile')

@@ -42,3 +42,3 @@ 'use strict'

function getContextDefault () {
const store = storage.getStore()
const store = storage('legacy').getStore()
return iastContextFunctions.getIastContext(store)

@@ -45,0 +45,0 @@ }

@@ -94,3 +94,3 @@ 'use strict'

if (!req) {
const store = storage.getStore()
const store = storage('legacy').getStore()
req = store?.req

@@ -190,3 +190,3 @@ }

function onPassportVerify ({ framework, login, user, success, abortController }) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const rootSpan = store?.req && web.root(store.req)

@@ -205,3 +205,3 @@

function onPassportDeserializeUser ({ user, abortController }) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const rootSpan = store?.req && web.root(store.req)

@@ -223,3 +223,3 @@

if (!req) {
const store = storage.getStore()
const store = storage('legacy').getStore()
req = store?.req

@@ -226,0 +226,0 @@ }

@@ -30,3 +30,3 @@ 'use strict'

const store = storage.getStore()
const store = storage('legacy').getStore()
const req = store?.req

@@ -33,0 +33,0 @@ if (!req) return

@@ -17,5 +17,5 @@ 'use strict'

function enterWith (fsProps, store = storage.getStore()) {
function enterWith (fsProps, store = storage('legacy').getStore()) {
if (store && !store.fs?.opExcluded) {
storage.enterWith({
storage('legacy').enterWith({
...store,

@@ -46,3 +46,3 @@ fs: {

_onFsOperationStart () {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store) {

@@ -58,5 +58,5 @@ enterWith({ root: store.fs?.root === undefined }, store)

_onFsOperationFinishOrRenderEnd () {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store?.fs?.parentStore) {
storage.enterWith(store.fs.parentStore)
storage('legacy').enterWith(store.fs.parentStore)
}

@@ -63,0 +63,0 @@ }

@@ -50,3 +50,3 @@ 'use strict'

function analyzeLfi (ctx) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store) return

@@ -53,0 +53,0 @@

@@ -52,3 +52,3 @@ 'use strict'

function analyzeSqlInjection (query, dbSystem, abortController) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store) return

@@ -95,3 +95,3 @@

const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store) return

@@ -98,0 +98,0 @@

@@ -22,3 +22,3 @@ 'use strict'

function analyzeSsrf (ctx) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const req = store?.req

@@ -25,0 +25,0 @@ const outgoingUrl = (ctx.args.options?.uri && format(ctx.args.options.uri)) ?? ctx.args.uri

@@ -105,3 +105,3 @@ 'use strict'

function reportMetrics (metrics, raspRule) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const rootSpan = store?.req && web.root(store.req)

@@ -121,3 +121,3 @@ if (!rootSpan) return

function reportAttack (attackData) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const req = store?.req

@@ -167,3 +167,3 @@ const rootSpan = web.root(req)

const req = storage.getStore()?.req
const req = storage('legacy').getStore()?.req
const rootSpan = web.root(req)

@@ -170,0 +170,0 @@

@@ -37,3 +37,3 @@ 'use strict'

if (!req || !res) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store) {

@@ -40,0 +40,0 @@ req = req || store.req

@@ -51,3 +51,3 @@ 'use strict'

if (!req) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store || !store.req) {

@@ -54,0 +54,0 @@ log.warn('[ASM] Request object not available in waf.run')

@@ -122,2 +122,4 @@ 'use strict'

onHit({ snapshot })
} else {
log.warn('Received a breakpoint hit for an unknown probe')
}

@@ -124,0 +126,0 @@ }).unref()

@@ -96,7 +96,10 @@ 'use strict'

const script = findScriptFromPartialPath(file)
if (!script) throw new Error(`No loaded script found for ${file}`)
if (!script) {
log.error(`No loaded script found for ${file}`)
throw new Error(`No loaded script found for ${file}`)
}
const [path, scriptId, sourceMapURL] = script
log.debug(`Adding breakpoint at ${path}:${line}`)
log.warn(`Adding breakpoint at ${path}:${line}`)

@@ -113,11 +116,15 @@ let lineNumber = line

const { breakpointId } = await session.post('Debugger.setBreakpoint', {
location: {
scriptId,
lineNumber: lineNumber - 1
}
})
try {
const { breakpointId } = await session.post('Debugger.setBreakpoint', {
location: {
scriptId,
lineNumber: lineNumber - 1
}
})
breakpointIdToProbe.set(breakpointId, probe)
probeIdToBreakpointId.set(probe.id, breakpointId)
breakpointIdToProbe.set(breakpointId, probe)
probeIdToBreakpointId.set(probe.id, breakpointId)
} catch (e) {
log.error(`Error setting breakpoint at ${path}:${line}:`, e)
}
}

@@ -124,0 +131,0 @@

@@ -20,3 +20,3 @@ const CiPlugin = require('../../plugins/ci_plugin')

this.unconfiguredAddSub('dd-trace:ci:manual:test:start', ({ testName, testSuite }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const testSuiteRelative = getTestSuitePath(testSuite, this.sourceRoot)

@@ -27,3 +27,3 @@ const testSpan = this.startTestSpan(testName, testSuiteRelative)

this.unconfiguredAddSub('dd-trace:ci:manual:test:finish', ({ status, error }) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const testSpan = store && store.span

@@ -40,3 +40,3 @@ if (testSpan) {

this.unconfiguredAddSub('dd-trace:ci:manual:test:addTags', (tags) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const testSpan = store && store.span

@@ -43,0 +43,0 @@ if (testSpan) {

@@ -521,2 +521,3 @@ 'use strict'

this._setValue(defaults, 'isTestDynamicInstrumentationEnabled', false)
this._setValue(defaults, 'isServiceUserProvided', false)
this._setValue(defaults, 'logInjection', false)

@@ -1160,2 +1161,3 @@ this._setValue(defaults, 'lookup', undefined)

this._setBoolean(calc, 'isTestDynamicInstrumentationEnabled', isTrue(DD_TEST_DYNAMIC_INSTRUMENTATION_ENABLED))
this._setBoolean(calc, 'isServiceUserProvided', !!this._env.service)
}

@@ -1162,0 +1164,0 @@ this._setString(calc, 'dogstatsd.hostname', this._getHostname())

@@ -5,3 +5,3 @@ const { storage } = require('../../datadog-core')

function getDataStreamsContext () {
const store = storage.getStore()
const store = storage('legacy').getStore()
return (store && store.dataStreamsContext) || null

@@ -13,3 +13,3 @@ }

if (dataStreamsContext) storage.enterWith({ ...(storage.getStore()), dataStreamsContext })
if (dataStreamsContext) storage('legacy').enterWith({ ...(storage('legacy').getStore()), dataStreamsContext })
}

@@ -16,0 +16,0 @@

@@ -29,3 +29,3 @@ 'use strict'

_noop (callback) {
return storage.run({ noop: true }, callback)
return storage('legacy').run({ noop: true }, callback)
}

@@ -32,0 +32,0 @@ }

@@ -129,5 +129,5 @@ 'use strict'

const store = storage.getStore()
const store = storage('legacy').getStore()
storage.enterWith({ noop: true })
storage('legacy').enterWith({ noop: true })

@@ -150,3 +150,3 @@ const req = client.request(options, onResponse)

storage.enterWith(store)
storage('legacy').enterWith(store)
}

@@ -153,0 +153,0 @@

@@ -32,3 +32,3 @@ const BaseLLMObsPlugin = require('./base')

}
const span = storage.getStore()?.span
const span = storage('legacy').getStore()?.span
this.setLLMObsTags({ request, span, response, modelProvider, modelName })

@@ -35,0 +35,0 @@ })

@@ -18,7 +18,7 @@ 'use strict'

function withNoop (fn) {
const store = storage.getStore()
const store = storage('legacy').getStore()
storage.enterWith({ noop: true })
storage('legacy').enterWith({ noop: true })
fn()
storage.enterWith(store)
storage('legacy').enterWith(store)
}

@@ -25,0 +25,0 @@

@@ -9,3 +9,3 @@ 'use strict'

constructor (tracer, parent) {
this._store = storage.getHandle()
this._store = storage('legacy').getHandle()
this._noopTracer = tracer

@@ -12,0 +12,0 @@ this._noopContext = this._createContext(parent)

@@ -328,2 +328,3 @@ 'use strict'

if (this._config.tracePropagationExtractFirst) {
this._extractBaggageItems(carrier, context)
return context

@@ -348,6 +349,3 @@ }

if (this._hasPropagationStyle('extract', 'baggage') && carrier.baggage) {
context = context || new DatadogSpanContext()
this._extractBaggageItems(carrier, context)
}
this._extractBaggageItems(carrier, context)

@@ -601,2 +599,5 @@ return context || this._extractSqsdContext(carrier)

_extractBaggageItems (carrier, spanContext) {
if (!this._hasPropagationStyle('extract', 'baggage')) return
if (!carrier || !carrier.baggage) return
if (!spanContext) return
const baggages = carrier.baggage.split(',')

@@ -603,0 +604,0 @@ for (const keyValue of baggages) {

@@ -68,3 +68,3 @@ 'use strict'

this._prioritySampler = prioritySampler
this._store = storage.getHandle()
this._store = storage('legacy').getHandle()
this._duration = undefined

@@ -71,0 +71,0 @@

@@ -146,2 +146,3 @@ 'use strict'

isTestDynamicInstrumentationEnabled,
isServiceUserProvided,
middlewareTracingEnabled

@@ -159,3 +160,4 @@ } = this._tracerConfig

ciVisAgentlessLogSubmissionEnabled,
isTestDynamicInstrumentationEnabled
isTestDynamicInstrumentationEnabled,
isServiceUserProvided
}

@@ -162,0 +164,0 @@

@@ -10,3 +10,3 @@ const TracingPlugin = require('./tracing')

bindStart (ctx) {
const store = storage.getStore()
const store = storage('legacy').getStore()
const childOf = store ? store.span : null

@@ -13,0 +13,0 @@

@@ -48,2 +48,3 @@ const {

this.fileLineToProbeId = new Map()
this.rootDir = process.cwd() // fallback in case :session:start events are not emitted

@@ -339,3 +340,18 @@

removeDiProbe (probeId) {
removeAllDiProbes () {
if (this.fileLineToProbeId.size === 0) {
return Promise.resolve()
}
log.debug('Removing all Dynamic Instrumentation probes')
return Promise.all(Array.from(this.fileLineToProbeId.keys())
.map((fileLine) => {
const [file, line] = fileLine.split(':')
return this.removeDiProbe({ file, line })
}))
}
removeDiProbe ({ file, line }) {
const probeId = this.fileLineToProbeId.get(`${file}:${line}`)
log.warn(`Removing probe from ${file}:${line}, with id: ${probeId}`)
this.fileLineToProbeId.delete(probeId)
return this.di.removeProbe(probeId)

@@ -351,5 +367,23 @@ }

}
log.debug('Adding breakpoint for Dynamic Instrumentation')
this.testErrorStackIndex = stackIndex
const activeProbeKey = `${file}:${line}`
if (this.fileLineToProbeId.has(activeProbeKey)) {
log.warn('Probe already set for this line')
const oldProbeId = this.fileLineToProbeId.get(activeProbeKey)
return {
probeId: oldProbeId,
setProbePromise: Promise.resolve(),
stackIndex,
file,
line
}
}
const [probeId, setProbePromise] = this.di.addLineProbe({ file, line }, this.onDiBreakpointHit.bind(this))
this.fileLineToProbeId.set(activeProbeKey, probeId)
return {

@@ -356,0 +390,0 @@ probeId,

@@ -43,3 +43,3 @@ 'use strict'

this.addSub(`apm:${this.constructor.id}:log`, (arg) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
const span = store && store.span

@@ -46,0 +46,0 @@

@@ -13,3 +13,3 @@ 'use strict'

this._handler = (message, name) => {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (!store || !store.noop) {

@@ -34,3 +34,3 @@ handler(message, name)

this._transform = data => {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -44,7 +44,7 @@ return !store || !store.noop

enable () {
this._channel.bindStore(storage, this._transform)
this._channel.bindStore(storage('legacy'), this._transform)
}
disable () {
this._channel.unbindStore(storage, this._transform)
this._channel.unbindStore(storage('legacy'))
}

@@ -68,4 +68,4 @@ }

enter (span, store) {
store = store || storage.getStore()
storage.enterWith({ ...store, span })
store = store || storage('legacy').getStore()
storage('legacy').enterWith({ ...store, span })
}

@@ -76,3 +76,3 @@

skip () {
storage.enterWith({ noop: true })
storage('legacy').enterWith({ noop: true })
}

@@ -99,3 +99,3 @@

addError (error) {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -102,0 +102,0 @@ if (!store || !store.span) return

@@ -19,3 +19,3 @@ 'use strict'

get activeSpan () {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -106,3 +106,3 @@ return store && store.span

startSpan (name, { childOf, kind, meta, metrics, service, resource, type } = {}, enter = true) {
const store = storage.getStore()
const store = storage('legacy').getStore()
if (store && childOf === undefined) {

@@ -131,3 +131,3 @@ childOf = store.span

if (enter) {
storage.enterWith({ ...store, span })
storage('legacy').enterWith({ ...store, span })
}

@@ -134,0 +134,0 @@

@@ -40,4 +40,4 @@ const cp = require('child_process')

) {
const store = storage.getStore()
storage.enterWith({ noop: true })
const store = storage('legacy').getStore()
storage('legacy').enterWith({ noop: true })

@@ -68,3 +68,3 @@ let startTime

} finally {
storage.enterWith(store)
storage('legacy').enterWith(store)
}

@@ -71,0 +71,0 @@ }

@@ -111,2 +111,4 @@ const path = require('path')

const DD_TEST_IS_USER_PROVIDED_SERVICE = '_dd.test.is_user_provided_service'
// Dynamic instrumentation - Test optimization integration tags

@@ -203,3 +205,4 @@ const DI_ERROR_DEBUG_INFO_CAPTURED = 'error.debug_info_captured'

DI_DEBUG_ERROR_LINE_SUFFIX,
getFormattedError
getFormattedError,
DD_TEST_IS_USER_PROVIDED_SERVICE
}

@@ -280,2 +283,3 @@

[TEST_FRAMEWORK]: testFramework,
[DD_TEST_IS_USER_PROVIDED_SERVICE]: (config && config.isServiceUserProvided) ? 'true' : 'false',
...gitMetadata,

@@ -282,0 +286,0 @@ ...ciMetadata,

@@ -43,4 +43,4 @@ 'use strict'

const store = storage.getStore()
storage.enterWith({ noop: true })
const store = storage('legacy').getStore()
storage('legacy').enterWith({ noop: true })
requestCounter.inc()

@@ -69,3 +69,3 @@ const start = perf.now()

}
storage.enterWith(store)
storage('legacy').enterWith(store)
}

@@ -72,0 +72,0 @@

@@ -28,3 +28,3 @@ 'use strict'

function getActiveSpan () {
const store = storage.getStore()
const store = storage('legacy').getStore()
return store && store.span

@@ -31,0 +31,0 @@ }

@@ -11,3 +11,3 @@ 'use strict'

active () {
const store = storage.getStore()
const store = storage('legacy').getStore()

@@ -20,6 +20,6 @@ return (store && store.span) || null

const oldStore = storage.getStore()
const newStore = span ? storage.getStore(span._store) : oldStore
const oldStore = storage('legacy').getStore()
const newStore = span ? storage('legacy').getStore(span._store) : oldStore
storage.enterWith({ ...newStore, span })
storage('legacy').enterWith({ ...newStore, span })

@@ -35,3 +35,3 @@ try {

} finally {
storage.enterWith(oldStore)
storage('legacy').enterWith(oldStore)
}

@@ -38,0 +38,0 @@ }

@@ -6,3 +6,2 @@ 'use strict'

const Scope = require('./scope')
const { storage } = require('../../datadog-core')
const { isError } = require('./util')

@@ -13,3 +12,2 @@ const { setStartupLogConfig } = require('./startup-log')

const { DsmPathwayCodec } = require('./datastreams/pathway')
const { DD_MAJOR } = require('../../../version')
const DataStreamsContext = require('./data_streams_context')

@@ -65,6 +63,2 @@ const { DataStreamsCheckpointer } = require('./data_streams')

if (!options.childOf && options.orphanable === false && DD_MAJOR < 4) {
return fn(null, () => {})
}
const span = this.startSpan(name, options)

@@ -112,6 +106,2 @@

return function () {
const store = storage.getStore()
if (store && store.noop) return fn.apply(this, arguments)
let optionsObj = options

@@ -122,6 +112,2 @@ if (typeof optionsObj === 'function' && typeof fn === 'function') {

if (optionsObj && optionsObj.orphanable === false && !tracer.scope().active() && DD_MAJOR < 4) {
return fn.apply(this, arguments)
}
const lastArgId = arguments.length - 1

@@ -128,0 +114,0 @@ const cb = arguments[lastArgId]

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc