Skip to content

Commit

Permalink
* Added support for feathers-distribution
Browse files Browse the repository at this point in the history
* Updated docs with Mac OS X issue workaround
* Bumped version to 2.1.1
  • Loading branch information
Dekel committed Aug 18, 2018
1 parent b96a016 commit e2e58ab
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ await hook.app.service('users').get(id, {
rootSpan: hook.params.rootSpan,
});
```

## Mac OS X
Run once `sudo sysctl -w net.inet.udp.maxdgram=65535` to prevent UDP buffer size errors.
30 changes: 27 additions & 3 deletions hooks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
const opentracing = require('opentracing');
const { tagDefaults, mask } = require('./utils');

const UBER_TRACE_ID = 'uber-trace-id';

const opentracingBegin = (options = {}) => {
return async context => {
const { path, method, id, data, params, service } = context;
const tracer = opentracing.globalTracer();

if (service.remote) {
const remoteHeaders = {};
tracer.inject(params.rootSpan, opentracing.FORMAT_TEXT_MAP, remoteHeaders);
params.rootSpan = remoteHeaders[UBER_TRACE_ID];

return context;
}

options.tag = { ...tagDefaults, ...options.tag };

const { path, method, id, data, params } = context;
const { rootSpan, firstEndpoint, query } = params;
const tracer = opentracing.globalTracer();
const span = firstEndpoint ? rootSpan : tracer.startSpan(path, { childOf: rootSpan });
let span = null;

if (typeof rootSpan === 'string') {
const wire = tracer.extract(opentracing.FORMAT_TEXT_MAP, { [UBER_TRACE_ID]: rootSpan });
span = tracer.startSpan(path, { childOf: wire });
} else {
span = firstEndpoint ? rootSpan : tracer.startSpan(path, { childOf: rootSpan });
}

if (!params.firstEndpoint) {
span.log({ event: 'request_received' });
Expand Down Expand Up @@ -39,6 +57,9 @@ const opentracingBegin = (options = {}) => {

const opentracingEnd = (options = {}) => {
return async context => {
if (context.service.remote)
return context;

options.tag = { ...tagDefaults, ...options.tag };

const { params, result, dispatch } = context;
Expand All @@ -62,6 +83,9 @@ const opentracingEnd = (options = {}) => {

const opentracingError = () => {
return async context => {
if (context.service.remote)
return context;

const { params } = context;
const { span } = params;
const { code, message, stack } = context.error;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "feathers-opentracing",
"version": "2.1.0",
"version": "2.1.1",
"description": "OpenTracing integration for FeathersJS services",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit e2e58ab

Please sign in to comment.