Socket
Socket
Sign inDemoInstall

dd-trace

Package Overview
Dependencies
18
Maintainers
3
Versions
558
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1-beta.2 to 0.2.1

6

benchmark/index.js

@@ -8,3 +8,3 @@ 'use strict'

const semver = require('semver')
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const platform = require('../src/platform')

@@ -68,4 +68,4 @@ const node = require('../src/platform/node')

spanContext = new DatadogSpanContext({
traceId: new Uint64BE(0x12345678, 0x12345678),
spanId: new Uint64BE(0x12345678, 0x12345678),
traceId: new Int64BE(0x12345678, 0x12345678),
spanId: new Int64BE(0x12345678, 0x12345678),
baggageItems: { foo: 'bar' }

@@ -72,0 +72,0 @@ })

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const id = new Uint64BE(0x12345678, 0x12345678)
const Int64BE = require('int64-buffer').Int64BE
const id = new Int64BE(0x12345678, 0x12345678)

@@ -6,0 +6,0 @@ const span = {

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const trace = [
{
trace_id: new Uint64BE(0x12345678, 0x9abcdef0),
span_id: new Uint64BE(0x12345678, 0x12345678),
trace_id: new Int64BE(0x12345678, 0x9abcdef0),
span_id: new Int64BE(0x12345678, 0x12345678),
parent_id: null,

@@ -20,5 +20,5 @@ name: 'root',

{
trace_id: new Uint64BE(0x12345678, 0x9abcdef0),
span_id: new Uint64BE(0x9abcdef0, 0x9abcdef0),
parent_id: new Uint64BE(0x12345678, 0x12345678),
trace_id: new Int64BE(0x12345678, 0x9abcdef0),
span_id: new Int64BE(0x9abcdef0, 0x9abcdef0),
parent_id: new Int64BE(0x12345678, 0x12345678),
name: 'child',

@@ -25,0 +25,0 @@ resource: '/',

@@ -96,3 +96,3 @@ <h1 id="home">Datadog JavaScript Tracer API</h1>

Each integration can be configured individually. See below for more information for every integration.
Each integration also has its own list of default tags. These tags get automatically added to the span created by the integration.

@@ -99,0 +99,0 @@ <h3 id="express">express</h3>

{
"name": "dd-trace",
"version": "0.2.1-beta.2",
"version": "0.2.1",
"description": "Datadog APM tracing client for JavaScript (experimental)",

@@ -5,0 +5,0 @@ "main": "index.js",

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE

@@ -32,4 +32,4 @@ const map = {

meta: {},
start: new Uint64BE(Math.round(span._startTime * 1e6)),
duration: new Uint64BE(Math.round(span._duration * 1e6))
start: new Int64BE(Math.round(span._startTime * 1e6)),
duration: new Int64BE(Math.round(span._duration * 1e6))
}

@@ -36,0 +36,0 @@ }

@@ -81,3 +81,3 @@ 'use strict'

function loadIntegrations () {
const integrations = requireDir('./plugins')
const integrations = requireDir(path.join(__dirname, './plugins'))

@@ -84,0 +84,0 @@ return Object.keys(integrations)

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const DatadogSpanContext = require('../span_context')

@@ -37,4 +37,4 @@

return new DatadogSpanContext({
traceId: new Uint64BE(carrier[traceKey], 10),
spanId: new Uint64BE(carrier[spanKey], 10),
traceId: new Int64BE(carrier[traceKey], 10),
spanId: new Int64BE(carrier[spanKey], 10),
baggageItems

@@ -41,0 +41,0 @@ })

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const randomBytes = require('crypto').randomBytes
module.exports = () => new Uint64BE(randomBytes(8))
module.exports = () => new Int64BE(randomBytes(8))

@@ -32,3 +32,3 @@ 'use strict'

if (paths) {
span.setTag('resource.name', paths.join(''))
span.setTag('resource.name', `${req.method} ${paths.join('')}`)
}

@@ -35,0 +35,0 @@

@@ -23,3 +23,4 @@ 'use strict'

let req
let span
let isFinish = false

@@ -32,4 +33,4 @@ tracer.trace('http.request', {

}
}, span => {
let isFinish = false
}, child => {
span = child

@@ -46,30 +47,30 @@ options = typeof options === 'string' ? url.parse(uri) : Object.assign({}, options)

tracer.inject(span, FORMAT_HTTP_HEADERS, options.headers)
})
function finish () {
if (!isFinish) {
isFinish = true
span.finish()
}
}
const req = request.call(this, options, res => {
span.setTag(Tags.HTTP_STATUS_CODE, res.statusCode)
res.on('end', finish)
callback && callback(res)
})
req = request.call(this, options, res => {
span.setTag(Tags.HTTP_STATUS_CODE, res.statusCode)
res.on('end', finish)
callback && callback(res)
})
req.on('socket', socket => {
socket.on('close', finish)
})
req.on('socket', socket => {
socket.on('close', finish)
req.on('error', err => {
span.addTags({
'error.type': err.name,
'error.msg': err.message,
'error.stack': err.stack
})
req.on('error', err => {
span.addTags({
'error.type': err.name,
'error.msg': err.message,
'error.stack': err.stack
})
span.finish()
})
function finish () {
if (!isFinish) {
isFinish = true
span.finish()
})
})
}
}

@@ -76,0 +77,0 @@ return req

@@ -193,5 +193,6 @@ 'use strict'

let result
let span
tracer.trace('mongodb.query', span => {
tracer.trace('mongodb.query', child => {
span = child
span.addTags({

@@ -205,11 +206,9 @@ 'service.name': config.service || 'mongodb',

})
if (typeof options === 'function') {
result = operation.call(this, ns, ops, wrapCallback(tracer, span, options))
} else {
result = operation.call(this, ns, ops, options, wrapCallback(tracer, span, callback))
}
})
return result
if (typeof options === 'function') {
return operation.call(this, ns, ops, wrapCallback(tracer, span, options))
} else {
return operation.call(this, ns, ops, options, wrapCallback(tracer, span, callback))
}
}

@@ -224,3 +223,6 @@ }

tracer.trace('mongodb.query', span => {
let span
tracer.trace('mongodb.query', child => {
span = child
span.addTags({

@@ -235,5 +237,5 @@ 'service.name': config.service || 'mongodb',

})
})
next.call(this, wrapCallback(tracer, span, cb))
})
next.call(this, wrapCallback(tracer, span, cb))
}

@@ -240,0 +242,0 @@ }

@@ -9,3 +9,3 @@ 'use strict'

return function queryWithTrace (sql, values, cb) {
let sequence
let span

@@ -17,27 +17,29 @@ tracer.trace('mysql.query', {

}
}, span => {
sequence = query.call(this, sql, values, cb)
}, child => {
span = child
})
span.setTag('service.name', config.service || 'mysql')
span.setTag('resource.name', sequence.sql)
span.setTag('out.host', this.config.host)
span.setTag('out.port', String(this.config.port))
span.setTag('span.type', 'db')
span.setTag('db.user', this.config.user)
const sequence = query.call(this, sql, values, cb)
if (this.config.database) {
span.setTag('db.name', this.config.database)
}
span.setTag('service.name', config.service || 'mysql')
span.setTag('resource.name', sequence.sql)
span.setTag('out.host', this.config.host)
span.setTag('out.port', String(this.config.port))
span.setTag('span.type', 'db')
span.setTag('db.user', this.config.user)
tracer.bindEmitter(sequence)
if (this.config.database) {
span.setTag('db.name', this.config.database)
}
if (sequence._callback) {
sequence._callback = wrapCallback(tracer, span, sequence._callback)
} else {
sequence.on('end', () => {
span.finish()
})
}
})
tracer.bindEmitter(sequence)
if (sequence._callback) {
sequence._callback = wrapCallback(tracer, span, sequence._callback)
} else {
sequence.on('end', () => {
span.finish()
})
}
return sequence

