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

telemetry: make count logic faster #5013

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/dd-trace/src/telemetry/logs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function onErrorLog (msg) {

const telLog = {
level: 'ERROR',
count: 1,

// existing log.error(err) without message will be reported as 'Generic Error'
message: message ?? 'Generic Error'
Expand Down
15 changes: 1 addition & 14 deletions packages/dd-trace/src/telemetry/logs/log-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const logCollector = {
}
const hash = createHash(logEntry)
if (!logs.has(hash)) {
logs.set(hash, errorCopy(logEntry))
logs.set(hash, logEntry)
return true
} else {
logs.get(hash).count++
Expand Down Expand Up @@ -122,19 +122,6 @@ const logCollector = {
}
}

// clone an Error object to later serialize and transmit
// { ...error } doesn't work
// also users can add arbitrary fields to an error
function errorCopy (error) {
const keys = Object.getOwnPropertyNames(error)
const obj = {}
for (const key of keys) {
obj[key] = error[key]
}
obj.count = 1
return obj
}

logCollector.reset()

module.exports = logCollector
6 changes: 2 additions & 4 deletions packages/dd-trace/test/telemetry/logs/log-collector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ describe('telemetry log collector', () => {
})

it('duplicated errors should send incremented count values', () => {
const err1 = new Error('oh no')
err1.level = 'ERROR'
const err1 = { message: 'oh no', level: 'ERROR', count: 1 }

const err2 = new Error('foo buzz')
err2.level = 'ERROR'
const err2 = { message: 'foo buzz', level: 'ERROR', count: 1 }

logCollector.add(err1)
logCollector.add(err2)
Expand Down
Loading