Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
image: redis:4.0-alpine
- &mongo
image: mongo:3.6
- &elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
- &rabbitmq
image: rabbitmq:3.6-alpine
working_directory: ~/dd-trace-js
steps:
- checkout
Expand All @@ -54,6 +58,8 @@ jobs:
- *mysql
- *redis
- *mongo
- *elasticsearch
- *rabbitmq
build-node-6:
<<: *node-base
docker:
Expand All @@ -62,6 +68,8 @@ jobs:
- *mysql
- *redis
- *mongo
- *elasticsearch
- *rabbitmq
build-node-8:
<<: *node-base
docker:
Expand All @@ -70,6 +78,8 @@ jobs:
- *mysql
- *redis
- *mongo
- *elasticsearch
- *rabbitmq
build-node-latest:
<<: *node-base
docker:
Expand All @@ -78,6 +88,8 @@ jobs:
- *mysql
- *redis
- *mongo
- *elasticsearch
- *rabbitmq

workflows:
version: 2
Expand Down
4 changes: 4 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require,cls-hooked,BSD-2-Clause,Copyright 2013-2016 Forrest L Norvell
require,continuation-local-storage,BSD-2-Clause,Copyright 2013-2016 Forrest L Norvell
require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
require,koalas,MIT,Copyright 2013-2017 Brian Woodward
require,lodash.kebabcase,MIT,Copyright JS Foundation and other contributors
require,methods,MIT,Copyright 2013-2014 TJ Holowaychuk 2013-2014 TJ Holowaychuk
require,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
Expand All @@ -16,11 +17,13 @@ require,require-in-the-middle,MIT,Copyright 2016-2018 Thomas Watson Steen
require,safe-buffer,MIT,Copyright Feross Aboukhadijeh
require,shimmer,BSD-2-Clause,Copyright Forrest L Norvell
require,url-parse,MIT,Copyright 2015 Unshift.io Arnout Kazemier the Contributors
dev,amqplib,MIT,Copyright 2013-2014 Michael Bridgen
dev,axios,MIT,Copyright 2014-present Matt Zabriskie
dev,benchmark,MIT,Copyright 2010-2016 Mathias Bynens Robert Kieffer John-David Dalton
dev,bluebird,MIT,Copyright 2013-2018 Petka Antonov
dev,body-parser,MIT,Copyright 2014 Jonathan Ong 2014-2015 Douglas Christopher Wilson
dev,chai,MIT,Copyright 2017 Chai.js Assertion Library
dev,elasticsearch,Apache-2.0,Copyright 2013 Elasticsearch BV
dev,eslint,MIT,Copyright JS Foundation and other contributors https://js.foundation
dev,eslint-config-standard,MIT,Copyright Feross Aboukhadijeh
dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
Expand All @@ -29,6 +32,7 @@ dev,eslint-plugin-promise,ISC,jden and other contributors
dev,eslint-plugin-standard,MIT,Copyright 2015 Jamund Ferguson
dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson
dev,get-port,MIT,Copyright Sindre Sorhus
dev,graphql,MIT,Copyright 2015-present Facebook Inc.
dev,gulp,MIT,Copyright 2013-2017 Blaine Bublitz Eric Schoffstall and other contributors
dev,gulp-jsdoc3,Apache-2.0,Copyright Marc Udoff
dev,jsdoc,Apache-2.0,Copyright 2011-present Michael Mathews and the contributors to JSDoc
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ services:
image: mongo:3.6
ports:
- "127.0.0.1:27017:27017"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
ports:
- "127.0.0.1:9200:9200"
rabbitmq:
image: rabbitmq:3.6-alpine
ports:
- "127.0.0.1:5672:5672"
93 changes: 92 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,65 @@ tracer.use('pg', {

Each integration also has its own list of default tags. These tags get automatically added to the span created by the integration.

<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>

<h5 id="express-tags">Tags</h5>
Expand All @@ -117,6 +176,38 @@ Each integration also has its own list of default tags. These tags get automatic
|------------------|---------------------------|----------------------------------------|
| service | *Service name of the app* | The service name for this integration. |

<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>

<h5 id="http-tags">Tags</h5>
Expand Down Expand Up @@ -233,7 +324,7 @@ Options can be configured as a parameter to the [init()](https://datadog.github.
| tags | | {} | Set global tags that should be applied to all spans. |
| sampleRate | | 1 | Percentage of spans to sample as a float between 0 and 1. |
| 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. |

<h3 id="custom-logging">Custom Logging</h3>
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '0.2.1'
module.exports = '0.3.0'
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dd-trace",
"version": "0.2.1",
"version": "0.3.0",
"description": "Datadog APM tracing client for JavaScript (experimental)",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,14 +29,15 @@
},
"homepage": "https://github.com/DataDog/dd-trace-js#readme",
"engines": {
"node": ">=4"
"node": ">=4.7"
},
"dependencies": {
"cls-bluebird": "^2.1.0",
"cls-hooked": "^4.2.2",
"continuation-local-storage": "^3.2.1",
"int64-buffer": "^0.1.9",
"koalas": "^1.0.2",
"lodash.kebabcase": "^4.1.1",
"methods": "^1.1.2",
"msgpack-lite": "^0.1.26",
"opentracing": "0.14.1",
Expand All @@ -52,11 +53,13 @@
"url-parse": "^1.2.0"
},
"devDependencies": {
"amqplib": "^0.5.2",
"axios": "^0.18.0",
"benchmark": "^2.1.4",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"chai": "^4.1.2",
"elasticsearch": "^15.0.0",
"eslint": "^4.15.0",
"eslint-config-standard": "^11.0.0-beta.0",
"eslint-plugin-import": "^2.8.0",
Expand All @@ -65,6 +68,7 @@
"eslint-plugin-standard": "^3.0.1",
"express": "^4.16.2",
"get-port": "^3.2.0",
"graphql": "^0.13.2",
"gulp": "^3.9.1",
"gulp-jsdoc3": "^2.0.0",
"jsdoc": "^3.5.5",
Expand Down
8 changes: 8 additions & 0 deletions scripts/helpers/color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
module.exports = {
GRAY: '\\033[1;90m',
CYAN: '\\033[1;36m',
NONE: '\\033[0m'
}
13 changes: 13 additions & 0 deletions scripts/helpers/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const execSync = require('child_process').execSync
const color = require('./color')

function exec (command, options) {
options = Object.assign({ stdio: [0, 1, 2] }, options)

execSync(`echo "${color.GRAY}$ ${command}${color.NONE}"`, options)
execSync(command, options)
}

module.exports = exec
15 changes: 15 additions & 0 deletions scripts/helpers/title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const exec = require('child_process').execSync
const color = require('./color')

function title (str) {
const options = { stdio: [0, 1, 2] }
const line = ''.padStart(str.length, '=')

exec(`echo "${color.CYAN}${line}${color.NONE}"`, options)
exec(`echo "${color.CYAN}${str}${color.NONE}"`, options)
exec(`echo "${color.CYAN}${line}${color.NONE}"`, options)
}

module.exports = title
26 changes: 26 additions & 0 deletions scripts/publish_docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const fs = require('fs')
const exec = require('./helpers/exec')
const title = require('./helpers/title')

title(`Publishing API documentation to GitHub Pages`)

const msg = process.argv[2]

if (!msg) {
throw new Error('Please provide a reason for the change. Example: node scripts/publish_docs.js "fix typo"')
}

if (fs.existsSync('yarn.lock')) {
exec('yarn')
} else {
exec('npm install')
}

exec('rm -rf ./out')
exec('git clone -b gh-pages --single-branch git@github.com:DataDog/dd-trace-js.git out')
exec('npm run jsdoc')
exec('git add -A', { cwd: './out' })
exec(`git commit -m "${msg}"`, { cwd: './out' })
exec('git push', { cwd: './out' })
8 changes: 7 additions & 1 deletion scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'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')
exec('git checkout master')
exec('git pull')
exec('npm publish')
exec(`node scripts/publish_docs.js "v${pkg.version}"`)
7 changes: 6 additions & 1 deletion scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
const path = require('path')
const fs = require('fs')
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`)
exec(`git pull`)
Expand All @@ -12,6 +15,8 @@ const pkg = require('../package.json')
const increment = getIncrement()
const version = semver.inc(pkg.version, increment)

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

pkg.version = version

exec(`git checkout -b v${version}`)
Expand Down
15 changes: 4 additions & 11 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Config {
const flushInterval = coalesce(parseInt(options.flushInterval, 10), 2000)
const plugins = coalesce(options.plugins, true)

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

this.enabled = String(enabled) === 'true'
this.debug = String(debug) === 'true'
this.service = service
Expand All @@ -30,18 +33,8 @@ class Config {
this.sampleRate = sampleRate
this.logger = options.logger
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
4 changes: 2 additions & 2 deletions src/platform/node/context/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

module.exports = config => {
module.exports = function () {
let namespace

if (config.experimental.asyncHooks) {
if (this._config.asyncHooks) {
namespace = require('./cls_hooked')
} else {
namespace = require('./cls')
Expand Down
Loading