diff --git a/README.md b/README.md index 0ff0a9b..688ebce 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/example/server-pg.js b/example/server-pg.js index 62dda66..f20ee12 100644 --- a/example/server-pg.js +++ b/example/server-pg.js @@ -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' + } } }) diff --git a/example/server1.js b/example/server1.js index 7ea7dd3..c888201 100644 --- a/example/server1.js +++ b/example/server1.js @@ -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' + } } }) diff --git a/example/server2.js b/example/server2.js index 9d98fe7..806b1f0 100644 --- a/example/server2.js +++ b/example/server2.js @@ -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') diff --git a/package-lock.json b/package-lock.json index 5c6eea3..1e1c81a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@risingstack/jaeger", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 1, "dependencies": { "accepts": { @@ -1666,11 +1666,6 @@ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true }, - "opentracing": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/opentracing/-/opentracing-0.14.1.tgz", - "integrity": "sha1-QNJ4vupBdmCjXdnT7nZRH/qRHc0=" - }, "optionator": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", diff --git a/package.json b/package.json index 5c4fe69..b6b25e5 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/instrumentation/express.js b/src/instrumentation/express.js index ac1d27e..da5e2d1 100644 --- a/src/instrumentation/express.js +++ b/src/instrumentation/express.js @@ -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') diff --git a/src/instrumentation/expressError.js b/src/instrumentation/expressError.js index 81992ad..5523341 100644 --- a/src/instrumentation/expressError.js +++ b/src/instrumentation/expressError.js @@ -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') diff --git a/src/instrumentation/httpClient.js b/src/instrumentation/httpClient.js index 54436ec..32ac97e 100644 --- a/src/instrumentation/httpClient.js +++ b/src/instrumentation/httpClient.js @@ -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 diff --git a/src/instrumentation/mongodbCore.js b/src/instrumentation/mongodbCore.js index 7c0d9b1..88cd662 100644 --- a/src/instrumentation/mongodbCore.js +++ b/src/instrumentation/mongodbCore.js @@ -1,6 +1,6 @@ 'use strict' -const opentracing = require('opentracing') +const { opentracing } = require('jaeger-client') const shimmer = require('shimmer') const cls = require('../cls') diff --git a/src/instrumentation/pg.js b/src/instrumentation/pg.js index b64d65a..122cc55 100644 --- a/src/instrumentation/pg.js +++ b/src/instrumentation/pg.js @@ -1,6 +1,6 @@ 'use strict' -const opentracing = require('opentracing') +const { opentracing } = require('jaeger-client') const shimmer = require('shimmer') const cls = require('../cls') diff --git a/src/tracer.js b/src/tracer.js index 6b3913b..47b7d65 100644 --- a/src/tracer.js +++ b/src/tracer.js @@ -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) => {