Skip to content

Commit

Permalink
Merge pull request #379 from DataDog/v0.7.0
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
rochdev authored Nov 16, 2018
2 parents 8e9c904 + b8be798 commit 94870e1
Show file tree
Hide file tree
Showing 56 changed files with 1,836 additions and 633 deletions.
89 changes: 82 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ jobs:
docker:
- image: node:8

node-core-10:
<<: *node-core-base
docker:
- image: node:10

node-core-latest:
<<: *node-core-base
docker:
Expand Down Expand Up @@ -145,6 +150,14 @@ jobs:
- QPIDD_ADMIN_USERNAME=admin
- QPIDD_ADMIN_PASSWORD=admin

node-bluebird:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=bluebird

node-elasticsearch:
<<: *node-plugin-base
docker:
Expand All @@ -157,6 +170,14 @@ jobs:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms64m -Xmx64m"

node-express:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=express

node-graphql:
<<: *node-plugin-base
docker:
Expand All @@ -165,6 +186,14 @@ jobs:
- SERVICES=
- PLUGINS=graphql

node-hapi:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=hapi

node-http:
<<: *node-plugin-base
docker:
Expand All @@ -173,6 +202,14 @@ jobs:
- SERVICES=
- PLUGINS=http

node-koa:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=koa

node-memcached:
<<: *node-plugin-base
docker:
Expand All @@ -194,7 +231,7 @@ jobs:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=db

node-mongo:
node-mongodb-core:
<<: *node-plugin-base
docker:
- image: node:8
Expand All @@ -212,6 +249,14 @@ jobs:
- PLUGINS=pg
- image: postgres:9.5

node-q:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=q

node-redis:
<<: *node-plugin-base
docker:
Expand All @@ -221,13 +266,29 @@ jobs:
- PLUGINS=redis|ioredis
- image: redis:4.0-alpine

node-web:
node-restify:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=restify

node-router:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=router

node-when:
<<: *node-plugin-base
docker:
- image: node:8
environment:
- SERVICES=
- PLUGINS=express|hapi|koa|restify
- PLUGINS=when

workflows:
version: 2
Expand All @@ -238,18 +299,25 @@ workflows:
- node-core-4
- node-core-6
- node-core-8
- node-core-10
- node-core-latest
- node-amqplib
- node-amqp10
- node-bluebird
- node-elasticsearch
- node-express
- node-graphql
- node-hapi
- node-http
- node-koa
- node-memcached
- node-mongo
- node-mongodb-core
- node-mysql
- node-postgres
- node-q
- node-redis
- node-web
- node-restify
- node-when
nightly:
triggers:
- schedule:
Expand All @@ -262,15 +330,22 @@ workflows:
- node-core-4
- node-core-6
- node-core-8
- node-core-10
- node-core-latest
- node-amqplib
- node-amqp10
- node-bluebird
- node-elasticsearch
- node-express
- node-graphql
- node-hapi
- node-http
- node-koa
- node-memcached
- node-mongo
- node-mongodb-core
- node-mysql
- node-postgres
- node-q
- node-redis
- node-web
- node-restify
- node-when
16 changes: 10 additions & 6 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Each integration also has its own list of default tags. These tags get automatic

<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`.
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`, `mutation` or `subscription`.

For example:

