dd-trace
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -1,1 +0,1 @@ | ||
module.exports = '0.7.0' | ||
module.exports = '0.7.1' |
{ | ||
"name": "dd-trace", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "Datadog APM tracing client for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,2 +17,3 @@ 'use strict' | ||
this._tracer = tracer | ||
this._enabled = false | ||
this._names = new Set() | ||
@@ -59,2 +60,4 @@ this._plugins = new Map() | ||
reload () { | ||
if (!this._enabled) return | ||
const instrumentations = Array.from(this._plugins.keys()) | ||
@@ -133,2 +136,6 @@ .reduce((prev, current) => prev.concat(current), []) | ||
enable () { | ||
this._enabled = true | ||
} | ||
_set (plugin, meta) { | ||
@@ -135,0 +142,0 @@ this._plugins.set(plugin, Object.assign({ config: {} }, meta)) |
@@ -40,3 +40,3 @@ 'use strict' | ||
next.call(this, wrapCallback(tracer, span, cb)) | ||
next.call(this, wrapCallback(tracer, span, cb, this)) | ||
} | ||
@@ -61,3 +61,9 @@ } | ||
if (topology.s && topology.s.options) { | ||
addHost(span, topology) | ||
} | ||
function addHost (span, topology) { | ||
const options = topology && topology.s && topology.s.options | ||
if (options && options.host && options.port) { | ||
span.addTags({ | ||
@@ -70,3 +76,3 @@ 'out.host': topology.s.options.host, | ||
function wrapCallback (tracer, span, done) { | ||
function wrapCallback (tracer, span, done, cursor) { | ||
return (err, res) => { | ||
@@ -81,2 +87,6 @@ if (err) { | ||
if (cursor) { | ||
addHost(span, cursor.server) | ||
} | ||
span.finish() | ||
@@ -111,8 +121,8 @@ | ||
if (!isObject(input) || Buffer.isBuffer(input) || isBSON(input)) return '?' | ||
for (const key in input) { | ||
if (isObject(input[key]) && !Buffer.isBuffer(input[key])) { | ||
output[key] = sanitize(input[key]) | ||
} else { | ||
output[key] = '?' | ||
} | ||
if (typeof input[key] === 'function') continue | ||
output[key] = sanitize(input[key]) | ||
} | ||
@@ -127,2 +137,6 @@ | ||
function isBSON (val) { | ||
return val && val._bsontype | ||
} | ||
module.exports = [ | ||
@@ -129,0 +143,0 @@ { |
'use strict' | ||
const METHODS = require('methods').concat('all') | ||
const pathToRegExp = require('path-to-regexp') | ||
@@ -39,31 +40,40 @@ const web = require('./util/web') | ||
function createWrapRouterMethod (tracer) { | ||
return function wrapRouterMethod (original) { | ||
return function methodWithTrace (fn) { | ||
const offset = this.stack.length | ||
const router = original.apply(this, arguments) | ||
const matchers = extractMatchers(fn) | ||
function wrapRouterMethod (original) { | ||
return function methodWithTrace (fn) { | ||
const offset = this.stack ? [].concat(this.stack).length : 0 | ||
const router = original.apply(this, arguments) | ||
this.stack.slice(offset).forEach(layer => { | ||
const handle = layer.handle | ||
if (this.stack) { | ||
wrapStack(this.stack, offset, extractMatchers(fn)) | ||
} | ||
if (handle.length === 4) { | ||
layer.handle = (error, req, res, next) => { | ||
return handle.call(layer, error, req, res, wrapNext(tracer, layer, req, next)) | ||
} | ||
} else { | ||
layer.handle = (req, res, next) => { | ||
return handle.call(layer, req, res, wrapNext(tracer, layer, req, next)) | ||
} | ||
} | ||
return router | ||
} | ||
} | ||
layer._datadog_matchers = matchers | ||
}) | ||
function wrapStack (stack, offset, matchers) { | ||
[].concat(stack).slice(offset).forEach(layer => { | ||
const handle = layer.handle || layer | ||
return router | ||
if (handle.length === 4) { | ||
layer.handle = (error, req, res, next) => { | ||
return handle.call(layer, error, req, res, wrapNext(layer, req, next)) | ||
} | ||
} else { | ||
layer.handle = (req, res, next) => { | ||
return handle.call(layer, req, res, wrapNext(layer, req, next)) | ||
} | ||
} | ||
} | ||
layer._datadog_matchers = matchers | ||
if (layer.route) { | ||
METHODS.forEach(method => { | ||
layer.route[method] = wrapRouterMethod(layer.route[method]) | ||
}) | ||
} | ||
}) | ||
} | ||
function wrapNext (tracer, layer, req, next) { | ||
function wrapNext (layer, req, next) { | ||
if (!web.active(req)) { | ||
@@ -119,4 +129,4 @@ return next | ||
this.wrap(Router.prototype, 'process_params', createWrapProcessParams(tracer, config)) | ||
this.wrap(Router.prototype, 'use', createWrapRouterMethod(tracer, config)) | ||
this.wrap(Router.prototype, 'route', createWrapRouterMethod(tracer, config)) | ||
this.wrap(Router.prototype, 'use', wrapRouterMethod) | ||
this.wrap(Router.prototype, 'route', wrapRouterMethod) | ||
}, | ||
@@ -123,0 +133,0 @@ unpatch (Router) { |
@@ -60,2 +60,3 @@ 'use strict' | ||
this._tracer = new DatadogTracer(config) | ||
this._instrumenter.enable() | ||
this._instrumenter.patch(config) | ||
@@ -62,0 +63,0 @@ } |
129143
3671
9