{"_id":"@alicloud/opentracing","_rev":"18-9898338b4742c5fcf018cda1e8a1c06d","name":"@alicloud/opentracing","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@alicloud/opentracing","version":"0.1.0","description":"============================================","main":"index.js","directories":{"lib":"lib","test":"test"},"scripts":{"lint":"eslint lib test index.js --fix","test":"mocha -R spec test/**/*.test.js","cov":"nyc --reporter=html --reporter=text --reporter=lcov mocha -t 3000 -R spec test/**/*.test.js","ci":"npm run lint && npm run cov && codecov"},"repository":{"type":"git","url":"git+https://github.com/aliyun-node/optracing.git"},"author":{"name":"yijun"},"license":"MIT","dependencies":{"footprint":"^1.1.0","internal-ip":"^3.0.1","moment":"^2.22.1","opentracing":"^0.14.3"},"devDependencies":{"codecov":"^3.0.0","eslint":"^4.19.1","expect.js":"^0.3.1","mm":"^2.2.0","mocha":"^3","nyc":"^11.6.0","rewire":"^2.5.2"},"files":["lib","index.js"],"gitHead":"b71f7b589ed6ca4499743068cf17268b6c03bce6","bugs":{"url":"https://github.com/aliyun-node/optracing/issues"},"homepage":"https://github.com/aliyun-node/optracing#readme","_id":"@alicloud/opentracing@0.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"dist":{"integrity":"sha512-u6piBO1ap15HOQqf1WCon/XOh7yKG0hwB3YdQNPW7EBYl0dg2LLhR+6u8XMMg+E1EYWHuEzxKk6+wTKpQB3DMA==","shasum":"3a4020d2365007e993a198ffe21b47f534e05712","tarball":"https://registry.npmjs.org/@alicloud/opentracing/-/opentracing-0.1.0.tgz","fileCount":10,"unpackedSize":14870,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbBR6mCRA9TVsSAnZWagAAPDgP/iLSC67XTvMI0T0JfzH+\np7FQtB7TNzVtqVnt/bUZ4m82CFZLWy57FzjaewX1IKO04moi4i3GYH2pE/qp\nOGJQuxbWRGu2r1VUcScvGm/OruztIPWQpT881aLVRJmCz1LlXORiVIui8ive\njJVUtHbf8Kg6mwi+m8GUkZq8T19Jft9SlNhnTu10MuRMr42JfS6+uTa+umMl\n0YQRb2JWPBUKyt8R93clRuew4Mqc/kNCNQ7gXdUnxmcQbm2VySNr38eHKjHE\nklc5gOR/yRPBLbDiMNi8AjK9waE6/F3UjPR0uSyYnKDodgMK0+f0rSmDuAcZ\nEOQAmoP1IQKDfqwI1MWBFXlDJWY+MvG6tkpnBMTPsmP90RI6BmDKlAfAriG7\nes/njQyE/beEdIbA+8CBZdsj/UntHr4n6cYy67AFYl3h0wyiZaAW7R+ihwVI\n//cW1RPTzIbaxjrS9r0KcEtdrciU+LpXqKac+Cbu+pBRauwsPTBCr3GTATTX\nsV12ah23eEkEfGni1XzlA2vf1iVhy3d+M30UbDBqrcQTJz3/SpIPIUxZq1pb\n55LRff8iRRuR3PcDh/yq2XoylaifaJxB6oEPYK0szvr7MQo7Rwv1L5V3O0SK\nhjDUGnvEb/reMCjnfZzRRvGvwdY0bSsji0YqIrBmviVFonZpVRGqqUuy1b/W\nxhyJ\r\n=KgMy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGUYydJdcnIAYr/zSUWZOPMQ3SceQoJFzaVqsxQoQ+Z+AiBbOcQzySQy1rthM7C0SD+4IyfWda62qnzsyr/e/o5E+Q=="}]},"maintainers":[{"name":"aleelock","email":"aleelock@126.com"},{"name":"humanhuang","email":"halfthink@gmail.com"},{"name":"jacksontian","email":"shyvo1987@gmail.com"},{"name":"ls_nodejs","email":"ls_huster@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opentracing_0.1.0_1527062180798_0.16651163514550427"},"_hasShrinkwrap":false},"0.1.1":{"name":"@alicloud/opentracing","version":"0.1.1","description":"[![npm version](https://badge.fury.io/js/@alicloud%2fopentracing.svg)](https://badge.fury.io/js/@alicloud%2fopentracing.svg) [![Build Status](https://travis-ci.org/aliyun-node/opentracing.png?branch=master)](https://travis-ci.org/aliyun-node/opentracing) ","main":"index.js","directories":{"lib":"lib","test":"test"},"scripts":{"lint":"eslint lib test index.js --fix","test":"mocha -R spec test/**/*.test.js","cov":"nyc --reporter=html --reporter=text --reporter=lcov mocha -t 3000 -R spec test/**/*.test.js","ci":"npm run lint && npm run cov && codecov"},"repository":{"type":"git","url":"git+https://github.com/aliyun-node/optracing.git"},"author":{"name":"yijun"},"license":"MIT","dependencies":{"footprint":"^1.1.0","internal-ip":"^3.0.1","moment":"^2.22.1","opentracing":"^0.14.3"},"devDependencies":{"codecov":"^3.0.0","eslint":"^4.19.1","expect.js":"^0.3.1","mm":"^2.2.0","mocha":"^3","nyc":"^11.6.0","rewire":"^2.5.2"},"files":["lib","index.js"],"gitHead":"b71f7b589ed6ca4499743068cf17268b6c03bce6","bugs":{"url":"https://github.com/aliyun-node/optracing/issues"},"homepage":"https://github.com/aliyun-node/optracing#readme","_id":"@alicloud/opentracing@0.1.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.0","_npmUser":{"name":"hyj1991","email":"1539194907@qq.com"},"dist":{"integrity":"sha512-JScrwJJluIIYhP0ZFuV0PLvU0i6une2VnX558QI3/sr9en7Bf2l2q5w01LIzisBSl/+ZzLnU8cnf+idyanmBAA==","shasum":"44ec5744dc36fd6a44e335570d1a1f21b67055f2","tarball":"https://registry.npmjs.org/@alicloud/opentracing/-/opentracing-0.1.1.tgz","fileCount":10,"unpackedSize":14956,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbBSESCRA9TVsSAnZWagAAYQEQAJ4fUxQ6XY0nLWbairrQ\nRGJLswjaUW3/rirFfP5SFx8cUf0OQ+IhSwuLA7N8KrLZWqWXasKnryz7rZW7\ncb97yw0Bs7XtmJCtrxE9glkVPtavBgZZZEhN7R8IMTZ/3TZQAV5dx9Dh5gML\njxGeYGbe5iJ4nZMaT9i0dpUp2B4/15hkgNE5awfsQD79gIHbCYZ6Gsg/umHT\nWodtVzeTIHAdTf15WA6nqk1MibvcVG+x763NNxAeX9Mq1lkQo2tNfVgbHlgH\nAInTX8EJdrXUbZT81Q3bu6tDkNHdcyyzkRdQNhNJ/equE8ENc3fclqM6JEJM\n0pJvXaqG07g3xkFawrIzSzehbqvj5rjeFugWag2fBsZ2S2tZrSfNthH8308K\nNEs5L2aRMoihhwe+f4H7pCMjcOJoHicDbCyDR+I9H1eIY6rQjsVO9wixLwhi\nWogg6sJJyKW6gxLUCAKIgSFynDc6zHMHnxJw7Mz9xysw1a6uHjs34wywHTrn\nf7FiGIK6mU6jNhtzzphkD8gHw4lIJpKvlpBZWokR/5m1bq0z7Vaa1nqj8zDx\nsQEZtb4M/KkK0RMYTyMGEcoQTCxEQKqYOYRmaC4O0tXFhcmTx8K9cgVPGPVi\nTTuYlNltPwhsw86+ATDbihpOr7CbghDjY0pjKQubzTJTOqsBL2GAFbXPY5rI\nWcyR\r\n=HzBn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC4gS4aeXHPMYlGpF/S1mFIQaX12evDyyKmFhgrehDVXgIgULIGcQDvxFA9L2czL1jxTl7XKvO+ex//0GGYMIfCFJA="}]},"maintainers":[{"email":"aleelock@126.com","name":"aleelock"},{"email":"halfthink@gmail.com","name":"humanhuang"},{"email":"1539194907@qq.com","name":"hyj1991"},{"email":"shyvo1987@gmail.com","name":"jacksontian"},{"email":"ls_huster@163.com","name":"ls_nodejs"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opentracing_0.1.1_1527062800790_0.20466464200054224"},"_hasShrinkwrap":false}},"time":{"created":"2018-05-23T07:56:20.610Z","0.1.0":"2018-05-23T07:56:20.872Z","modified":"2022-04-04T12:58:09.256Z","0.1.1":"2018-05-23T08:06:40.845Z"},"maintainers":[{"email":"console-fe@alibabacloud.com","name":"console-fe"},{"email":"sdk-team@alibabacloud.com","name":"aliyunsdkteam"},{"email":"cpj1106@gmail.com","name":"pagecao"},{"email":"fengmk2@gmail.com","name":"fengmk2"},{"email":"shyvo1987@gmail.com","name":"jacksontian"}],"description":"[![npm version](https://badge.fury.io/js/@alicloud%2fopentracing.svg)](https://badge.fury.io/js/@alicloud%2fopentracing.svg) [![Build Status](https://travis-ci.org/aliyun-node/opentracing.png?branch=master)](https://travis-ci.org/aliyun-node/opentracing) ","homepage":"https://github.com/aliyun-node/optracing#readme","repository":{"type":"git","url":"git+https://github.com/aliyun-node/optracing.git"},"author":{"name":"yijun"},"bugs":{"url":"https://github.com/aliyun-node/optracing/issues"},"license":"MIT","readme":"# Node.js 性能平台 - 慢链路追踪\n\n[![npm version](https://badge.fury.io/js/@alicloud%2fopentracing.svg)](https://badge.fury.io/js/@alicloud%2fopentracing.svg)\n[![Build Status](https://travis-ci.org/aliyun-node/opentracing.png?branch=master)](https://travis-ci.org/aliyun-node/opentracing)\n[![codecov](https://codecov.io/gh/aliyun-node/opentracing/branch/master/graph/badge.svg)](https://codecov.io/gh/aliyun-node/opentracing)\n\n@alicloud/opentracing 是 alinode 团队开发的慢链路追踪日志输出模块，配合 [Node.js 性能平台](https://node.console.aliyun.com/) 可以展示您的 web 应用中抓取到的慢请求的产生原因。\n\n## 安装\n\n```sh\n$ npm install @alicloud/opentracing\n```\n\n## 使用\n\n### 公共类: Tracer(name[, option][, reporter]): \n\n#### I. 参数:\n\n* **name** String - tracer 的名称\n* **option** Object - 可选\n  * **limit** Number - 每分钟限制记录落盘的数据条数限制，防止大量异常的情况下大量日志写入文件造成磁盘溢出\n  * **logger** Object - 日志句柄，最小需要实现 info、log、warn 和 error 方法，默认采用 console\n* **reporter** Object - 自定义发送方法，需要实现 report 方法，入参为 span\n\n#### II. 成员方法：startSpan(spanName[, option])\n\n* **spanName** String - span 的名称，用来标记此 span 下的异步调用\n* **option** Object - 可选\n  * **childOf** Object - 传入当前 span 的父级 span 实例\n* **返回值** Object - 返回内置的类 Span 的实例\n\n### 内置类：Span\n\n#### I. 成员方法：setTag(tag, value)\n\n* **tag** String - Tag 名称，可以自定义，一般从 opentracing.Tags 中获取（里面定义了常见的 host、url、statusCode 等链路信息 Key）\n* **value** String - Tag 名称对应的值\n\n#### II. 成员方法：log(key, value)\n\n* **key** String - 自定义的日志键\n* **value** String - 自定义的日志值\n\n#### III. 成员方法: finish(req)\n\n* **req** Object - http 请求的 request 对象\n\n## 例子\n\n下面是一个嵌入 express 应用的使用完整样例，模拟了并发的异步耗时调用，和顺序的异步耗时调用：\n\n```js\n'use strict';\nconst express = require('express');\nconst app = express();\nconst opentracing = require('@alicloud/opentracing');\nconst tracer = new opentracing.Tracer('测试链路');\n\n// 模拟耗时的异步操作\nfunction delay(time, req) {\n  let child = tracer.startSpan('子模块 1: 随机并发延迟', { childOf: req.parentSpan });\n  child.setTag('timeout', time);\n  child.log({ state: 'timer1' });\n  return new Promise((resolve, reject) => {\n    setTimeout(() => {\n      resolve();\n      child.finish(req);\n    }, time);\n  });\n}\n\n// 在所有中间件之前，开启一个根 span，记录下 hostname、method、url，以及收到 end 事件后的\napp.use(function (req, res, next) {\n  req.parentSpan = tracer.startSpan('根模块');\n  req.parentSpan.setTag(opentracing.Tags.PEER_HOSTNAME, req.hostname);\n  req.parentSpan.setTag(opentracing.Tags.HTTP_METHOD, req.method.toUpperCase());\n  req.parentSpan.setTag(opentracing.Tags.HTTP_URL, req.url);\n  next();\n  res.once('finish', () => {\n    req.parentSpan.setTag(opentracing.Tags.HTTP_STATUS_CODE, res.statusCode);\n    req.parentSpan.finish(req);\n  });\n});\n\n// 模拟并发的耗时异步操作\napp.use(function (req, res, next) {\n  Promise.all([\n    delay(Math.random() * 10 * 1000, req),\n    delay(Math.random() * 10 * 1000, req)\n  ]).then(() => next());\n});\n\n// 继续模拟一个顺序的 3s 耗时异步操作\napp.use(function (req, res, next) {\n  let child = tracer.startSpan('子模块 2: 延迟 3s', { childOf: req.parentSpan });\n  child.setTag('timeout', '3s');\n  child.log({ state: 'timer2' });\n  // 3s call\n  setTimeout(() => {\n    child.finish(req);\n    next()\n  }, 3000);\n});\n\n// 响应页面\napp.get('*', function (req, res) {\n  res.send('Hello Node.js Performance Platform!');\n});\n\napp.listen(3000);\n```\n\n等待约 1min 后，可以在控制台的相应 Tab 页看到：\n\n![慢链路追踪样例](https://raw.githubusercontent.com/aliyun-node/opentracing/master/assets/20180522164039.png)\n\n## 联系我们\n\n所有使用中遇到的问题，请咨询钉钉群：11794270。\n\n## License\n\n[MIT](LICENSE)","readmeFilename":"README.md"}