@@ -44,0 +46,0 @@ }

@@ -9,3 +9,3 @@ 'use strict'

return function queryWithTrace (sql, values, cb) {
let sequence
let span

@@ -17,27 +17,29 @@ tracer.trace('mysql.query', {

}
}, span => {
sequence = query.call(this, sql, values, cb)
}, child => {
span = child
})
span.setTag('service.name', config.service || 'mysql')
span.setTag('resource.name', sequence.sql)
span.setTag('out.host', this.config.host)
span.setTag('out.port', String(this.config.port))
span.setTag('span.type', 'db')
span.setTag('db.user', this.config.user)
const sequence = query.call(this, sql, values, cb)
if (this.config.database) {
span.setTag('db.name', this.config.database)
}
span.setTag('service.name', config.service || 'mysql')
span.setTag('resource.name', sequence.sql)
span.setTag('out.host', this.config.host)
span.setTag('out.port', String(this.config.port))
span.setTag('span.type', 'db')
span.setTag('db.user', this.config.user)
tracer.bindEmitter(sequence)
if (this.config.database) {
span.setTag('db.name', this.config.database)
}
if (sequence.onResult) {
sequence.onResult = wrapCallback(tracer, span, sequence.onResult)
} else {
sequence.on('end', () => {
span.finish()
})
}
})
tracer.bindEmitter(sequence)
if (sequence.onResult) {
sequence.onResult = wrapCallback(tracer, span, sequence.onResult)
} else {
sequence.on('end', () => {
span.finish()
})
}
return sequence

@@ -44,0 +46,0 @@ }

@@ -40,7 +40,7 @@ 'use strict'

span.finish()
})
if (originalCallback) {
originalCallback(err, res)
}
})
if (originalCallback) {
originalCallback(err, res)
}
}

@@ -47,0 +47,0 @@

@@ -28,2 +28,4 @@ 'use strict'

return function internalSendCommandWithTrace (options) {
let span
tracer.trace(`redis.command`, {

@@ -34,3 +36,4 @@ tags: {

}
}, span => {
}, child => {
span = child
span.addTags({

@@ -44,6 +47,6 @@ 'service.name': config.service || 'redis',

})
options.callback = wrapCallback(tracer, span, options.callback)
})
options.callback = wrapCallback(tracer, span, options.callback)
return internalSendCommand.call(this, options)

@@ -50,0 +53,0 @@ }

@@ -30,3 +30,3 @@ 'use strict'

log.debug(() => `Adding encoded trace to buffer: ${buffer}`)
log.debug(() => `Adding encoded trace to buffer: ${buffer.inspect()}`)

@@ -33,0 +33,0 @@ if (this.length < this._size) {

@@ -6,3 +6,3 @@ 'use strict'

const getPort = require('get-port')
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const msgpack = require('msgpack-lite')

@@ -47,5 +47,5 @@ const codec = msgpack.createCodec({ int64: true })

expect(payload[0][0].trace_id).to.be.instanceof(Uint64BE)
expect(payload[0][0].trace_id).to.be.instanceof(Int64BE)
expect(payload[0][0].trace_id.toString()).to.equal(span.context().traceId.toString())
expect(payload[0][0].span_id).to.be.instanceof(Uint64BE)
expect(payload[0][0].span_id).to.be.instanceof(Int64BE)
expect(payload[0][0].span_id.toString()).to.equal(span.context().spanId.toString())

@@ -55,4 +55,4 @@ expect(payload[0][0].service).to.equal('test')

expect(payload[0][0].resource).to.equal('/hello/:name')
expect(payload[0][0].start).to.be.instanceof(Uint64BE)
expect(payload[0][0].duration).to.be.instanceof(Uint64BE)
expect(payload[0][0].start).to.be.instanceof(Int64BE)
expect(payload[0][0].duration).to.be.instanceof(Int64BE)

@@ -59,0 +59,0 @@ res.status(200).send('OK')

@@ -5,3 +5,3 @@ 'use strict'

const codec = msgpack.createCodec({ int64: true })
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE

@@ -17,3 +17,3 @@ describe('encode', () => {

const data = [{
id: new Uint64BE(0x12345678, 0x12345678),
id: new Int64BE(0x12345678, 0x12345678),
name: 'test'

@@ -20,0 +20,0 @@ }]

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const id = new Uint64BE(0x12345678, 0x12345678)
const Int64BE = require('int64-buffer').Int64BE
const id = new Int64BE(0x12345678, 0x12345678)

@@ -46,5 +46,5 @@ describe('format', () => {

expect(trace.error).to.equal(0)
expect(trace.start).to.be.instanceof(Uint64BE)
expect(trace.start).to.be.instanceof(Int64BE)
expect(trace.start.toNumber()).to.equal(span._startTime * 1e6)
expect(trace.duration).to.be.instanceof(Uint64BE)
expect(trace.duration).to.be.instanceof(Int64BE)
expect(trace.duration.toNumber()).to.equal(span._duration * 1e6)

@@ -113,6 +113,6 @@ })

expect(trace.meta['foo.bar']).to.equal('null')
expect(trace.start).to.be.instanceof(Uint64BE)
expect(trace.duration).to.be.instanceof(Uint64BE)
expect(trace.start).to.be.instanceof(Int64BE)
expect(trace.duration).to.be.instanceof(Int64BE)
})
})
})

