Skip to content

Commit

Permalink
Merge branch 'master' into igor/fix-mongoose-8.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua authored Feb 10, 2025
2 parents eeb57c6 + 66c13fc commit 2f2479e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/datadog-plugin-mongoose/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('Plugin', () => {
describe('mongoose', () => {
withVersions('mongoose', ['mongoose'], (version) => {
const specificVersion = require(`../../../versions/mongoose@${version}`).version()
if (NODE_MAJOR === 14 && semver.satisfies(specificVersion, '>=8')) return
if ((NODE_MAJOR === 14 && semver.satisfies(specificVersion, '>=8')) ||
semver.satisfies(specificVersion, '>=8.10.0')) return

let mongoose

Expand Down
9 changes: 5 additions & 4 deletions packages/dd-trace/src/opentracing/propagation/text_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class TextMapPropagator {
if (context === null) {
context = extractedContext
if (this._config.tracePropagationExtractFirst) {
this._extractBaggageItems(carrier, context)
return context
}
} else {
Expand All @@ -344,10 +345,7 @@ class TextMapPropagator {
}
}

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

return context || this._extractSqsdContext(carrier)
}
Expand Down Expand Up @@ -596,6 +594,9 @@ class TextMapPropagator {
}

_extractBaggageItems (carrier, spanContext) {
if (!this._hasPropagationStyle('extract', 'baggage')) return
if (!carrier || !carrier.baggage) return
if (!spanContext) return
const baggages = carrier.baggage.split(',')
for (const keyValue of baggages) {
if (!keyValue.includes('=')) {
Expand Down
36 changes: 26 additions & 10 deletions packages/dd-trace/test/appsec/iast/taint-tracking/rewriter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ describe('IAST Rewriter', () => {
'@datadog/native-iast-rewriter': {
Rewriter,
getPrepareStackTrace: function (fn) {
const testWrap = function testWrappedPrepareStackTrace (_, callsites) {
return fn(_, callsites)
const testWrap = function testWrappedPrepareStackTrace (error, callsites) {
if (typeof fn !== 'function') {
return error.stack
}

return fn?.(error, callsites)
}

Object.defineProperty(testWrap, kSymbolPrepareStackTrace, {
value: true
})
Expand Down Expand Up @@ -219,6 +224,21 @@ describe('IAST Rewriter', () => {
describe('thread communication', () => {
let port

function waitUntilCheckSuccess (check, maxMs = 500) {
setTimeout(() => {
try {
check()
} catch (e) {
if (maxMs > 0) {
waitUntilCheckSuccess(check, maxMs - 10)
return
}

throw e
}
}, 10)
}

beforeEach(() => {
process.execArgv = ['--loader', 'dd-trace/initialize.mjs']
rewriter.enableRewriter()
Expand All @@ -237,7 +257,7 @@ describe('IAST Rewriter', () => {

port.postMessage({ type: constants.REWRITTEN_MESSAGE, data })

setTimeout(() => {
waitUntilCheckSuccess(() => {
expect(cacheRewrittenSourceMap).to.be.calledOnceWith('file.js', content)

done()
Expand All @@ -257,7 +277,7 @@ describe('IAST Rewriter', () => {

port.postMessage({ type: constants.REWRITTEN_MESSAGE, data })

setTimeout(() => {
waitUntilCheckSuccess(() => {
expect(rewriterTelemetry.incrementTelemetryIfNeeded).to.be.calledOnceWith(metrics)

done()
Expand All @@ -281,16 +301,13 @@ describe('IAST Rewriter', () => {
function onHardcodedSecret (literals) {
expect(literals).to.deep.equal(literalsResult)

hardcodedSecretCh.unsubscribe(onHardcodedSecret)
done()
}

hardcodedSecretCh.subscribe(onHardcodedSecret)

port.postMessage({ type: constants.REWRITTEN_MESSAGE, data })

setTimeout(() => {
hardcodedSecretCh.unsubscribe(onHardcodedSecret)
})
})

it('should log the message', (done) => {
Expand All @@ -302,9 +319,8 @@ describe('IAST Rewriter', () => {

port.postMessage({ type: constants.LOG_MESSAGE, data })

setTimeout(() => {
waitUntilCheckSuccess(() => {
expect(log.error).to.be.calledOnceWith(...messages)

done()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ describe('TextMapPropagator', () => {
expect(spanContextD._baggageItems).to.deep.equal({})
})

it('should extract baggage when it is the only propagation style', () => {
// temporary test. On the contrary, it SHOULD extract baggage
it('should not extract baggage when it is the only propagation style', () => {
config = new Config({
tracePropagationStyle: {
extract: ['baggage']
Expand All @@ -462,7 +463,7 @@ describe('TextMapPropagator', () => {
baggage: 'foo=bar'
}
const spanContext = propagator.extract(carrier)
expect(spanContext._baggageItems).to.deep.equal({ foo: 'bar' })
expect(spanContext).to.be.null
})

it('should convert signed IDs to unsigned', () => {
Expand Down

0 comments on commit 2f2479e

Please sign in to comment.