egg-jaeger
Advanced tools
Comparing version
'use strict'; | ||
const hookSequelize = require('./lib/hookSequelize'); | ||
const hooks = require('./lib/hooks'); | ||
module.exports = (app) => { | ||
module.exports = app => { | ||
app.beforeStart(async () => { | ||
app.als.enable(); | ||
hookSequelize(app); | ||
hooks(app); | ||
}); | ||
@@ -10,0 +10,0 @@ // put before other core middlewares |
'use strict'; | ||
const cluster = require('cluster'); | ||
const address = require('address'); | ||
const cacheJaeger = Symbol('jaeger_client_tracer'); | ||
@@ -7,2 +9,6 @@ const { initTracer, opentracing } = require('jaeger-client'); | ||
const WORKER_ID = cluster.worker ? cluster.worker.id : 0; | ||
const IPV4 = address.ip(); | ||
const IPV6 = address.ipv6(); | ||
module.exports = { | ||
@@ -22,7 +28,12 @@ get als() { | ||
startSpan(name, tags = {}) { | ||
const childOf = als.getFromParent('span'); | ||
this.coreLogger.debug('[egg-jaeger] startSpan %s', name); | ||
tags['worker.id'] = WORKER_ID; | ||
tags['process.id'] = process.pid; | ||
tags['local.ipv4'] = IPV4; | ||
tags['local.ipv6'] = IPV6; | ||
const childOf = this.als.getFromParent('span'); | ||
const span = this.jaeger.startSpan(name, childOf ? { childOf, tags } : { tags }); | ||
als.set('span', span); | ||
this.als.set('span', span); | ||
return span; | ||
}, | ||
}; |
'use strict'; | ||
const als = require('async-local-storage'); | ||
module.exports = (options, app) => async function jaegerMiddleware(ctx, next) { | ||
als.scope() | ||
const span = app.startSpan(ctx.path); | ||
span.setTag('requestMethod', ctx.method); | ||
als.set('span', span); | ||
try { | ||
await next(); | ||
span.finish(); | ||
} catch (err) { | ||
span.setTag(app.opentracing.Tags.ERROR, true); | ||
const finishSpan = (span, ctx, err) => { | ||
span.setTag('http.status_code', ctx.response.status); | ||
if (err) { | ||
span.setTag('error', true); | ||
span.log({ | ||
@@ -21,5 +13,20 @@ event: 'error', | ||
}); | ||
span.finish(); | ||
} | ||
ctx.app.coreLogger.debug('[egg-jaeger] finishSpan', span); | ||
span.finish(); | ||
}; | ||
module.exports = (options, app) => async function jaegerMiddleware(ctx, next) { | ||
app.als.scope(); | ||
const span = app.startSpan(ctx.path, { | ||
'http.method': ctx.method, | ||
'http.url': ctx.url, | ||
}); | ||
try { | ||
await next(); | ||
finishSpan(span, ctx); | ||
} catch (err) { | ||
finishSpan(span, ctx, err); | ||
throw err; | ||
} | ||
}; |
{ | ||
"name": "egg-jaeger", | ||
"version": "1.0.3", | ||
"description": "", | ||
"version": "1.0.5", | ||
"description": "jaeger egg plugin", | ||
"eggPlugin": { | ||
"name": "jaeger", | ||
"optionalDependencies": [ | ||
"sequelize" | ||
] | ||
"name": "jaeger" | ||
}, | ||
"keywords": [ | ||
"egg", | ||
"eggPlugin", | ||
"egg-plugin" | ||
], | ||
"dependencies": { | ||
"async-local-storage": "^2.1.0", | ||
"jaeger-client": "^3.13.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.2.1", | ||
"@commitlint/config-conventional": "^7.1.2", | ||
"autod": "^3.0.0", | ||
"autod-egg": "^1.0.0", | ||
"egg": "^2.0.0", | ||
"egg-bin": "^4.3.0", | ||
"egg-ci": "^1.8.0", | ||
"egg-mock": "^3.13.0", | ||
"egg-redis": "^2.2.0", | ||
"eslint": "^4.11.0", | ||
"eslint-config-egg": "^5.1.0", | ||
"husky": "^1.2.0", | ||
"lint-staged": "^8.1.0", | ||
"standard-version": "^4.4.0", | ||
"webstorm-disable-index": "^1.2.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"release": "standard-version", | ||
"test": "npm run lint -- --fix && egg-bin pkgfiles && npm run test-local", | ||
"test-local": "egg-bin test", | ||
"cov": "egg-bin cov", | ||
"lint": "eslint .", | ||
"ci": "egg-bin pkgfiles --check && npm run lint && npm run cov", | ||
"pkgfiles": "egg-bin pkgfiles", | ||
"autod": "autod" | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
] | ||
}, | ||
"files": [ | ||
"app", | ||
"config", | ||
"app.js", | ||
"lib", | ||
"commitlint.config.js" | ||
], | ||
"ci": { | ||
"version": "8, 9" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sqlwwx/egg-jaeger.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sqlwwx/egg-jaeger/issues" | ||
}, | ||
"homepage": "https://github.com/sqlwwx/egg-jaeger#readme", | ||
"author": "sqlwwx <wwx_2012@live.com> (http://wiki.lab.wuweixing.com)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"async-local-storage": "github:sqlwwx/async-local-storage#7a5f7d1", | ||
"jaeger-client": "^3.13.0" | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
} | ||
} |
@@ -1,3 +0,63 @@ | ||
# links | ||
# egg-jaeger | ||
https://github.com/weidian-lab/jaeger-tracer-node | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![David deps][david-image]][david-url] | ||
[![Known Vulnerabilities][snyk-image]][snyk-url] | ||
[![npm download][download-image]][download-url] | ||
[npm-image]: https://img.shields.io/npm/v/egg-jaeger.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/egg-jaeger | ||
[travis-image]: https://img.shields.io/travis/sqlwwx/egg-jaeger.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/sqlwwx/egg-jaeger | ||
[codecov-image]: https://img.shields.io/codecov/c/github/sqlwwx/egg-jaeger.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/sqlwwx/egg-jaeger?branch=master | ||
[david-image]: https://img.shields.io/david/sqlwwx/egg-jaeger.svg?style=flat-square | ||
[david-url]: https://david-dm.org/sqlwwx/egg-jaeger | ||
[snyk-image]: https://snyk.io/test/npm/egg-jaeger/badge.svg?style=flat-square | ||
[snyk-url]: https://snyk.io/test/npm/egg-jaeger | ||
[download-image]: https://img.shields.io/npm/dm/egg-jaeger.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/egg-jaeger | ||
<!-- | ||
Description here. | ||
--> | ||
## Install | ||
```bash | ||
$ npm i egg-jaeger --save | ||
``` | ||
## Usage | ||
```js | ||
// {app_root}/config/plugin.js | ||
exports.jaeger = { | ||
enable: true, | ||
package: 'egg-jaeger', | ||
}; | ||
``` | ||
## Configuration | ||
```js | ||
// {app_root}/config/config.default.js | ||
exports.jaeger = { | ||
}; | ||
``` | ||
see [config/config.default.js](config/config.default.js) for more detail. | ||
## Example | ||
<!-- example here --> | ||
## Questions & Suggestions | ||
Please open an issue [here](https://github.com/sqlwwx/egg-jaeger/issues). | ||
## License | ||
[MIT](LICENSE) |
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
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
11279
74.19%14
55.56%155
59.79%0
-100%0
-100%64
1500%0
-100%0
-100%15
Infinity%1
Infinity%+ Added
+ Added
Updated