Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5.42.1 proposal #5431

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dd-trace",
"version": "5.42.0",
"version": "5.42.1",
"description": "Datadog APM tracing client for JavaScript",
"main": "index.js",
"typings": "index.d.ts",
23 changes: 19 additions & 4 deletions packages/datadog-instrumentations/src/vitest.js
Original file line number Diff line number Diff line change
@@ -94,6 +94,10 @@ function isReporterPackageNewest (vitestPackage) {
return vitestPackage.h?.name === 'BaseSequencer'
}

function isBaseSequencer (vitestPackage) {
return vitestPackage.b?.name === 'BaseSequencer'
}

function getChannelPromise (channelToPublishTo) {
return new Promise(resolve => {
sessionAsyncResource.runInAsyncScope(() => {
@@ -615,11 +619,22 @@ addHook({

addHook({
name: 'vitest',
versions: ['>=3.0.0'],
versions: ['>=3.0.9'],
filePattern: 'dist/chunks/coverage.*'
}, (coveragePackage) => {
if (isBaseSequencer(coveragePackage)) {
shimmer.wrap(coveragePackage.b.prototype, 'sort', getSortWrapper)
}
return coveragePackage
})

addHook({
name: 'vitest',
versions: ['>=3.0.0 <3.0.9'],
filePattern: 'dist/chunks/resolveConfig.*'
}, (randomSequencerPackage) => {
shimmer.wrap(randomSequencerPackage.B.prototype, 'sort', getSortWrapper)
return randomSequencerPackage
}, (resolveConfigPackage) => {
shimmer.wrap(resolveConfigPackage.B.prototype, 'sort', getSortWrapper)
return resolveConfigPackage
})

// Can't specify file because compiled vitest includes hashes in their files
6 changes: 3 additions & 3 deletions packages/dd-trace/src/dogstatsd.js
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ class MetricsAggregationClient {
this._histograms[name].get(tag).record(value)
}

count (name, count, tag, monotonic = false) {
count (name, count, tag, monotonic = true) {
if (typeof tag === 'boolean') {
monotonic = tag
tag = undefined
@@ -254,8 +254,8 @@ class MetricsAggregationClient {
this._gauges[name].set(tag, value)
}

increment (name, count = 1, tag, monotonic) {
this.count(name, count, tag, monotonic)
increment (name, count = 1, tag) {
this.count(name, count, tag)
}

decrement (name, count = 1, tag) {
6 changes: 3 additions & 3 deletions packages/dd-trace/src/llmobs/sdk.js
Original file line number Diff line number Diff line change
@@ -105,12 +105,12 @@ class LLMObs extends NoopLLMObs {

if (fn.length > 1) {
return this._tracer.trace(name, spanOptions, (span, cb) =>
this._activate(span, { kind, options: llmobsOptions }, () => fn(span, cb))
this._activate(span, { kind, ...llmobsOptions }, () => fn(span, cb))
)
}

return this._tracer.trace(name, spanOptions, span =>
this._activate(span, { kind, options: llmobsOptions }, () => fn(span))
this._activate(span, { kind, ...llmobsOptions }, () => fn(span))
)
}

@@ -166,7 +166,7 @@ class LLMObs extends NoopLLMObs {
}

try {
const result = llmobs._activate(span, { kind, options: llmobsOptions }, () => fn.apply(this, fnArgs))
const result = llmobs._activate(span, { kind, ...llmobsOptions }, () => fn.apply(this, fnArgs))

if (result && typeof result.then === 'function') {
return result.then(
27 changes: 13 additions & 14 deletions packages/dd-trace/src/runtime_metrics/runtime_metrics.js
Original file line number Diff line number Diff line change
@@ -111,11 +111,11 @@ const runtimeMetrics = module.exports = {
},

increment (name, tag, monotonic) {
client && client.increment(name, 1, tag, monotonic)
this.count(name, 1, tag, monotonic)
},

decrement (name, tag) {
client && client.decrement(name, 1, tag)
this.count(name, -1, tag)
}
}

@@ -211,7 +211,7 @@ function captureGCMetrics () {
histogram('runtime.node.gc.pause', pauseAll)

for (const type in pause) {
histogram('runtime.node.gc.pause.by.type', pause[type], [`gc_type:${type}`])
histogram('runtime.node.gc.pause.by.type', pause[type], `gc_type:${type}`)
}

gcProfiler.start()
@@ -265,7 +265,7 @@ function captureNativeMetrics () {
if (type === 'all') {
histogram('runtime.node.gc.pause', stats.gc[type])
} else {
histogram('runtime.node.gc.pause.by.type', stats.gc[type], [`gc_type:${type}`])
histogram('runtime.node.gc.pause.by.type', stats.gc[type], `gc_type:${type}`)
}
})

@@ -279,16 +279,15 @@ function captureNativeMetrics () {
}
}

function histogram (name, stats, tags) {
tags = tags ? [].concat(tags) : []

if (tags.length > 0) {
for (const tag of tags) {
client.histogram(name, stats, tag)
}
} else {
client.histogram(name, stats)
}
function histogram (name, stats, tag) {
client.gauge(`${name}.min`, stats.min, tag)
client.gauge(`${name}.max`, stats.max, tag)
client.increment(`${name}.sum`, stats.sum, tag)
client.increment(`${name}.total`, stats.sum, tag)
client.gauge(`${name}.avg`, stats.avg, tag)
client.increment(`${name}.count`, stats.count, tag)
client.gauge(`${name}.median`, stats.median, tag)
client.gauge(`${name}.95percentile`, stats.p95, tag)
}

function startGCObserver () {
2 changes: 1 addition & 1 deletion packages/dd-trace/test/custom-metrics.spec.js
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ describe('Custom Metrics', () => {
if (stdout) console.log(stdout)
if (stderr) console.error(stderr)

expect(metricsData.split('#')[0]).to.equal('page.views.data:1|g|')
expect(metricsData.split('#')[0]).to.equal('page.views.data:1|c|')

done()
})
8 changes: 4 additions & 4 deletions packages/dd-trace/test/dogstatsd.spec.js
Original file line number Diff line number Diff line change
@@ -382,7 +382,7 @@ describe('dogstatsd', () => {
client.flush()

expect(udp4.send).to.have.been.called
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:20|g\n')
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:20|c\n')
})

it('.increment() with default', () => {
@@ -393,7 +393,7 @@ describe('dogstatsd', () => {
client.flush()

expect(udp4.send).to.have.been.called
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:2|g\n')
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:2|c\n')
})

it('.decrement()', () => {
@@ -404,7 +404,7 @@ describe('dogstatsd', () => {
client.flush()

expect(udp4.send).to.have.been.called
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:-20|g\n')
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:-20|c\n')
})

it('.decrement() with default', () => {
@@ -415,7 +415,7 @@ describe('dogstatsd', () => {
client.flush()

expect(udp4.send).to.have.been.called
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:-2|g\n')
expect(udp4.send.firstCall.args[0].toString()).to.equal('test.count:-2|c\n')
})

it('.distribution()', () => {
49 changes: 49 additions & 0 deletions packages/dd-trace/test/llmobs/sdk/index.spec.js
Original file line number Diff line number Diff line change
@@ -327,6 +327,29 @@ describe('sdk', () => {
})
})
})

it('passes the options to the tagger correctly', () => {
let span
llmobs.trace({
kind: 'workflow',
name: 'test',
mlApp: 'override',
sessionId: 'sessionId',
modelName: 'modelName',
modelProvider: 'modelProvider'
}, (_span) => {
span = _span
})

expect(LLMObsTagger.tagMap.get(span)).to.deep.equal({
'_ml_obs.meta.span.kind': 'workflow',
'_ml_obs.meta.ml_app': 'override',
'_ml_obs.meta.model_name': 'modelName',
'_ml_obs.meta.model_provider': 'modelProvider',
'_ml_obs.session_id': 'sessionId',
'_ml_obs.llmobs_parent_id': 'undefined'
})
})
})

describe('wrap', () => {
@@ -745,6 +768,32 @@ describe('sdk', () => {
wrappedOuter()
})
})

it('passes the options to the tagger correctly', () => {
let span

const fn = llmobs.wrap({
kind: 'workflow',
name: 'test',
mlApp: 'override',
sessionId: 'sessionId',
modelName: 'modelName',
modelProvider: 'modelProvider'
}, () => {
span = llmobs._active()
})

fn()

expect(LLMObsTagger.tagMap.get(span)).to.deep.equal({
'_ml_obs.meta.span.kind': 'workflow',
'_ml_obs.meta.ml_app': 'override',
'_ml_obs.meta.model_name': 'modelName',
'_ml_obs.meta.model_provider': 'modelProvider',
'_ml_obs.session_id': 'sessionId',
'_ml_obs.llmobs_parent_id': 'undefined'
})
})
})
})

44 changes: 22 additions & 22 deletions packages/dd-trace/test/runtime_metrics.spec.js
Original file line number Diff line number Diff line change
@@ -218,31 +218,31 @@ suiteDescribe('runtimeMetrics', () => {
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.malloced_memory')
expect(client.gauge).to.have.been.calledWith('runtime.node.heap.peak_malloced_memory')

expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.min')
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.count')
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.max', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.min', sinon.match.number)
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.sum', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.avg', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.median', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.delay.95percentile', sinon.match.number)
expect(client.increment).to.have.been.calledWith('runtime.node.event_loop.delay.count', sinon.match.number)

expect(client.gauge).to.have.been.calledWith('runtime.node.event_loop.utilization')

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.min')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.count')

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.max')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.min')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.sum')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.avg')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.median')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.95percentile')
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.count')
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.max', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.min', sinon.match.number)
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.sum', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.avg', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.median', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.95percentile', sinon.match.number)
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.count', sinon.match.number)

expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.max', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.min', sinon.match.number)
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.sum', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.avg', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.median', sinon.match.number)
expect(client.gauge).to.have.been.calledWith('runtime.node.gc.pause.by.type.95percentile', sinon.match.number)
expect(client.increment).to.have.been.calledWith('runtime.node.gc.pause.by.type.count', sinon.match.number)
expect(client.increment).to.have.been.calledWith(
'runtime.node.gc.pause.by.type.count', sinon.match.any, sinon.match(val => {
return val && /^gc_type:[a-z_]+$/.test(val[0])