Socket
Socket
Sign inDemoInstall

dd-trace

Package Overview
Dependencies
19
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 to 0.3.0

scripts/helpers/color.js

6

benchmark/index.js

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

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

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

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

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

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

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

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

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

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

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

@@ -75,2 +75,8 @@ <h1 id="home">Datadog JavaScript Tracer API</h1>

The following tags are available to override Datadog specific options:
* `service.name`: The service name to be used for this span. The service name from the tracer will be used if this is not provided.
* `resource.name`: The resource name to be used for this span. The operation name will be used if this is not provided.
* `span.type`: The span type to be used for this span. Will fallback to `custom` if not provided.
**NOTE: When using OpenTracing, context propagation is not handled

@@ -99,2 +105,61 @@ automatically.**

<h3 id="amqplib">amqplib</h3>
<h5 id="amqplib-tags">Tags</h5>
| Tag | Description |
|------------------|-----------------------------------------------------------|
| out.host | The host of the AMQP server. |
| out.port | The port of the AMQP server. |
| span.kind | Set to either `producer` or `consumer` where it applies. |
| amqp.queue | The queue targeted by the command (when available). |
| amqp.exchange | The exchange targeted by the command (when available). |
| amqp.routingKey | The routing key targeted by the command (when available). |
| amqp.consumerTag | The consumer tag (when available). |
| amqp.source | The source exchange of the binding (when available). |
| amqp.destination | The destination exchange of the binding (when available). |
<h5 id="amqplib-config">Configuration Options</h5>
| Option | Default | Description |
|------------------|---------------------------|----------------------------------------|
| service | *Service name of the app* | The service name for this integration. |
<h5 id="amqplib-limitations">Known Limitations</h5>
When consuming messages, the current span will be immediately finished. This means that if any asynchronous operation is started in the message handler callback, its duration will be excluded from the span duration.
For example:
```js
channel.consume('queue', msg => {
setTimeout(() => {
// The message span will not include the 1 second from this operation.
}, 1000)
}, {}, () => {})
```
This limitation doesn't apply to other commands. We are working on improving this behavior in a future version.
<h3 id="elasticsearch">elasticsearch</h3>
<h5 id="elasticsearch-tags">Tags</h5>
| Tag | Description |
|----------------------|-------------------------------------------------------|
| db.type | Always set to `elasticsearch`. |
| out.host | The host of the Elasticsearch server. |
| out.port | The port of the Elasticsearch server. |
| span.kind | Always set to `client`. |
| elasticsearch.method | The underlying HTTP request verb. |
| elasticsearch.url | The underlying HTTP request URL path. |
| elasticsearch.body | The body of the query. |
| elasticsearch.params | The parameters of the query. |
<h5 id="elasticsearch-config">Configuration Options</h5>
| Option | Default | Description |
|------------------|------------------|----------------------------------------|
| service | elasticsearch | The service name for this integration. |
<h3 id="express">express</h3>

@@ -116,2 +181,34 @@

<h3 id="graphql">graphql</h3>
The `graphql` integration uses the operation name as the span resource name. If no operation name is set, the resource name will always be just `query` or `mutation`.
For example:
```graphql
# good, the resource name will be `query HelloWorld`
query HelloWorld {
hello
world
}
# bad, the resource name will be `query`
{
hello
world
}
```
<h5 id="graphql-tags">Tags</h5>
| Tag | Description |
|------------------|-----------------------------------------------------------|
| graphql.document | The original GraphQL document. |
<h5 id="graphql-config">Configuration Options</h5>
| Option | Default | Description |
|---------|--------------------------------------------------|----------------------------------------|
| service | *Service name of the app suffixed with -graphql* | The service name for this integration. |
<h3 id="http">http / https</h3>

@@ -233,3 +330,3 @@

| flushInterval | | 2000 | Interval in milliseconds at which the tracer will submit traces to the agent. |
| experimental | | {} | Experimental features can be enabled all at once using boolean `true` or individually using key/value pairs. Available experimental features: `asyncHooks`. |
| experimental | | {} | Experimental features can be enabled all at once using boolean `true` or individually using key/value pairs. There are currently no experimental features available. |
| plugins | | true | Whether or not to enable automatic instrumentation of external libraries using the built-in plugins. |

@@ -236,0 +333,0 @@

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

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

