Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix format
  • Loading branch information
sydney-tung committed Aug 20, 2025
commit a9f35030a8598edd5e7d2f91349620cbe901c743
1 change: 0 additions & 1 deletion packages/dd-trace/src/guardrails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function guard (fn) {
if (!clobberBailout && (!initBailout || forced)) {
// Ensure the instrumentation source is set for the current process and potential child processes.
var result = fn()

telemetry('complete', ['injection_forced:' + (forced && initBailout ? 'true' : 'false')], {
result: 'success',
result_class: initBailout ? 'success_forced' : 'success',
Expand Down
10 changes: 7 additions & 3 deletions packages/dd-trace/src/guardrails/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@
if (typeof name === 'string') {
points = [{ name: name, tags: tags || [] }]
}

var currentMetadata = metadata
if (resultMetadata) {
currentMetadata = Object.assign({}, metadata, resultMetadata)
for (var key in metadata) {
currentMetadata[key] = metadata[key]
}
for (var key in resultMetadata) {

Check failure on line 60 in packages/dd-trace/src/guardrails/telemetry.js

View workflow job for this annotation

GitHub Actions / lint

'key' is already defined
currentMetadata[key] = resultMetadata[key]
}
}
if (['1', 'true', 'True'].indexOf(process.env.DD_INJECT_FORCE) !== -1) {
points = points.filter(function (p) { return ['error', 'complete'].indexOf(p.name) !== -1 })
Expand All @@ -74,7 +78,7 @@
log.error('Failed to spawn telemetry forwarder')
})
proc.on('exit', function (code) {
if (code != 0) {
if (code !== 0) {
log.error('Telemetry forwarder exited with code', code)
}
})
Expand Down
42 changes: 0 additions & 42 deletions packages/dd-trace/test/guardrails/telemetry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,4 @@ describe('sendTelemetry', () => {
assertTelemetryPoints(process.pid, msgs, ['abort.integration', '1'])
})
})

describe('Error scenarios and metadata', () => {
let mockProc, telemetryModule, capturedStdinData

function createMockProcess () {
const proc = new EventEmitter()
proc.stdin = new EventEmitter()
proc.stdin.end = (data) => {
capturedStdinData = data
}
return proc
}

function loadTelemetryModuleWithMockProc () {
return proxyquire('../src/guardrails/telemetry', {
child_process: { spawn: () => mockProc }
})
}

function runTelemetry (eventType, value) {
const originalStringify = JSON.stringify
JSON.stringify = function (obj) {
if (obj && obj.metadata && obj.points) {
if (eventType === 'spawn-error') {
mockProc.emit('error', new Error(value))
} else if (eventType === 'exit') {
mockProc.emit('exit', value)
} else if (eventType === 'stdin-error') {
mockProc.stdin.emit('error', new Error(value))
}
}
return originalStringify.apply(this, arguments)
}

try {
telemetryModule([{ name: 'test', tags: [] }])
} finally {
JSON.stringify = originalStringify
}
}

})
})
Loading