Expand Down Expand Up @@ -178,8 +178,9 @@ query HelloWorld {
| Option | Default | Description |
|-----------------|--------------------------------------------------|------------------------------------------------------------------------|
| service | *Service name of the app suffixed with -graphql* | The service name for this integration. |
| variables | `undefined` | A callback to enable recording of variables. By default, no variables are recorded. For example, using `variables => variables` would record all variables. |
| variables | [] | An array of variable names to record. Can also be a callback that returns the key/value pairs to record. For example, using `variables => variables` would record all variables. |
| depth | -1 | The maximum depth of fields/resolvers to instrument. Set to `0` to only instrument the operation or to -1 to instrument all fields/resolvers. |
| collapse | true | Whether to collapse list items into a single element. (i.e. single `users.*.name` span instead of `users.0.name`, `users.1.name`, etc) |

<h3 id="hapi">hapi</h3>

Expand Down Expand Up @@ -212,10 +213,13 @@ query HelloWorld {

<h5 id="http-config">Configuration Options</h5>

| Option | Default | Description |
|------------------|------------------|----------------------------------------|
| service | http-client | The service name for this integration. |
| splitByDomain | false | Use the remote endpoint host as the service name instead of the default. |
| Option | Default | Description |
|------------------|---------------------------------------|-------------------|
| service | http-client | The service name for this integration. |
| splitByDomain | false | Use the remote endpoint host as the service name instead of the default. |
| validateStatus | `code => code < 400 || code >= 500` | Callback function to determine if an HTTP response should be recorded as an error. It should take a status code as its only parameter and return `true` for success or `false` for errors.
| blacklist | [] | List of URLs that should not be instrumented. Can be a string, RegExp, callback that takes the URL as a parameter, or an array of any of these.
| whitelist | /.*/ | List of URLs that should be instrumented. If this is set, other URLs will not be instrumented. Can be a string, RegExp, callback that takes the URL as a parameter, or an array of any of these.

<h3 id="ioredis">ioredis</h3>

Expand Down
1 change: 1 addition & 0 deletions ext/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ module.exports = {
HTTP_URL: 'http.url',
HTTP_METHOD: 'http.method',
HTTP_STATUS_CODE: 'http.status_code',
HTTP_ROUTE: 'http.route',
HTTP_HEADERS: 'http.headers'
}
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '0.6.2'
module.exports = '0.7.0'
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dd-trace",
"version": "0.6.2",
"version": "0.7.0",
"description": "Datadog APM tracing client for JavaScript",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"tdd": "yarn services && mocha --watch 'test/setup/**/*.js'",
"test": "yarn services && cov8 --include \"src/**/*.js\" -- mocha --exit 'test/setup/all.js' 'test/**/*.spec.js'",
"test:core": "mocha --exit --exclude \"test/plugins/**/*.spec.js\" --file test/setup/core.js \"test/**/*.spec.js\"",
"test:plugins": "yarn services && cov8 --include \"src/**/*.js\" -- mocha --exit --file \"test/setup/all.js\" \"test/plugins/@($(echo $PLUGINS)).spec.js\"",
"test:plugins": "yarn services && cov8 --include \"src/**/*.js\" -- mocha --exit --file \"test/setup/all.js\" \"test/plugins/@($(echo $PLUGINS)).spec.js\" \"test/plugins/@($(echo $PLUGINS))/**/*.spec.js\"",
"leak:core": "node ./scripts/install_plugin_modules && (cd test/leak && yarn) && NODE_PATH=./test/leak/node_modules node --no-warnings ./node_modules/.bin/tape 'test/leak/{,!(node_modules|plugins)/**/}/*.js'",
"leak:plugins": "yarn services && (cd test/leak && yarn) && NODE_PATH=./test/leak/node_modules node --no-warnings ./node_modules/.bin/tape \"test/leak/plugins/@($(echo $PLUGINS)).js\""
},
Expand Down
7 changes: 6 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class Config {
const debug = coalesce(options.debug, platform.env('DD_TRACE_DEBUG'), false)
const env = coalesce(options.env, platform.env('DD_ENV'))
const protocol = 'http'
const hostname = coalesce(options.hostname, platform.env('DD_TRACE_AGENT_HOSTNAME'), 'localhost')
const hostname = coalesce(
options.hostname,
platform.env('DD_AGENT_HOST'),
platform.env('DD_TRACE_AGENT_HOSTNAME'),
'localhost'
)
const port = coalesce(options.port, platform.env('DD_TRACE_AGENT_PORT'), 8126)
const sampleRate = coalesce(Math.min(Math.max(options.sampleRate, 0), 1), 1)
const flushInterval = coalesce(parseInt(options.flushInterval, 10), 2000)
Expand Down
36 changes: 24 additions & 12 deletions src/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ shimmer({ logger: () => {} })
class Instrumenter {
constructor (tracer) {
this._tracer = tracer
this._names = []
this._names = new Set()
this._plugins = new Map()
this._instrumented = new Map()
}
Expand Down Expand Up @@ -61,28 +61,38 @@ class Instrumenter {
const instrumentedModules = uniq(instrumentations
.map(instrumentation => instrumentation.name))

this._names = instrumentations
.map(instrumentation => filename(instrumentation))
this._names = new Set(instrumentations
.map(instrumentation => filename(instrumentation)))

hook(instrumentedModules, { internals: true }, this.hookModule.bind(this))
}

wrap (nodule, name) {
if (typeof nodule[name] !== 'function') {
throw new Error(`Expected object ${nodule} to contain method ${name}.`)
}
wrap (nodules, names, wrapper) {
nodules = [].concat(nodules)
names = [].concat(names)

nodules.forEach(nodule => {
names.forEach(name => {
if (typeof nodule[name] !== 'function') {
throw new Error(`Expected object ${nodule} to contain method ${name}.`)
}
})
})

return shimmer.wrap.apply(this, arguments)
return shimmer.massWrap.call(this, nodules, names, wrapper)
}

unwrap () {
return shimmer.unwrap.apply(this, arguments)
unwrap (nodules, names, wrapper) {
nodules = [].concat(nodules)
names = [].concat(names)

return shimmer.massUnwrap.call(this, nodules, names, wrapper)
}

hookModule (moduleExports, moduleName, moduleBaseDir) {
moduleName = moduleName.replace(pathSepExpr, '/')

if (this._names.indexOf(moduleName) === -1) {
if (!this._names.has(moduleName)) {
return moduleExports
}

Expand All @@ -93,7 +103,9 @@ class Instrumenter {
const moduleVersion = getVersion(moduleBaseDir)

Array.from(this._plugins.keys())
.filter(plugin => [].concat(plugin).some(instrumentation => filename(instrumentation) === moduleName))
.filter(plugin => [].concat(plugin).some(instrumentation =>
filename(instrumentation) === moduleName && matchVersion(moduleVersion, instrumentation.versions)
))
.forEach(plugin => this._validate(plugin, moduleBaseDir))

this._plugins
Expand Down
4 changes: 1 addition & 3 deletions src/opentracing/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ class DatadogTracer extends Tracer {
const references = getReferences(fields.references)
const parent = getParent(references)
const tags = {
'resource.name': name
'service.name': this._service
}

tags['service.name'] = this._service

if (this._env) {
tags.env = this._env
}
Expand Down
16 changes: 16 additions & 0 deletions src/plugins/bluebird.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const tx = require('./util/promise')

module.exports = [
{
name: 'bluebird',
versions: ['2.0.2 - 3'], // 2.0.0 and 2.0.1 were removed from npm
patch (Promise, tracer, config) {
this.wrap(Promise.prototype, '_then', tx.createWrapThen(tracer, config))
},
unpatch (Promise) {
this.unwrap(Promise.prototype, '_then')
}
}
]
2 changes: 1 addition & 1 deletion src/plugins/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = [
{
name: 'elasticsearch',
file: 'src/lib/transport.js',
versions: ['15.x'],
versions: ['>=10 <=15'],
patch (Transport, tracer, config) {
this.wrap(Transport.prototype, 'request', createWrapRequest(tracer, config))
},
Expand Down
Loading

0 comments on commit 94870e1

Please sign in to comment.