Skip to content

Commit

Permalink
feat(tracer): jaeger-client interface
Browse files Browse the repository at this point in the history
BREAKING CHANGE: tracer constructor is now follows jaeger-client
  • Loading branch information
Peter Marton committed Jul 4, 2017
1 parent 90f04bf commit f153326
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 44 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,23 @@ open http://localhost:16686

## API

### new Tracer(options)
### new Tracer(args)

Create a new Tracer and instrument modules.

- `options.serviceName`: Name of your service
- `args.serviceName`: Name of your service
- **required**
- example: `'my-service-1'`
- `options.tags`: Meta tags
- `args.sampler`: Jaeger sampler, see [sampler docs](https://github.com/uber/jaeger-client-node/tree/master/src/samplers)
- *optional*
- example: `{ gitHash: 'foobar' }`
- `options.maxSamplesPerSecond`: maximum number of samples per second
- default: `new jaeger.RateLimitingSampler(1)`
- `args.reporter`: Jaeger sampler, see [reporter docs](https://github.com/uber/jaeger-client-node/tree/master/src/reporters)
- *optional*
- default: `1`
- `options.sender`: sender configuration *(Your Jaeger backend)*
- default: `new jaeger.RemoteReporter(new UDPSender())`
- `args.options`: Jaeger options, see [docs](https://github.com/uber/jaeger-client-node#initialization)
- *optional*
- default: `{ host: 'localhost', port: 6832, maxPacketSize: 65000 }`
- example: `{ tags: { gitHash: 'foobar' } }`


## Instrumentations

Expand All @@ -89,4 +90,3 @@ Create a new Tracer and instrument modules.
- more database instrumentation: MySQL, Redis etc.
- messaging broker instrumentation: RabbitMQ, Kafka etc.
- test coverage
- multiple sampling algorithms
6 changes: 4 additions & 2 deletions example/server-pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const Tracer = require('../src')
// eslint-disable-next-line
const tracer = new Tracer({
serviceName: 'my-server-pg',
tags: {
gitTag: 'foobar'
options: {
tags: {
gitTag: 'foobar'
}
}
})

Expand Down
6 changes: 4 additions & 2 deletions example/server1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const Tracer = require('../src')
// eslint-disable-next-line
const tracer = new Tracer({
serviceName: 'my-server-1',
tags: {
gitTag: 'foobar'
options: {
tags: {
gitTag: 'foo'
}
}
})

Expand Down
6 changes: 4 additions & 2 deletions example/server2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const Tracer = require('../src')
// eslint-disable-next-line
const tracer = new Tracer({
serviceName: 'my-server-2',
tags: {
gitTag: 'foobar'
options: {
tags: {
gitTag: 'bar'
}
}
})
const express = require('express')
Expand Down
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"jaeger-client": "3.5.3",
"lodash": "4.17.4",
"methods": "1.1.2",
"opentracing": "0.14.1",
"require-in-the-middle": "2.1.2",
"semver": "5.3.0",
"shimmer": "1.1.0"
Expand Down
3 changes: 1 addition & 2 deletions src/instrumentation/express.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

const opentracing = require('opentracing')
const shimmer = require('shimmer')
const SpanContext = require('jaeger-client').SpanContext
const { opentracing } = require('jaeger-client')
const methods = require('methods').concat('use', 'route', 'param', 'all')
const cls = require('../cls')
const { isExpressV4 } = require('./util')
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/expressError.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const shimmer = require('shimmer')
const opentracing = require('opentracing')
const { opentracing } = require('jaeger-client')
const cls = require('../cls')
const { isExpressV4 } = require('./util')

Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/httpClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const url = require('url')
const opentracing = require('opentracing')
const { opentracing } = require('jaeger-client')
const shimmer = require('shimmer')
const _ = require('lodash')
// eslint-disable-next-line
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/mongodbCore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const opentracing = require('opentracing')
const { opentracing } = require('jaeger-client')
const shimmer = require('shimmer')
const cls = require('../cls')

Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/pg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const opentracing = require('opentracing')
const { opentracing } = require('jaeger-client')
const shimmer = require('shimmer')
const cls = require('../cls')

Expand Down
26 changes: 10 additions & 16 deletions src/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,30 @@ const instrumentations = require('./instrumentation')
class Tracer {
constructor ({
serviceName,
tags = {},
maxSamplesPerSecond = 1,
sender = {},
logger = undefined
sampler = new jaeger.RateLimitingSampler(1),
reporter = new jaeger.RemoteReporter(new UDPSender()),
options = {}
}) {
const senderOptions = _.defaults(sender, {
host: 'localhost',
port: 6832,
maxPacketSize: 65000
})
const udpSender = new UDPSender(senderOptions)
const reporter = new jaeger.RemoteReporter(udpSender)
const sampler = new jaeger.RateLimitingSampler(maxSamplesPerSecond)
if (!serviceName) {
throw new Error('serviceName is required')
}

this._tracer = new jaeger.Tracer(serviceName, reporter, sampler, {
logger,
tags
})
this._tracer = new jaeger.Tracer(serviceName, reporter, sampler, options)

const instrumentedModules = _.uniq(instrumentations.map((instrumentation) => instrumentation.module))

// Instrunent modules: hook require
hook(instrumentedModules, (moduleExports, moduleName, moduleBaseDir) => {
let moduleVersion

// Look for version in package.json
if (moduleBaseDir) {
const packageJSON = path.join(moduleBaseDir, 'package.json')
// eslint-disable-next-line
moduleVersion = require(packageJSON).version
}

// Apply instrumentations
instrumentations
.filter((instrumentation) => instrumentation.module === moduleName)
.filter((instrumentation) => {
Expand Down

0 comments on commit f153326

Please sign in to comment.