diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index e020256..0000000 --- a/.eslintrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "extends": "eslint-config-airbnb", - "env": { - "browser": true, - "mocha": true, - "node": true - }, - "globals": { - }, - "rules": { - "consistent-return": [0], - "func-names": [0], - "guard-for-in": [0], - "indent": [2, 4], - "key-spacing": [2, { "align": "colon", "beforeColon": true, "afterColon": true }], - "max-len": [2, 120, 4], - "no-console": [1], - "no-underscore-dangle": [0], - "no-multi-spaces": [2, { "exceptions": { - "AssignmentExpression": true, - "VariableDeclarator": true, - }} ], - "no-param-reassign": [0], - "no-unused-vars": [2, { "vars": "all", "args" : "none" }], - "object-shorthand": [2, "never" ], - "prefer-const": [0], - "prefer-rest-params" : [0], - "spaced-comment": [0], // Disabled as the "exceptions" clause does not seem to currently work - "strict": [0] - } -} diff --git a/.gitignore b/.gitignore index 73944b4..0c699ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ node_modules/ npm-debug.log -dist/* -coverage/* +coverage/ +typedoc/ +dist/ +lib/ +.DS_Store diff --git a/.npmignore b/.npmignore index 1ca9571..8a5e1b2 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,5 @@ node_modules/ npm-debug.log +src/ +typedoc/ +coverage/ diff --git a/.travis.yml b/.travis.yml index 6f8ec5e..dec1500 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,21 @@ + language: node_js + node_js: - - 0.12 -after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" + - 4 + +script: + - npm run lint + - npm run build + - npm run test-cover + +after_script: + - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js + +before_deploy: + - npm run typedoc +deploy: + provider: surge + project: ./typedoc/ + domain: opentracing-javascript.surge.sh + skip_cleanup: true diff --git a/Makefile b/Makefile deleted file mode 100644 index a1a413d..0000000 --- a/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# http://stackoverflow.com/questions/3774568/makefile-issue-smart-way-to-scan-directory-tree-for-c-files -recursive_wildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call recursive_wildcard,$d/,$2)) - -CMD_BABEL = node node_modules/babel-cli/bin/babel.js -SOURCES_JS = $(call recursive_wildcard,src/,*.js) -COMPILED_PROD_JS = $(SOURCES_JS:src/%.js=lib/%.js) -COMPILED_DEBUG_JS = $(SOURCES_JS:src/%.js=lib-debug/%.js) -DST_BROWSER = \ - dist/opentracing-browser.js \ - dist/opentracing-browser.min.js - -.PHONY: build -build: node_modules build-node build-browser - -# Compiles the ES6 source down to ES5 for greater compatibility across versions -# of node. -# -# Also builds a 'lib-debug' version of the library that will do additional -# runtime checks to help diagnose problems. -.PHONY: build-node -build-node: node_modules package.json $(COMPILED_PROD_JS) $(COMPILED_DEBUG_JS) -lib/%.js: src/%.js - mkdir -p $(@D) - NODE_ENV=production $(CMD_BABEL) --presets es2015 --plugins transform-node-env-inline-and-fold $< -o $@ --source-maps -lib-debug/%.js: src/%.js - mkdir -p $(@D) - $(CMD_BABEL) --presets es2015 $< -o $@ --source-maps - -# Use webpack to build a minified production bundle ande debug bundle for the -# browser -.PHONY: build-browser -build-browser: $(DST_BROWSER) webpack.config.js package.json -$(DST_BROWSER): $(SOURCES_JS) - npm run webpack - -node_modules: - npm install - -.PHONY: clean -clean: - rm -rf node_modules/ - rm -rf lib/ && mkdir lib - rm -rf lib-debug/ && mkdir lib-debug - rm -rf dist/apidoc - rm dist/* - -.PHONY: lint -lint: - node node_modules/eslint/bin/eslint.js --fix --color src - -# NOTE: `npm version` automatically creates a git commit and git tag for the -# incremented version -.PHONY: publish -publish: test - npm version patch - make build # need to rebuild with the new version number - git push - git push --tags - npm publish - -.PHONY: test -test: build - node node_modules/eslint/bin/eslint.js --color src - npm test - -# A target that runs the unit tests without code coverage testing, as the code -# coverage testing throws off the source code line number information - making -# failures more difficult to debug. -.PHONY: test-no-coverage -test-no-coverage: build - NODE_ENV=debug node ./node_modules/.bin/_mocha test/unittest.js --check-leaks --color - -.PHONY: test-all -test-all: build - scripts/docker_test.sh latest - scripts/docker_test.sh 5.8 - scripts/docker_test.sh 4.4 - scripts/docker_test.sh 0.12 - -.PHONY: example -example: build - NODE_ENV=debug node ./lib-debug/examples/demo/demo.js diff --git a/README.md b/README.md index 6219530..4f5e089 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ npm install --save opentracing The package contains a example using a naive `MockTracer` implementation. To run the example: ```bash -make example +npm run example ``` The output should look something like: @@ -42,32 +42,32 @@ Spans: In your JavaScript code, add instrumentation to the operations to be tracked. This is composed primarily of using "spans" around operations of interest and adding log statements to capture useful data relevant to those operations. ```js -var http = require('http'); -var opentracing = require('opentracing'); +const http = require('http'); +const opentracing = require('opentracing'); // NOTE: the default OpenTracing tracer does not record any tracing information. // Replace this line with the tracer implementation of your choice. -var tracer = new opentracing.Tracer(); +const tracer = new opentracing.Tracer(); -var span = tracer.startSpan('http_request'); -var opts = { +const span = tracer.startSpan('http_request'); +const opts = { host : 'example.com', method: 'GET', port : '80', path: '/', }; -http.request(opts, function (res) { +http.request(opts, res => { res.setEncoding('utf8'); - res.on('error', function (err) { + res.on('error', err => { // assuming no retries, mark the span as failed span.setTag(opentracing.Tags.ERROR, true); - span.log({'event': 'error', 'error.object': err); + span.log({'event': 'error', 'error.object': err, 'message': err.message, 'stack': err.stack}); span.finish(); }); - res.on('data', function (chunk) { + res.on('data', chunk => { span.log({'event': 'data_received', 'data': chunk}); }); - res.on('end', function() { + res.on('end', () { span.log({'event': 'request_end'}); span.finish(); }); @@ -77,17 +77,22 @@ http.request(opts, function (res) { As noted in the source snippet, the default behavior of the `opentracing` package is to act as a "no op" implementation. To capture and make the tracing data actionable, the `tracer` object should be initialized with the OpenTracing implementation of your choice as in the pseudo-code below: ```js -var CustomTracer = require('tracing-implementation-of-your-choice'); -var tracer = new CustomTracer(); +const CustomTracer = require('tracing-implementation-of-your-choice'); +const tracer = new CustomTracer(); ``` ### Usage in the browser -The package contains two bundles built with webpack that can be included using a standard `