Skip to content

Commit

Permalink
rename class and some fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Jun 15, 2023
1 parent f73e9eb commit f864ec6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions packages/dd-trace/src/external-logger/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ const tracerLogger = require('../../log')// path to require tracer logger

const https = require('https')

class V2LogWriter {
class ExternalLogger {
// Note: these attribute names match the corresponding entry in the JSON payload.
constructor ({ ddsource, hostname, service, apiKey, site = 'datadoghq.com', interval = 10000, timeout = 2000, limit = 1000 }) {
this.ddsource = ddsource
this.hostname = hostname
this.service = service
this.interval = interval
this.timeout = timeout
this.buffer = []
this.bufferLimit = limit
this.queue = []
this.limit = limit
this.endpoint = '/api/v2/logs'
this.site = site
this.intake = `http-intake.logs.${this.site}`
Expand All @@ -36,7 +36,7 @@ class V2LogWriter {

// Parses and enqueues a log
log (log, span, tags) {
const logTags = V2LogWriter.tagString(tags)
const logTags = ExternalLogger.tagString(tags)

if (span) {
log['dd.trace_id'] = String(span.trace_id)
Expand All @@ -57,10 +57,10 @@ class V2LogWriter {

// Enqueues a raw, non-formatted log object
enqueue (log) {
if (this.buffer.length >= this.bufferLimit) {
if (this.queue.length >= this.limit) {
this.flush()
}
this.buffer.push(log)
this.queue.push(log)
}

shutdown () {
Expand All @@ -74,14 +74,14 @@ class V2LogWriter {
let numLogs
let encodedLogs

if (!this.buffer.length) {
if (!this.queue.length) {
cb()
return
}

try {
logs = this.buffer
this.buffer = []
logs = this.queue
this.queue = []

numLogs = logs.length
encodedLogs = JSON.stringify(logs)
Expand Down Expand Up @@ -118,4 +118,4 @@ class V2LogWriter {
}
}

module.exports = V2LogWriter
module.exports = ExternalLogger
16 changes: 8 additions & 8 deletions packages/dd-trace/src/external-logger/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const tracerLogger = require('../../log')

describe('External Logger', () => {
let externalLogger
let V2LogWriter
let ExternalLogger
let interceptor
let errorLog

beforeEach(() => {
errorLog = sinon.spy(tracerLogger, 'error')

V2LogWriter = proxyquire('../src', {
ExternalLogger = proxyquire('../src', {
'../../log': {
error: errorLog
}
})

externalLogger = new V2LogWriter({
externalLogger = new ExternalLogger({
ddsource: 'logging_from_space',
hostname: 'mac_desktop',
apiKey: 'API_KEY_PLACEHOLDER',
Expand Down Expand Up @@ -87,16 +87,16 @@ describe('External Logger', () => {
})
})

it('should empty the buffer when calling flush', (done) => {
it('should empty the log queue when calling flush', (done) => {
interceptor = nock('https://http-intake.logs.datadoghq.com:443')
.post('/api/v2/logs')
.reply(202, {})

externalLogger.enqueue({})
expect(externalLogger.buffer.length).to.equal(1)
expect(externalLogger.queue.length).to.equal(1)

externalLogger.flush((err) => {
expect(externalLogger.buffer.length).to.equal(0)
expect(externalLogger.queue.length).to.equal(0)
done(err)
})
})
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('External Logger', () => {
})
})

it('causes a flush when exceeding buffer limit', (done) => {
it('causes a flush when exceeding log queue limit', (done) => {
const flusher = sinon.stub(externalLogger, 'flush')

for (let i = 0; i < 10; i++) {
Expand All @@ -140,7 +140,7 @@ describe('External Logger', () => {
expect(flusher).to.not.have.been.called

externalLogger.enqueue({})
expect(flusher).to.have.been.calledOnce
expect(flusher).to.have.been.called

flusher.restore()
done()
Expand Down

0 comments on commit f864ec6

Please sign in to comment.