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
1 change: 1 addition & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ query HelloWorld {
| 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. |

<h3 id="mongodb-core">mongodb-core</h3>

Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config {

const enabled = coalesce(options.enabled, platform.env('DD_TRACE_ENABLED'), true)
const debug = coalesce(options.debug, platform.env('DD_TRACE_DEBUG'), false)
const service = coalesce(options.service, platform.env('DD_SERVICE_NAME'), platform.service())
const service = coalesce(options.service, platform.env('DD_SERVICE_NAME'), platform.service(), 'node')
const env = coalesce(options.env, platform.env('DD_ENV'))
const protocol = 'http'
const hostname = coalesce(options.hostname, platform.env('DD_TRACE_AGENT_HOSTNAME'), 'localhost')
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/amqplib.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function createWrapDispatchMessage (tracer, config) {
return function dispatchMessageWithTrace (fields, message) {
const span = tracer.startSpan('amqp.command')

addTags(this, config, span, 'basic.deliver', fields)
addTags(this, tracer, config, span, 'basic.deliver', fields)

setImmediate(() => {
tracer.scopeManager().activate(span, true)
Expand All @@ -46,7 +46,7 @@ function sendWithTrace (send, channel, args, tracer, config, method, fields) {
childOf: parentScope && parentScope.span()
})

addTags(channel, config, span, method, fields)
addTags(channel, tracer, config, span, method, fields)

try {
return send.apply(channel, args)
Expand Down Expand Up @@ -82,7 +82,7 @@ function addError (span, error) {
return error
}

function addTags (channel, config, span, method, fields) {
function addTags (channel, tracer, config, span, method, fields) {
const fieldNames = [
'queue',
'exchange',
Expand All @@ -93,7 +93,7 @@ function addTags (channel, config, span, method, fields) {
]

span.addTags({
'service.name': config.service || 'amqp',
'service.name': config.service || `${tracer._service}-amqp`,
'resource.name': getResourceName(method, fields),
'span.type': 'worker'
})
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function createWrapRequest (tracer, config) {
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
[Tags.DB_TYPE]: 'elasticsearch',
'service.name': config.service || 'elasticsearch',
'service.name': config.service || `${tracer._service}-elasticsearch`,
'resource.name': `${params.method} ${quantizePath(params.path)}`,
'span.type': 'db',
'span.type': 'elasticsearch',
'elasticsearch.url': params.path,
'elasticsearch.method': params.method,
'elasticsearch.params': JSON.stringify(params.query)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function createWrapMethod (tracer, config) {
}

span.setTag('service.name', config.service || tracer._service)
span.setTag('span.type', 'web')
span.setTag('span.type', 'http')
span.setTag(Tags.HTTP_STATUS_CODE, res.statusCode)

if (!validateStatus(res.statusCode)) {
Expand Down
49 changes: 39 additions & 10 deletions src/plugins/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ function patch (http, tracer, config) {

let isFinish = false

options = typeof options === 'string' ? url.parse(uri) : Object.assign({}, options)
options.headers = options.headers || {}

const parentScope = tracer.scopeManager().active()
const parent = parentScope && parentScope.span()
const span = tracer.startSpan('http.request', {
childOf: parentScope && parentScope.span(),
childOf: parent,
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
'service.name': config.service || 'http-client',
'service.name': getServiceName(tracer, config, options),
'resource.name': method,
'span.type': 'web',
'http.method': method,
'http.url': uri
}
})

options = typeof options === 'string' ? url.parse(uri) : Object.assign({}, options)
options.headers = options.headers || {}

tracer.inject(span, FORMAT_HTTP_HEADERS, options.headers)

const req = request.call(this, options, res => {
Expand Down Expand Up @@ -83,13 +84,41 @@ function patch (http, tracer, config) {
}
}

function getHost (options) {
if (typeof options === 'string') {
return url.parse(options).host
}

const hostname = options.hostname || options.host || 'localhost'
const port = options.port

return [hostname, port].filter(val => val).join(':')
}

function getServiceName (tracer, config, options) {
if (config.splitByDomain) {
return getHost(options)
} else if (config.service) {
return config.service
}

return `${tracer._service}-http-client`
}

function unpatch (http) {
this.unwrap(http, 'request')
this.unwrap(http, 'get')
}

module.exports = {
name: 'http',
patch,
unpatch
}
module.exports = [
{
name: 'http',
patch,
unpatch
},
{
name: 'https',
patch,
unpatch
}
]
9 changes: 0 additions & 9 deletions src/plugins/https.js

This file was deleted.

10 changes: 5 additions & 5 deletions src/plugins/mongodb-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function createWrapOperation (tracer, config, operationName) {
childOf: parentScope && parentScope.span()
})

addTags(span, config, resource, ns, this)
addTags(span, tracer, config, resource, ns, this)

if (typeof options === 'function') {
return operation.call(this, ns, ops, wrapCallback(tracer, span, options))
Expand All @@ -214,7 +214,7 @@ function createWrapNext (tracer, config) {
childOf: parentScope && parentScope.span()
})

addTags(span, config, resource, this.ns, this.topology)
addTags(span, tracer, config, resource, this.ns, this.topology)

if (this.cursorState) {
span.addTags({
Expand All @@ -227,11 +227,11 @@ function createWrapNext (tracer, config) {
}
}

function addTags (span, config, resource, ns, topology) {
function addTags (span, tracer, config, resource, ns, topology) {
span.addTags({
'service.name': config.service || 'mongodb',
'service.name': config.service || `${tracer._service}-mongodb`,
'resource.name': resource,
'span.type': 'db',
'span.type': 'mongodb',
'db.name': ns
})

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createWrapQuery (tracer, config) {
childOf: parent,
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
'service.name': config.service || 'mysql',
'service.name': config.service || `${tracer._service}-mysql`,
'span.type': 'sql',
'db.type': 'mysql',
'db.user': this.config.user,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mysql2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createWrapQuery (tracer, config) {
childOf: parent,
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
'service.name': config.service || 'mysql',
'service.name': config.service || `${tracer._service}-mysql`,
'span.type': 'sql',
'db.type': 'mysql',
'db.user': this.config.user,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function patch (pg, tracer, config) {
childOf: parent,
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
'service.name': config.service || 'postgres',
'service.name': config.service || `${tracer._service}-postgres`,
'resource.name': statement,
'span.type': 'sql',
'db.type': 'postgres'
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function createWrapInternalSendCommand (tracer, config) {
tags: {
[Tags.SPAN_KIND]: Tags.SPAN_KIND_RPC_CLIENT,
[Tags.DB_TYPE]: 'redis',
'service.name': config.service || 'redis',
'service.name': config.service || `${tracer._service}-redis`,
'resource.name': options.command,
'span.type': 'db',
'span.type': 'redis',
'db.name': this.selected_db || '0'
}
})
Expand Down
11 changes: 9 additions & 2 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('Config', () => {
env: sinon.stub(),
service: sinon.stub()
}
platform.service.returns('test')

Config = proxyquire('../src/config', {
'./platform': platform
Expand All @@ -19,7 +18,7 @@ describe('Config', () => {
it('should initialize with the correct defaults', () => {
const config = new Config()

expect(config).to.have.property('service', 'test')
expect(config).to.have.property('service', 'node')
expect(config).to.have.property('enabled', true)
expect(config).to.have.property('debug', false)
expect(config).to.have.nested.property('url.protocol', 'http:')
Expand All @@ -33,6 +32,14 @@ describe('Config', () => {
expect(config).to.have.property('env', undefined)
})

it('should initialize from the platform', () => {
platform.service.returns('test')

const config = new Config()

expect(config).to.have.property('service', 'test')
})

it('should initialize from environment variables', () => {
platform.env.withArgs('DD_TRACE_AGENT_HOSTNAME').returns('agent')
platform.env.withArgs('DD_TRACE_AGENT_PORT').returns('6218')
Expand Down
8 changes: 4 additions & 4 deletions test/plugins/amqplib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Plugin', () => {
const span = traces[0][0]

expect(span).to.have.property('name', 'amqp.command')
expect(span).to.have.property('service', 'amqp')
expect(span).to.have.property('service', 'test-amqp')
expect(span).to.have.property('resource', 'queue.declare test')
expect(span).to.have.property('type', 'worker')
expect(span.meta).to.have.property('out.host', 'localhost')
Expand All @@ -68,7 +68,7 @@ describe('Plugin', () => {
const span = traces[0][0]

expect(span).to.have.property('name', 'amqp.command')
expect(span).to.have.property('service', 'amqp')
expect(span).to.have.property('service', 'test-amqp')
expect(span).to.have.property('resource', 'queue.delete test')
expect(span).to.have.property('type', 'worker')
expect(span.meta).to.have.property('out.host', 'localhost')
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('Plugin', () => {
const span = traces[0][0]

expect(span).to.have.property('name', 'amqp.command')
expect(span).to.have.property('service', 'amqp')
expect(span).to.have.property('service', 'test-amqp')
expect(span).to.have.property('resource', 'basic.publish exchange routingKey')
expect(span).to.have.property('type', 'worker')
expect(span.meta).to.have.property('out.host', 'localhost')
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('Plugin', () => {
const span = traces[0][0]

expect(span).to.have.property('name', 'amqp.command')
expect(span).to.have.property('service', 'amqp')
expect(span).to.have.property('service', 'test-amqp')
expect(span).to.have.property('resource', `basic.deliver ${queue}`)
expect(span).to.have.property('type', 'worker')
expect(span.meta).to.have.property('out.host', 'localhost')
Expand Down
8 changes: 4 additions & 4 deletions test/plugins/elasticsearch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ describe('Plugin', () => {
it('should do automatic instrumentation', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'elasticsearch')
expect(traces[0][0]).to.have.property('service', 'test-elasticsearch')
expect(traces[0][0]).to.have.property('resource', 'HEAD /')
expect(traces[0][0]).to.have.property('type', 'db')
expect(traces[0][0]).to.have.property('type', 'elasticsearch')
})
.then(done)
.catch(done)
Expand Down Expand Up @@ -142,9 +142,9 @@ describe('Plugin', () => {
it('should do automatic instrumentation', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'elasticsearch')
expect(traces[0][0]).to.have.property('service', 'test-elasticsearch')
expect(traces[0][0]).to.have.property('resource', 'HEAD /')
expect(traces[0][0]).to.have.property('type', 'db')
expect(traces[0][0]).to.have.property('type', 'elasticsearch')
})
.then(done)
.catch(done)
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/express.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Plugin', () => {
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('type', 'http')
expect(traces[0][0]).to.have.property('resource', 'GET /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`)
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Plugin', () => {
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('type', 'http')
expect(traces[0][0]).to.have.property('resource', 'GET /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`)
Expand Down
Loading