@@ -32,3 +32,3 @@ "main": "index.js",

"engines": {
"node": ">=4"
"node": ">=4.7"
},

@@ -41,2 +41,3 @@ "dependencies": {

"koalas": "^1.0.2",
"lodash.kebabcase": "^4.1.1",
"methods": "^1.1.2",

@@ -50,3 +51,3 @@ "msgpack-lite": "^0.1.26",

"require-dir": "^1.0.0",
"require-in-the-middle": "^2.2.1",
"require-in-the-middle": "^2.2.2",
"safe-buffer": "^5.1.1",

@@ -58,2 +59,3 @@ "semver": "^5.5.0",

"devDependencies": {
"amqplib": "^0.5.2",
"axios": "^0.18.0",

@@ -64,2 +66,3 @@ "benchmark": "^2.1.4",

"chai": "^4.1.2",
"elasticsearch": "^15.0.0",
"eslint": "^4.15.0",

@@ -73,2 +76,3 @@ "eslint-config-standard": "^11.0.0-beta.0",

"get-port": "^3.2.0",
"graphql": "^0.13.2",
"gulp": "^3.9.1",

@@ -75,0 +79,0 @@ "gulp-jsdoc3": "^2.0.0",

'use strict'
const exec = require('child_process').execSync
const exec = require('./helpers/exec')
const title = require('./helpers/title')
title(`Publishing package to the npm registry`)
const pkg = require('../package.json')
exec('npm whoami')

@@ -9,1 +14,2 @@ exec('git checkout master')

exec('npm publish')
exec(`node scripts/publish_docs.js "v${pkg.version}"`)

@@ -6,4 +6,7 @@ 'use strict'

const semver = require('semver')
const exec = require('child_process').execSync
const exec = require('./helpers/exec')
const title = require('./helpers/title')
title('Pulling latest changes from master')
exec(`git checkout master`)

@@ -16,2 +19,4 @@ exec(`git pull`)

title(`Bumping version to v${version} in a new branch`)
pkg.version = version

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

@@ -22,2 +22,5 @@ 'use strict'

// Temporary safety net. Do not disable without contacting support.
const asyncHooks = coalesce(options.asyncHooks, true)
this.enabled = String(enabled) === 'true'

@@ -34,16 +37,6 @@ this.debug = String(debug) === 'true'

this.plugins = !!plugins
this.experimental = {
asyncHooks: isFlagEnabled(options.experimental, 'asyncHooks')
}
this.asyncHooks = !!asyncHooks
}
}
function isFlagEnabled (obj, prop) {
return obj === true || (isObject(obj) && !!obj[prop])
}
function isObject (value) {
return typeof value === 'object' && value !== null
}
module.exports = Config

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

name: String(span._operationName),
resource: String(span._operationName),
service: String(tracer._service),

@@ -46,2 +47,7 @@ error: 0,

break
case 'error':
if (tags[tag]) {
trace.error = 1
}
break
case 'error.type':

@@ -48,0 +54,0 @@ case 'error.msg':

@@ -20,11 +20,9 @@ 'use strict'

use (name, config) {
config = config || {}
if (typeof name === 'string') {
this._integrations
.filter(plugin => plugin.name === name)
.forEach(plugin => this._plugins.set(plugin, config))
} else {
.forEach(plugin => this._set(plugin, config))
} else if (name) {
[].concat(name)
.forEach(plugin => this._plugins.set(plugin, config))
.forEach(plugin => this._set(plugin, config))
}

@@ -40,3 +38,3 @@

this._integrations.forEach(integration => {
this._plugins.has(integration) || this._plugins.set(integration, {})
this._plugins.has(integration) || this._set(integration, {})
})

@@ -80,2 +78,15 @@ }

}
_set (plugin, config) {
config = config || {}
this._plugins.set(plugin, config)
if (require.cache[plugin.name]) {
log.debug([
`Instrumented module "${plugin.name}" was imported before calling tracer.init().`,
`Please make sure to initialize the tracer before importing any instrumented module.`
].join(' '))
}
}
}

@@ -82,0 +93,0 @@

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

@@ -13,4 +14,4 @@ const DatadogSpanContext = require('../span_context')