@@ -68,3 +68,3 @@ 'use strict'

requireDir = sinon.stub()
requireDir.withArgs('./plugins').returns(integrations)
requireDir.withArgs(path.join(__dirname, '../src/plugins')).returns(integrations)

@@ -71,0 +71,0 @@ Instrumenter = proxyquire('../src/instrumenter', {

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const SpanContext = require('../../../src/opentracing/span_context')

@@ -19,4 +19,4 @@

const spanContext = new SpanContext({
traceId: new Uint64BE(0, 123),
spanId: new Uint64BE(0, 456)
traceId: new Int64BE(0, 123),
spanId: new Int64BE(0, 456)
})

@@ -23,0 +23,0 @@

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE
const SpanContext = require('../../../src/opentracing/span_context')

@@ -29,4 +29,4 @@

const spanContext = new SpanContext({
traceId: new Uint64BE(0, 123),
spanId: new Uint64BE(0, 456),
traceId: new Int64BE(0, 123),
spanId: new Int64BE(0, 456),
baggageItems

@@ -43,4 +43,4 @@ })

const spanContext = new SpanContext({
traceId: new Uint64BE(0, 123),
spanId: new Uint64BE(0, 456),
traceId: new Int64BE(0, 123),
spanId: new Int64BE(0, 456),
baggageItems: {

@@ -69,4 +69,4 @@ number: 1.23,

expect(spanContext).to.deep.equal(new SpanContext({
traceId: new Uint64BE(0, 123),
spanId: new Uint64BE(0, 456),
traceId: new Int64BE(0, 123),
spanId: new Int64BE(0, 456),
baggageItems

@@ -73,0 +73,0 @@ }))

'use strict'
const Uint64BE = require('int64-buffer').Uint64BE
const Int64BE = require('int64-buffer').Int64BE

@@ -13,4 +13,4 @@ describe('Span', () => {

platform = { id: sinon.stub() }
platform.id.onFirstCall().returns(new Uint64BE(123, 123))
platform.id.onSecondCall().returns(new Uint64BE(456, 456))
platform.id.onFirstCall().returns(new Int64BE(123, 123))
platform.id.onSecondCall().returns(new Int64BE(456, 456))

@@ -30,4 +30,4 @@ tracer = {

expect(span.context().traceId).to.deep.equal(new Uint64BE(123, 123))
expect(span.context().spanId).to.deep.equal(new Uint64BE(123, 123))
expect(span.context().traceId).to.deep.equal(new Int64BE(123, 123))
expect(span.context().spanId).to.deep.equal(new Int64BE(123, 123))
})

@@ -43,4 +43,4 @@

const parent = {
traceId: new Uint64BE(123, 123),
spanId: new Uint64BE(456, 456),
traceId: new Int64BE(123, 123),
spanId: new Int64BE(456, 456),
sampled: false,

@@ -56,4 +56,4 @@ baggageItems: { foo: 'bar' },

expect(span.context().traceId).to.deep.equal(new Uint64BE(123, 123))
expect(span.context().parentId).to.deep.equal(new Uint64BE(456, 456))
expect(span.context().traceId).to.deep.equal(new Int64BE(123, 123))
expect(span.context().parentId).to.deep.equal(new Int64BE(456, 456))
expect(span.context().baggageItems).to.deep.equal({ foo: 'bar' })

@@ -60,0 +60,0 @@ expect(span.context().trace.started).to.deep.equal(['span', span])

@@ -14,2 +14,3 @@ 'use strict'

let handlers = []
let skip = []

@@ -29,3 +30,6 @@ module.exports = {

if (handlers[0]) {
if (skip[0]) {
skip[0].resolve()
skip.shift()
} else if (handlers[0]) {
handlers[0](req.body)

@@ -74,2 +78,15 @@ handlers.shift()

skip (count) {
for (let i = 0; i < count; i++) {
const defer = {}
defer.promise = new Promise((resolve, reject) => {
defer.resolve = resolve
defer.reject = reject
})
skip.push(defer)
}
},
currentSpan () {

@@ -80,8 +97,17 @@ return tracer.currentSpan()

close () {
listener.close()
listener = null
agent = null
handlers = []
delete require.cache[require.resolve('../..')]
const timeout = setTimeout(() => {
skip.forEach(defer => defer.resolve())
}, 1000)
return Promise.all(skip.map(defer => defer.promise))
.then(() => {
clearTimeout(timeout)
listener.close()
listener = null
agent = null
handlers = []
skip = []
delete require.cache[require.resolve('../..')]
})
}
}

@@ -42,3 +42,3 @@ 'use strict'

expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', '/user')
expect(traces[0][0]).to.have.property('resource', 'GET /user')
expect(traces[0][0].meta).to.have.property('span.kind', 'server')

@@ -75,3 +75,3 @@ expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)

expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0]).to.have.property('resource', 'GET /app/user/:id')
expect(traces[0][0].meta).to.have.property('span.kind', 'server')

@@ -106,3 +106,3 @@ expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/app/user/1`)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app(/^\\/user\\/(\\d)$/)')
expect(traces[0][0]).to.have.property('resource', 'GET /app(/^\\/user\\/(\\d)$/)')
})

@@ -133,3 +133,3 @@ .then(done)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0]).to.have.property('resource', 'GET /app/user/:id')
})

@@ -166,3 +166,3 @@ .then(done)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/foo/bar')
expect(traces[0][0]).to.have.property('resource', 'GET /foo/bar')
})

@@ -193,3 +193,3 @@ .then(done)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0]).to.have.property('resource', 'GET /app/user/:id')
})

@@ -221,3 +221,3 @@ .then(done)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0]).to.have.property('resource', 'GET /app/user/:id')
})

@@ -296,3 +296,3 @@ .then(done)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/user')
expect(traces[0][0]).to.have.property('resource', 'GET /user')
})

@@ -384,3 +384,3 @@ .then(done)

.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0]).to.have.property('resource', 'GET /app/user/:id')
})

@@ -387,0 +387,0 @@ .then(done)

@@ -11,2 +11,3 @@ 'use strict'

let appListener
let context

@@ -18,7 +19,8 @@ describe('http', () => {

http = require('http')
context = require('../../src/platform').context({ experimental: {} })
})
afterEach(() => {
agent.close()
appListener.close()
return agent.close()
})

@@ -39,14 +41,15 @@

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('service', 'http-client')
expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', 'GET')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
expect(traces[0][0].meta).to.have.property('http.method', 'GET')
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'http-client')
expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', 'GET')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
expect(traces[0][0].meta).to.have.property('http.method', 'GET')
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
})
.then(done)
.catch(done)
done()
})
appListener = app.listen(port, 'localhost', () => {

@@ -70,8 +73,9 @@ const req = http.request(`http://localhost:${port}/user`, res => {

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.not.be.undefined
agent
.use(traces => {
expect(traces[0][0]).to.not.be.undefined
})
.then(done)
.catch(done)
done()
})
appListener = app.listen(port, 'localhost', () => {

@@ -89,8 +93,9 @@ const req = http.get(`http://localhost:${port}/user`, res => {

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
agent
.use(traces => {
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/user`)
})
.then(done)
.catch(done)
done()
})
const uri = {

@@ -110,8 +115,9 @@ hostname: 'localhost',

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/`)
agent
.use(traces => {
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/`)
})
.then(done)
.catch(done)
done()
})
const req = http.request({

@@ -133,8 +139,9 @@ port

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.not.be.undefined
agent
.use(traces => {
expect(traces[0][0]).to.not.be.undefined
})
.then(done)
.catch(done)
done()
})
appListener = app.listen(port, 'localhost', () => {

@@ -159,10 +166,30 @@ const req = http.request(`http://localhost:${port}/user`)

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
agent
.use(traces => {
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
})
.then(done)
.catch(done)
done()
appListener = app.listen(port, 'localhost', () => {
const req = http.request(`http://localhost:${port}/user`)
req.end()
})
})
})
it('should run the callback in the parent context', done => {
const app = express()
app.get('/user', (req, res) => {
res.status(200).send('OK')
})
getPort().then(port => {
appListener = app.listen(port, 'localhost', () => {
const req = http.request(`http://localhost:${port}/user`)
const req = http.request(`http://localhost:${port}/user`, res => {
expect(context.get('current')).to.be.undefined
done()
})

@@ -174,12 +201,35 @@ req.end()

it('should handle errors', done => {
it('should run the event listeners in the parent context', done => {
const app = express()
app.get('/user', (req, res) => {
res.status(200).send('OK')
})
getPort().then(port => {
agent.use(traces => {
expect(traces[0][0].meta).to.have.property('error.type', 'Error')
expect(traces[0][0].meta).to.have.property('error.msg', `connect ECONNREFUSED 127.0.0.1:${port}`)
expect(traces[0][0].meta).to.have.property('error.stack')
appListener = app.listen(port, 'localhost', () => {
const req = http.request(`http://localhost:${port}/user`, res => {
res.on('data', () => {})
res.on('end', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
done()
req.end()
})
})
})
it('should handle errors', done => {
getPort().then(port => {
agent
.use(traces => {
expect(traces[0][0].meta).to.have.property('error.type', 'Error')
expect(traces[0][0].meta).to.have.property('error.msg', `connect ECONNREFUSED 127.0.0.1:${port}`)
expect(traces[0][0].meta).to.have.property('error.stack')
})
.then(done)
.catch(done)
const req = http.request(`http://localhost:${port}/user`)

@@ -211,8 +261,9 @@

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('service', 'custom')
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'custom')
})
.then(done)
.catch(done)
done()
})
appListener = app.listen(port, 'localhost', () => {

@@ -219,0 +270,0 @@ const req = http.request(`http://localhost:${port}/user`, res => {

@@ -164,2 +164,9 @@ 'use strict'

it('should run the callback in the parent context', done => {
server.insert(`test.${collection}`, [{ a: 1 }], {}, () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should handle errors', done => {

@@ -278,2 +285,14 @@ let error

it('should run the callback in the parent context', done => {
const cursor = server.cursor(`test.${collection}`, {
find: `test.${collection}`,
query: { a: 1 }
})
cursor.next(() => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should handle errors', done => {

@@ -280,0 +299,0 @@ let error

@@ -53,2 +53,9 @@ 'use strict'

it('should run the callback in the parent context', done => {
connection.query('SELECT 1 + 1 AS solution', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should propagate context to events', done => {

@@ -69,2 +76,11 @@ let query

it('should run event listeners in the parent context', done => {
const query = connection.query('SELECT 1 + 1 AS solution')
query.on('result', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should do automatic instrumentation', done => {

@@ -193,4 +209,11 @@ agent.use(traces => {

})
it('should run the callback in the parent context', done => {
pool.query('SELECT 1 + 1 AS solution', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
})
})
})

@@ -53,2 +53,9 @@ 'use strict'

it('should run the callback in the parent context', done => {
connection.query('SELECT 1 + 1 AS solution', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should propagate context to events', done => {

@@ -69,2 +76,11 @@ let query

it('should run event listeners in the parent context', done => {
const query = connection.query('SELECT 1 + 1 AS solution')
query.on('result', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should do automatic instrumentation', done => {

@@ -199,4 +215,11 @@ agent

})
it('should run the callback in the parent context', done => {
pool.query('SELECT 1 + 1 AS solution', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
})
})
})

@@ -8,2 +8,4 @@ 'use strict'

let pg
let client
let context

@@ -14,2 +16,3 @@ describe('pg', () => {

plugin = proxyquire('../src/plugins/pg', { 'pg': pg })
context = require('../../src/platform').context({ experimental: { asyncHooks: false } })
})

@@ -22,4 +25,15 @@

describe('without configuration', () => {
beforeEach(() => {
return agent.load(plugin, 'pg')
beforeEach(done => {
agent.load(plugin, 'pg')
.then(() => {
client = new pg.Client({
user: 'postgres',
password: 'postgres',
database: 'postgres',
application_name: 'test'
})
client.connect(err => done(err))
})
.catch(done)
})

@@ -40,18 +54,7 @@

const client = new pg.Client({
user: 'postgres',
password: 'postgres',
database: 'postgres',
application_name: 'test'
})
client.connect((err) => {
client.query('SELECT $1::text as message', ['Hello world!'], (err, result) => {
if (err) throw err
client.query('SELECT $1::text as message', ['Hello world!'], (err, result) => {
client.end((err) => {
if (err) throw err
client.end((err) => {
if (err) throw err
})
})

@@ -70,18 +73,19 @@ })

const client = new pg.Client({
user: 'postgres',
password: 'postgres',
database: 'postgres'
client.query('INVALID', (err, result) => {
expect(err).to.be.an('error')
client.end((err) => {
if (err) throw err
})
})
})
client.connect((err) => {
it('should run the callback in the parent context', done => {
client.query('SELECT $1::text as message', ['Hello World!'], () => {
expect(context.get('current')).to.be.undefined
done()
})
client.end((err) => {
if (err) throw err
client.query('INVALID', (err, result) => {
expect(err).to.be.an('error')
client.end((err) => {
if (err) throw err
})
})
})

@@ -95,15 +99,5 @@ })

const client = new pg.Client({
user: 'postgres',
password: 'postgres',
database: 'postgres'
})
client.connect((err) => {
client.query('SELECT $1::text as message', ['Hello World!'])
client.end((err) => {
if (err) throw err
client.query('SELECT $1::text as message', ['Hello World!'])
client.end((err) => {
if (err) throw err
})
})

@@ -116,3 +110,3 @@ })

beforeEach(() => {
beforeEach(done => {
config = {

@@ -122,3 +116,13 @@ service: 'custom'

return agent.load(plugin, 'pg', config)
agent.load(plugin, 'pg', config)
.then(() => {
client = new pg.Client({
user: 'postgres',
password: 'postgres',
database: 'postgres'
})
client.connect(err => done(err))
})
.catch(done)
})

@@ -133,17 +137,7 @@

const client = new pg.Client({
user: 'postgres',
password: 'postgres',
database: 'postgres'
})
client.connect((err) => {
client.query('SELECT $1::text as message', ['Hello world!'], (err, result) => {
if (err) throw err
client.query('SELECT $1::text as message', ['Hello world!'], (err, result) => {
client.end((err) => {
if (err) throw err
client.end((err) => {
if (err) throw err
})
})

@@ -150,0 +144,0 @@ })

@@ -65,2 +65,11 @@ 'use strict'

it('should run the callback in the parent context', done => {
client.on('error', done)
client.get('foo', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should propagate context to client emitters', done => {

@@ -80,2 +89,11 @@ client.on('error', done)

it('should run client emitter listeners in the parent context', done => {
client.on('error', done)
client.on('ready', () => {
expect(context.get('current')).to.be.undefined
done()
})
})
it('should propagate context to stream emitters', done => {

@@ -97,2 +115,13 @@ client.on('error', done)

it('should run stream emitter listeners in the parent context', done => {
client.on('error', done)
client.stream.on('close', () => {
expect(context.get('current')).to.be.undefined
done()
})
client.stream.destroy()
})
it('should handle errors', done => {

@@ -99,0 +128,0 @@ let error

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc