Socket
Socket
Sign inDemoInstall

dd-trace

Package Overview
Dependencies
Maintainers
3
Versions
579
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dd-trace - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

src/plugins/mysql.js

2

lib/version.js

@@ -1,1 +0,1 @@

module.exports = '0.1.6'
module.exports = '0.1.7'
{
"name": "dd-trace",
"version": "0.1.6",
"version": "0.1.7",
"description": "Datadog APM tracing client for JavaScript (experimental)",

@@ -67,2 +67,3 @@ "main": "index.js",

"mocha": "^5.0.0",
"mysql": "^2.15.0",
"nock": "^9.1.6",

@@ -72,2 +73,3 @@ "nyc": "^11.4.1",

"proxyquire": "^1.8.0",
"redis": "^2.8.0",
"retry": "^0.10.1",

@@ -74,0 +76,0 @@ "sinon": "^4.2.1",

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

this._url = config.url
this._env = config.env
this._tags = config.tags
this._recorder = new Recorder(config.url, config.flushInterval, config.bufferSize)

@@ -33,6 +35,12 @@ this._recorder.init()

_startSpan (name, fields) {
const tags = {}
if (this._env) {
tags.env = this._env
}
return new Span(this, {
operationName: fields.operationName || name,
parent: getParent(fields.references),
tags: fields.tags,
tags: Object.assign(tags, this._tags, fields.tags),
startTime: fields.startTime

@@ -39,0 +47,0 @@ })

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

context.run(() => {
context.set('express.paths', paths)
layer.handle = context.bind(layer.handle)
})
context.set('express.paths', paths)

@@ -90,3 +87,21 @@ break

function createWrapRouterMethod () {
function createWrapRouterHandle (tracer, config) {
const context = tracer._context
return function wrapRouterHandle (handle) {
return function handleWithTrace (req, res, out) {
let returnValue
context.run(() => {
returnValue = handle.call(this, req, res, context.bind(out))
})
return returnValue
}
}
}
function createWrapRouterMethod (tracer) {
const context = tracer._context
return function wrapRouterMethod (original) {

@@ -99,2 +114,8 @@ return function methodWithTrace (fn) {

this.stack.slice(offset).forEach(layer => {
const handle = layer.handle_request
layer.handle_request = (req, res, next) => {
return handle.call(layer, req, res, context.bind(next))
}
layer._datadog_matchers = matchers

@@ -130,2 +151,3 @@ })

shimmer.wrap(express.Router, 'process_params', createWrapProcessParams(tracer, config))
shimmer.wrap(express.Router, 'handle', createWrapRouterHandle(tracer, config))
shimmer.wrap(express.Router, 'use', createWrapRouterMethod(tracer, config))

@@ -138,2 +160,3 @@ shimmer.wrap(express.Router, 'route', createWrapRouterMethod(tracer, config))

shimmer.unwrap(express.Router, 'process_params')
shimmer.unwrap(express.Router, 'handle')
shimmer.unwrap(express.Router, 'use')

@@ -140,0 +163,0 @@ shimmer.unwrap(express.Router, 'route')

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

bufferSize: 1000,
logger: 'logger'
logger: 'logger',
tags: {}
}

@@ -164,2 +165,38 @@

})
it('should merge default tracer tags with span tags', () => {
config.tags = {
'foo': 'tracer',
'bar': 'tracer'
}
fields.tags = {
'bar': 'span',
'baz': 'span'
}
tracer = new Tracer(config)
tracer.startSpan('name', fields)
expect(Span).to.have.been.calledWithMatch(tracer, {
tags: {
'foo': 'tracer',
'bar': 'span',
'baz': 'span'
}
})
})
it('should add the env tag from the env option', () => {
config.env = 'test'
tracer = new Tracer(config)
tracer.startSpan('name', fields)
expect(Span).to.have.been.calledWithMatch(tracer, {
tags: {
'env': 'test'
}
})
})
})

@@ -166,0 +203,0 @@

@@ -38,14 +38,15 @@ 'use strict'

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test')
expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', '/user')
expect(traces[0][0].meta).to.have.property('span.kind', 'server')
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', 'test')
expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', '/user')
expect(traces[0][0].meta).to.have.property('span.kind', 'server')
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,14 +71,15 @@ axios

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test')
expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0].meta).to.have.property('span.kind', 'server')
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/app/user/1`)
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', 'test')
expect(traces[0][0]).to.have.property('type', 'web')
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
expect(traces[0][0].meta).to.have.property('span.kind', 'server')
expect(traces[0][0].meta).to.have.property('http.url', `http://localhost:${port}/app/user/1`)
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', () => {

@@ -102,8 +104,9 @@ axios

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app(/^\\/user\\/(\\d)$/)')
agent
.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app(/^\\/user\\/(\\d)$/)')
})
.then(done)
.catch(done)
done()
})
appListener = app.listen(port, 'localhost', () => {

@@ -121,3 +124,3 @@ axios

router.get([['/user/:id'], '/users/:id'], (req, res) => {
router.get([['/user/:id'], '/users/:id'], (req, res, next) => {
res.status(200).send()

@@ -129,8 +132,35 @@ })

getPort().then(port => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
agent
.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
})
.then(done)
.catch(done)
done()
appListener = app.listen(port, 'localhost', () => {
axios
.get(`http://localhost:${port}/app/user/1`)
.catch(done)
})
})
})
it('should support asynchronous routers', done => {
const app = express()
const router = express.Router()
router.get('/user/:id', (req, res) => {
setTimeout(() => res.status(200).send())
})
app.use('/app', router)
getPort().then(port => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
})
.then(done)
.catch(done)
appListener = app.listen(port, 'localhost', () => {

@@ -144,2 +174,29 @@ axios

it('should support asynchronous middlewares', done => {
const app = express()
const router = express.Router()
router.use((req, res, next) => setTimeout(() => next()))
router.get('/user/:id', (req, res) => {
res.status(200).send()
})
app.use('/app', router)
getPort().then(port => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('resource', '/app/user/:id')
})
.then(done)
.catch(done)
appListener = app.listen(port, 'localhost', () => {
axios
.get(`http://localhost:${port}/app/user/1`)
.catch(done)
})
})
})
it('should fallback to the default resource name if a path pattern could not be found', done => {

@@ -151,8 +208,9 @@ const app = express()

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

@@ -195,3 +253,2 @@ axios

app.get('/user', (req, res) => {
expect(agent.currentSpan().context().baggageItems).to.have.property('foo', 'bar')
res.status(200).send()

@@ -204,5 +261,5 @@ })

expect(traces[0][0].parent_id.toString()).to.equal('5678')
done()
})
.then(done)
.catch(done)

@@ -243,8 +300,9 @@ appListener = app.listen(port, 'localhost', () => {

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', () => {

@@ -251,0 +309,0 @@ axios

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

const pg = require('pg')
const mysql = require('mysql')
const redis = require('redis')
const platform = require('../src/platform')

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

factor: 1,
minTimeout: 1000,
maxTimeout: 1000,
minTimeout: 3000,
maxTimeout: 3000,
randomize: false

@@ -40,3 +42,5 @@ }

return Promise.all([
waitForPostgres()
waitForPostgres(),
waitForMysql(),
waitForRedis()
])

@@ -76,1 +80,39 @@ }

}
function waitForMysql () {
return new Promise((resolve, reject) => {
const connection = mysql.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
connection.connect()
connection.query('SELECT 1 + 1 AS solution', (error, results, fields) => {
if (error) throw error
})
connection.end(() => resolve())
})
}
function waitForRedis () {
return new Promise((resolve, reject) => {
const client = redis.createClient({
retry_strategy: function (options) {
if (options.attempt > retryOptions.retries) {
return reject(options.error)
}
return retryOptions.maxTimeout
}
})
client.on('connect', () => {
client.quit()
resolve()
})
})
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc