Skip to content

Commit 959d9d0

Browse files
committed
fix: add commit and change dir
1 parent 5897da7 commit 959d9d0

File tree

14 files changed

+44
-61
lines changed

14 files changed

+44
-61
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ Tencent component monitor.
99

1010
## Usage
1111

12+
如果组件需要支持自定义监控数据上报,需在 component 的\_shims 下安装 tencent-component-monitor
13+
1214
```bash
1315
$ npm install tencent-component-monitor --save
1416
```
1517

18+
并在 handler.js 文件里面,在所有引用的最前面引入 monitor
19+
20+
```
21+
require('tencent-component-monitor')
22+
const fs = require('fs')
23+
const path = require('path')
24+
const { createServer, proxy } = require('tencent-serverless-http')
25+
26+
```
27+
1628
## License
1729

1830
MIT License

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tencent-component-monitor",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Tencent component monitor",
55
"main": "src/index.js",
66
"scripts": {
@@ -36,7 +36,7 @@
3636
},
3737
"repository": {
3838
"type": "git",
39-
"url": "git+https://github.com/serverless-tencent/tencent-component-toolkit.git"
39+
"url": "git+https://github.com/serverless-tencent/tencent-component-monitor.git"
4040
},
4141
"keywords": [
4242
"template",
@@ -46,9 +46,9 @@
4646
"author": "Tencent Cloud Inc.",
4747
"license": "MIT",
4848
"bugs": {
49-
"url": "https://github.com/serverless-tencent/tencent-component-toolkit/issues"
49+
"url": "https://github.com/serverless-tencent/tencent-component-monitor/issues"
5050
},
51-
"homepage": "https://github.com/serverless-tencent/tencent-component-toolkit#readme",
51+
"homepage": "https://github.com/serverless-tencent/tencent-component-monitor#readme",
5252
"devDependencies": {
5353
"@commitlint/cli": "^8.3.5",
5454
"@commitlint/config-conventional": "^8.3.4",

src/agent.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { EventEmitter } = require('events')
2+
3+
class Agent extends EventEmitter {}
4+
5+
module.exports = Agent
File renamed without changes.

src/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
const Monitor = require('./monitor')
1+
const shimmer = require('./shimmer')
2+
const Agent = require('./agent')
23

3-
module.exports = {
4-
Monitor
4+
function initialize() {
5+
const agent = new Agent()
6+
// 封装 module的_load方法,在load时针对基础组件附加探针
7+
shimmer.patchModule()
8+
// 初始化一系列基础组件
9+
shimmer.bootstrapInstrumentation(agent)
510
}
11+
12+
initialize()

src/monitor/instrumentation/express.js renamed to src/instrumentation/express.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ module.exports = function initialize(agent, express) {
1818
return false
1919
}
2020

21-
// wrapExpress4(express)
2221
utils.wrapMethod(express.Router, 'route', function wrapRoute(fn) {
2322
if (!utils.isFunction(fn)) {
2423
return fn
2524
}
2625

2726
return function wrappedRoute() {
2827
const sourceRoute = fn.apply(this, arguments)
29-
// Express should create a new route and layer every time Router#route is
30-
// called, but just to be on the safe side, make sure we haven't wrapped
31-
// this already.
28+
// Router每次添加一个route,都会把route包装到layer中,并且将layer添加到的stack中
29+
// 当客户端发送一个http请求后,会先进入express实例对象对应的router.handle函数中,
30+
// router.handle函数会通过next()遍历stack中的每一个layer进行match,
31+
// 如果match返回true,则获取layer.route,执行route.dispatch函数,
32+
// route.dispatch同样是通过next()遍历stack中的每一个layer,
33+
// 然后执行layer.handle_request,也就是调用中间件函数。直到所有的中间件函数被执行完毕,整个路由处理结束
3234
if (!utils.isWrapped(sourceRoute, 'get')) {
3335
wrapRouteMethods(sourceRoute)
3436

src/monitor/instrumentation/tencent-serverless-http.js renamed to src/instrumentation/tencent-serverless-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function initialize(agent, httpProxy) {
88
context[REUQEST_START_KEY] = Date.now()
99
const proxy = fn.apply(this, arguments)
1010
return new Promise(function(resolve) {
11-
agent.on('responseFinish', function(ctx, method, path, responseCode) {
11+
agent.once('responseFinish', function(ctx, method, path, responseCode) {
1212
if (ctx) {
1313
report.reportHttp(ctx, method, path, responseCode).then(
1414
function() {
File renamed without changes.
File renamed without changes.

src/monitor/agent.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)