fastify-jaeger
Advanced tools
Comparing version 1.0.0 to 1.0.1
15
index.js
@@ -12,6 +12,5 @@ 'use strict' | ||
assert(opts.serviceName, 'Jaeger Plugin requires serviceName option') | ||
const { state = {}, initTracerOpts = {}, ...tracerConfig } = opts | ||
const exposeAPI = opts.exposeAPI !== false | ||
const { state } = opts | ||
const tracerConfig = { | ||
serviceName: opts.serviceName, | ||
const defaultConfig = { | ||
sampler: { | ||
@@ -26,10 +25,11 @@ type: 'const', | ||
const tracerOptions = { | ||
const defaultOptions = { | ||
logger: fastify.log | ||
} | ||
const tracerDefaults = { state, ...opts } | ||
const tracer = initTracer( | ||
{ ...defaultConfig, ...tracerConfig }, | ||
{ ...defaultOptions, ...initTracerOpts } | ||
) | ||
const tracer = initTracer({ ...tracerConfig, ...tracerDefaults }, { ...tracerOptions, ...tracerDefaults }) | ||
const tracerMap = new WeakMap() | ||
@@ -78,2 +78,3 @@ | ||
span.setTag(Tags.HTTP_STATUS_CODE, reply.res.statusCode) | ||
span.finish() | ||
done() | ||
@@ -80,0 +81,0 @@ } |
{ | ||
"name": "fastify-jaeger", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Fastify plugin for Jaeger distributed tracing system", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,4 +19,7 @@ # fastify-jaeger | ||
This plugins supports all other options and configurations of the official [jaeger-client-node](https://github.com/jaegertracing/jaeger-client-node) throught the options object of the plugin. | ||
This plugins supports all options and configurations of [jaeger-client-node's `initTracer` method](https://github.com/jaegertracing/jaeger-client-node#initialization). | ||
- The options param can be configured via `opts.initTracerOpts` | ||
- All other top-level `opts` will be passed in as the config param. | ||
It uses the logger set to the fastify instance as the tracer logger. | ||
@@ -37,3 +40,3 @@ | ||
if (err) throw err | ||
console.log('Server listenting on localhost:', fastify.server.address().port) | ||
console.log('Server listening on localhost:', fastify.server.address().port) | ||
}) | ||
@@ -40,0 +43,0 @@ ``` |
@@ -34,5 +34,9 @@ 'use strict' | ||
test('Should initialize plugin with default configuration', async ({ teardown, is, has }) => { | ||
delete require.cache[require.resolve('jaeger-client')] | ||
delete require.cache[require.resolve(require('path').join(__dirname, '../index'))] | ||
const setupTracerTest = (pluginOpts) => { | ||
const clear = () => { | ||
delete require.cache[require.resolve('jaeger-client')] | ||
delete require.cache[require.resolve(require('path').join(__dirname, '../index'))] | ||
} | ||
clear() | ||
require('jaeger-client') | ||
@@ -43,18 +47,55 @@ const initTracerSpy = spy(require.cache[require.resolve('jaeger-client')].exports.initTracer) | ||
const fastify = createFastify() | ||
fastify.get('/', (req, reply) => { | ||
reply.code(200).send({ hello: 'world' }) | ||
}) | ||
teardown(async () => { | ||
delete require.cache[require.resolve('jaeger-client')] | ||
delete require.cache[require.resolve(require('path').join(__dirname, '../index'))] | ||
await fastify.close() | ||
fastify.register(require('../index'), pluginOpts) | ||
return { | ||
fastify, | ||
initTracerSpy, | ||
teardownCb: async () => { | ||
clear() | ||
await fastify.close() | ||
} | ||
} | ||
} | ||
test('should use default config when no configuration is provided', async ({ teardown, is, has }) => { | ||
const { fastify, initTracerSpy, teardownCb } = setupTracerTest({ serviceName: 'test' }) | ||
teardown(teardownCb) | ||
await fastify.ready() | ||
const response = await fastify.inject({ method: 'GET', url: '/' }) | ||
is(initTracerSpy.spy.calls.length, 1) | ||
has(initTracerSpy.spy.calls[0][0], { | ||
serviceName: 'test', | ||
sampler: { type: 'const', param: 1 }, | ||
reporter: { logSpans: false } | ||
}) | ||
has(initTracerSpy.spy.calls[0][1], { logger: fastify.log }) | ||
is(fastify.hasRequestDecorator('jaeger'), true) | ||
is(response.statusCode, 200) | ||
}) | ||
fastify.get('/', (req, reply) => { | ||
reply.code(200).send({ hello: 'world' }) | ||
test('should merge default config with the user provided config', async ({ teardown, is, has }) => { | ||
const { fastify, initTracerSpy, teardownCb } = setupTracerTest({ | ||
serviceName: 'test', | ||
reporter: { | ||
logSpans: true | ||
}, | ||
initTracerOpts: { | ||
tags: { | ||
foo: 'bar' | ||
} | ||
} | ||
}) | ||
fastify.register(require('../index'), { serviceName: 'test' }) | ||
teardown(teardownCb) | ||
await fastify.ready() | ||
const response = await fastify.inject({ method: 'GET', url: '/' }) | ||
const response = await fastify.inject({ method: 'GET', url: '/' }) | ||
is(initTracerSpy.spy.calls.length, 1) | ||
@@ -64,13 +105,12 @@ has(initTracerSpy.spy.calls[0][0], { | ||
sampler: { type: 'const', param: 1 }, | ||
reporter: { logSpans: false }, | ||
state: undefined | ||
reporter: { logSpans: true } | ||
}) | ||
has(initTracerSpy.spy.calls[0][1], { | ||
state: undefined, | ||
serviceName: 'test' | ||
logger: fastify.log, | ||
tags: { | ||
foo: 'bar' | ||
} | ||
}) | ||
has(initTracerSpy.spy.results[0].value, { _tags: { foo: 'bar' } }) | ||
is(fastify.hasRequestDecorator('jaeger'), true) | ||
is(initTracerSpy.spy.calls[0][1].logger, fastify.log) | ||
is(response.statusCode, 200) | ||
@@ -77,0 +117,0 @@ }) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12181
276
46
1
0