inject (spanContext, carrier) {
carrier[traceKey] = spanContext.traceId.toString()
carrier[spanKey] = spanContext.spanId.toString()
carrier[traceKey] = new Int64BE(spanContext.traceId.toBuffer()).toString()
carrier[spanKey] = new Int64BE(spanContext.spanId.toBuffer()).toString()

@@ -38,4 +39,4 @@ spanContext.baggageItems && Object.keys(spanContext.baggageItems).forEach(key => {

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

@@ -42,0 +43,0 @@ })

'use strict'
module.exports = config => {
module.exports = function () {
let namespace
if (config.experimental.asyncHooks) {
if (this._config.asyncHooks) {
namespace = require('./cls_hooked')

@@ -8,0 +8,0 @@ } else {

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

@@ -13,5 +13,9 @@ 'use strict'

module.exports = {
_config: {},
name: () => 'nodejs',
version: () => process.version,
engine: () => process.jsEngine || 'v8',
configure (config) {
this._config = config
},
id,

@@ -18,0 +22,0 @@ now,

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

function createWrapGetConnection (tracer) {
return function wrapGetConnection (getConnection) {
return function getConnectionWithTrace (cb) {
return getConnection.call(this, tracer.bind(cb))
}
}
}
function wrapCallback (tracer, span, done) {

@@ -81,10 +73,2 @@ return tracer.bind((err, res) => {

function patchPool (Pool, tracer, config) {
shimmer.wrap(Pool.prototype, 'getConnection', createWrapGetConnection(tracer, config))
}
function unpatchPool (Pool) {
shimmer.unwrap(Pool.prototype, 'getConnection')
}
module.exports = [

@@ -97,10 +81,3 @@ {

unpatch: unpatchConnection
},
{
name: 'mysql',
file: 'lib/Pool.js',
versions: ['2.x'],
patch: patchPool,
unpatch: unpatchPool
}
]

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

function createWrapGetConnection (tracer) {
return function wrapGetConnection (getConnection) {
return function getConnectionWithTrace (cb) {
return getConnection.call(this, tracer.bind(cb))
}
}
}
function wrapCallback (tracer, span, done) {

@@ -81,10 +73,2 @@ return tracer.bind((err, res) => {

function patch (mysql2, tracer, config) {
shimmer.wrap(mysql2.Pool.prototype, 'getConnection', createWrapGetConnection(tracer, config))
}
function unpatch (mysql2) {
shimmer.unwrap(mysql2.Pool.prototype, 'getConnection')
}
module.exports = [

@@ -97,9 +81,3 @@ {

unpatch: unpatchConnection
},
{
name: 'mysql2',
versions: ['^1.5'],
patch: patch,
unpatch: unpatch
}
]

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

name: 'redis',
versions: ['>=2.6'],
versions: ['^2.6'],
patch,
unpatch
}

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

* using boolean `true` or individually using key/value pairs.
* @param {boolean} [options.experimental.asyncHooks=false] Whether to use Node's experimental async hooks.
* @param {boolean} [options.plugins=true] Whether to load all built-in plugins.

@@ -49,2 +48,4 @@ * @returns {Tracer} Self

platform.configure(config)
this._tracer = new DatadogTracer(config)

@@ -51,0 +52,0 @@ this._instrumenter.patch(config)

@@ -21,9 +21,14 @@ 'use strict'

const childOf = options.childOf !== undefined ? options.childOf : this._context.get('current')
const tags = Object.assign({
const defaultTags = {
'service.name': options.service || this._service,
'resource.name': options.resource || name,
'span.type': options.type
}, options.tags)
'resource.name': options.resource || name
}
if (options.type) {
defaultTags['span.type'] = options.type
}
const tags = Object.assign(defaultTags, options.tags)
const span = this.startSpan(name, { childOf, tags })
this._context.set('current', span)

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

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

log.debug(() => `Adding encoded trace to buffer: ${buffer.inspect()}`)
log.debug(() => `Adding encoded trace to buffer: ${buffer.toString('hex').match(/../g).join(' ')}`)

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

@@ -12,3 +12,4 @@ {

"proxyquire": true,
"nock": true
"nock": true,
"wrapIt": true
},

@@ -15,0 +16,0 @@ "rules": {

@@ -109,24 +109,2 @@ 'use strict'

it('should support global experimental flag', () => {
const config = new Config({
experimental: true
})
expect(config).to.have.deep.property('experimental', {
asyncHooks: true
})
})
it('should support experimental asyncHooks flag', () => {
const config = new Config({
experimental: {
asyncHooks: true
}
})
expect(config).to.have.deep.property('experimental', {
asyncHooks: true
})
})
it('should sanitize the sample rate to be between 0 and 1', () => {

@@ -133,0 +111,0 @@ expect(new Config({ sampleRate: -1 })).to.have.property('sampleRate', 0)

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

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

@@ -47,5 +48,5 @@ const msgpack = require('msgpack-lite')

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

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

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

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

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

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

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

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

@@ -44,2 +44,3 @@ describe('format', () => {

expect(trace.name).to.equal(span._operationName)
expect(trace.resource).to.equal(span._operationName)
expect(trace.service).to.equal(span.tracer()._service)

@@ -89,3 +90,29 @@ expect(trace.error).to.equal(0)

it('should set the error flag when there is an error tag', () => {
describe('when there is an `error` tag ', () => {
it('should set the error flag when error tag is true', () => {
span._tags['error'] = true
trace = format(span)
expect(trace.error).to.equal(1)
})
it('should not set the error flag when error is false', () => {
span._tags['error'] = false
trace = format(span)
expect(trace.error).to.equal(0)
})
it('should not extract error to meta', () => {
span._tags['error'] = true
trace = format(span)
expect(trace.meta['error']).to.be.undefined
})
})
it('should set the error flag when there is an error-related tag', () => {
span._tags['error.type'] = 'Error'

@@ -113,2 +140,3 @@ span._tags['error.msg'] = 'boom'

expect(trace.service).to.equal('null')
expect(trace.resource).to.equal('null')
expect(trace.meta['foo.bar']).to.equal('null')

@@ -115,0 +143,0 @@ expect(trace.start).to.be.instanceof(Int64BE)

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

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

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

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

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

@@ -17,3 +17,3 @@

'x-datadog-trace-id': '123',
'x-datadog-parent-id': '456',
'x-datadog-parent-id': '-456',
'ot-baggage-foo': 'bar'

@@ -30,4 +30,4 @@ }

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

@@ -44,4 +44,4 @@ })

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

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

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

@@ -74,0 +74,0 @@ }))

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

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

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

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

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

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

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

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

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().traceId).to.deep.equal(new Uint64BE(123, 123))
expect(span.context().parentId).to.deep.equal(new Uint64BE(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])

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

wrapIt()
describe('Platform', () => {

@@ -325,3 +327,2 @@ describe('Node', () => {

describe('context', () => {
let context
let namespace

@@ -334,3 +335,2 @@ let clsBluebird

clsBluebird = sinon.spy(require.cache[require.resolve('cls-bluebird')], 'exports')
context = require('../../../src/platform/node/context')
})

@@ -344,4 +344,4 @@

beforeEach(() => {
config = { experimental: { asyncHooks: false } }
namespace = context(config)
platform.configure({ asyncHooks: false })
namespace = platform.context()
})

@@ -352,13 +352,11 @@

if (semver.gte(semver.valid(process.version), '8.2.0')) {
describe('cls-hooked', () => {
beforeEach(() => {
config = { experimental: { asyncHooks: true } }
namespace = context(config)
})
testContext('../../../src/platform/node/context/cls_hooked')
describe('cls-hooked', () => {
beforeEach(() => {
platform.configure({ asyncHooks: true })
namespace = platform.context(config)
})
}
testContext('../../../src/platform/node/context/cls_hooked')
})
function testContext (modulePath) {

@@ -464,3 +462,3 @@ it('should use the correct implementation from the experimental flag', () => {

it('should only patch bluebird once', () => {
context(config)
platform.context()
expect(clsBluebird).to.not.have.been.called

@@ -467,0 +465,0 @@ })

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

let handlers = []
let promise
let skip = []

@@ -64,13 +65,20 @@

use (callback) {
return new Promise((resolve, reject) => {
handlers.push(function () {
try {
callback.apply(null, arguments)
resolve()
} catch (e) {
reject(e)
}
})
})
use (callback, count) {
count = count || 1
promise = Promise.reject(new Error('No request was expected.'))
for (let i = 0; i < count; i++) {
promise = promise.catch(() => new Promise((resolve, reject) => {
handlers.push(function () {
try {
callback.apply(null, arguments)
resolve()
} catch (e) {
reject(e)
}
})
}))
}
return promise
},

@@ -77,0 +85,0 @@

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

wrapIt()
describe('Plugin', () => {

@@ -18,3 +20,3 @@ let plugin

express = require('express')
context = require('../../src/platform').context({ experimental: { asyncHooks: false } })
context = require('../../src/platform').context()
})

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

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

wrapIt()
describe('Plugin', () => {

@@ -8,0 +10,0 @@ let plugin

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

wrapIt()
describe('Plugin', () => {

@@ -48,3 +50,3 @@ let plugin

platform = require('../../src/platform')
context = platform.context({ experimental: { asyncHooks: false } })
context = platform.context()

@@ -51,0 +53,0 @@ collection = platform.id().toString()

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

wrapIt()
describe('Plugin', () => {

@@ -15,3 +17,3 @@ let plugin

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

@@ -27,12 +29,15 @@

beforeEach(() => {
connection = mysql.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql')
.then(() => {
mysql = require('mysql')
connection.connect()
connection = mysql.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql')
connection.connect()
})
})

@@ -118,3 +123,2 @@

error = err
expect(error).to.be.an('error')
})

@@ -141,12 +145,15 @@ })

connection = mysql.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql', config)
.then(() => {
mysql = require('mysql')
connection.connect()
connection = mysql.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql', config)
connection.connect()
})
})

@@ -172,10 +179,13 @@

beforeEach(() => {
pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'user',
password: 'userpass'
})
return agent.load(plugin, 'mysql')
.then(() => {
mysql = require('mysql')
return agent.load(plugin, 'mysql')
pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'user',
password: 'userpass'
})
})
})

@@ -182,0 +192,0 @@

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

wrapIt()
describe('Plugin', () => {

@@ -13,5 +15,4 @@ let plugin

beforeEach(() => {
mysql2 = require('mysql2')
plugin = require('../../src/plugins/mysql2')
context = require('../../src/platform').context({ experimental: { asyncHooks: false } })
context = require('../../src/platform').context()
})

@@ -27,12 +28,15 @@

beforeEach(() => {
connection = mysql2.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql2')
.then(() => {
mysql2 = require('mysql2')
connection.connect()
connection = mysql2.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql2')
connection.connect()
})
})

@@ -120,3 +124,2 @@

error = err
expect(error).to.be.an('error')
})

@@ -144,12 +147,15 @@ })

connection = mysql2.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql2', config)
.then(() => {
mysql2 = require('mysql2')
connection.connect()
connection = mysql2.createConnection({
host: 'localhost',
user: 'user',
password: 'userpass',
database: 'db'
})
return agent.load(plugin, 'mysql2', config)
connection.connect()
})
})

@@ -177,10 +183,13 @@

beforeEach(() => {
pool = mysql2.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'user',
password: 'userpass'
})
return agent.load(plugin, 'mysql2')
.then(() => {
mysql2 = require('mysql2')
return agent.load(plugin, 'mysql2')
pool = mysql2.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'user',
password: 'userpass'
})
})
})

@@ -187,0 +196,0 @@

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

wrapIt()
describe('Plugin', () => {

@@ -7,0 +9,0 @@ let plugin

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

wrapIt()
describe('Plugin', () => {

@@ -16,3 +18,3 @@ let plugin

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

@@ -19,0 +21,0 @@

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

const mongo = require('mongodb-core')
const elasticsearch = require('elasticsearch')
const amqplib = require('amqplib/callback_api')
const platform = require('../src/platform')

@@ -31,2 +33,3 @@ const node = require('../src/platform/node')

global.nock = nock
global.wrapIt = wrapIt

@@ -46,3 +49,5 @@ platform.use(node)

waitForRedis(),
waitForMongo()
waitForMongo(),
waitForElasticsearch(),
waitForRabbitMQ()
])

@@ -150,1 +155,78 @@ }

}
function waitForElasticsearch () {
return new Promise((resolve, reject) => {
const operation = retry.operation(retryOptions)
operation.attempt(currentAttempt => {
const client = new elasticsearch.Client({
host: 'localhost:9200'
})
client.ping((err) => {
if (operation.retry(err)) return
if (err) reject(err)
resolve()
})
})
})
}
function waitForRabbitMQ () {
return new Promise((resolve, reject) => {
const operation = retry.operation(retryOptions)
operation.attempt(currentAttempt => {
amqplib
.connect((err, conn) => {
if (operation.retry(err)) return
if (err) reject(err)
conn.close(() => resolve())
})
})
})
}
function wrapIt () {
const it = global.it
global.it = function (title, fn) {
if (fn.length > 0) {
return it.call(this, title, function (done) {
const context = platform.context()
arguments[0] = context.bind(done)
return fn.apply(this, arguments)
})
} else {
return it.call(this, title, function () {
const context = platform.context()
const defer = {}
defer.promise = new Promise((resolve, reject) => {
defer.resolve = context.bind(resolve)
defer.reject = context.bind(reject)
})
const result = fn.apply(this, arguments)
if (result && result.then) {
return result
.then(function () {
defer.resolve.apply(defer, arguments)
return defer.promise
})
.catch(function () {
defer.reject.apply(defer, arguments)
return defer.promise
})
}
return result
})
}
}
}
'use strict'
const EventEmitter = require('events')
const Span = require('../src/opentracing/span')

@@ -8,2 +9,4 @@ const SpanContext = require('../src/opentracing/span_context')

wrapIt()
describe('Tracer', () => {

@@ -20,4 +23,4 @@ let Tracer

context = platform.context(config)
sinon.stub(context, 'bind')
sinon.stub(context, 'bindEmitter')
sinon.spy(context, 'bind')
sinon.spy(context, 'bindEmitter')

@@ -33,2 +36,4 @@ instrumenter = {

})
tracer = new Tracer(config)
})

@@ -43,4 +48,2 @@

it('should run the callback with the new span', done => {
tracer = new Tracer(config)
tracer.trace('name', current => {

@@ -53,4 +56,2 @@ expect(current).to.be.instanceof(Span)

it('should use the parent context', done => {
tracer = new Tracer(config)
tracer.trace('parent', parent => {

@@ -65,4 +66,2 @@ tracer.trace('child', child => {

it('should support explicitly creating a root span', done => {
tracer = new Tracer(config)
tracer.trace('parent', parent => {

@@ -77,7 +76,6 @@ tracer.trace('child', { childOf: null }, child => {

it('should set default tags', done => {
tracer = new Tracer(config)
tracer.trace('name', current => {
expect(current._tags).to.have.property('service.name', 'service')
expect(current._tags).to.have.property('resource.name', 'name')
expect(current._tags).to.not.have.property('span.type')
done()

@@ -88,4 +86,2 @@ })

it('should support service option', done => {
tracer = new Tracer(config)
tracer.trace('name', { service: 'test' }, current => {

@@ -98,4 +94,2 @@ expect(current._tags).to.have.property('service.name', 'test')

it('should support resource option', done => {
tracer = new Tracer(config)
tracer.trace('name', { resource: 'test' }, current => {

@@ -108,4 +102,2 @@ expect(current._tags).to.have.property('resource.name', 'test')

it('should support type option', done => {
tracer = new Tracer(config)
tracer.trace('name', { type: 'test' }, current => {

@@ -122,4 +114,2 @@ expect(current._tags).to.have.property('span.type', 'test')

tracer = new Tracer(config)
tracer.trace('name', { tags }, current => {

@@ -137,4 +127,2 @@ expect(current._tags).to.have.property('foo', 'bar')

tracer = new Tracer(config)
tracer.trace('name', { childOf }, current => {

@@ -150,4 +138,2 @@ expect(current.context().traceId).to.equal(childOf.traceId)

it('should return the current span', done => {
tracer = new Tracer(config)
tracer.trace('name', current => {

@@ -160,4 +146,2 @@ expect(tracer.currentSpan()).to.equal(current)

it('should return null when there is no current span', () => {
tracer = new Tracer(config)
expect(tracer.currentSpan()).to.be.null

@@ -171,4 +155,2 @@ })

tracer = new Tracer(config)
tracer.trace('name', current => {

@@ -183,7 +165,9 @@ tracer.bind(callback)

describe('bindEmitter', () => {
it('should bind an emitter to the context', done => {
const emitter = 'emitter'
let emitter
tracer = new Tracer(config)
beforeEach(() => {
emitter = new EventEmitter()
})
it('should bind an emitter to the context', done => {
tracer.trace('name', current => {

@@ -190,0 +174,0 @@ tracer.bindEmitter(emitter)

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc