0.0.9 • Published 5 years ago

cla-node v0.0.9

Weekly downloads
28
License
-
Repository
-
Last release
5 years ago

CLA NODE SDK

Is adapted from airBrake

Hello Cla

Install cla node sdk

npm install cla-node

Quick start:

const Cla = require('cla-node')
cosnt cla = new Cla.Notifier({
  appname: 'app-demo',
  grpc: 'ip:port,ip:port'
})

Attention:

  • appname is required, and used by es as index
  • grpc grpc IP端口,多个用逗号分隔以负载均衡,注意可能会影响日志时序

API

cla.notify(error)

发送error消息 error参数结构

  • error is object
fieldcomment
errorJS Error instance
contexterror context
context.userAddrrequest ip
context.userAgentuser agent
context.urlexpress request url
context.httpMethodhttp method
context.componentweb framework
context.historylog history, up to 20 records
context.routeexpress route
context.actionexpress action
context.refererhttp referer
paramsnull allowed
environmentnull allowed
sessionnull allowed
  • error is not object

cla.scope().pushHistory(log)

记录应用中的日志,在发送消息时作为history一起上报 log参数结构

fieldcomment
typelog类型
severitylog级别
argumentslog内容

cla.routes.start(method, route, statusCode, contentType)与cla.routes.notify(metric)成对使用

监控并上报web框架的路由质量,统计周期为15s 参数结构

fieldcomment
methodhttp method
route路由规则
statusCodehttp相应status码
contentTypehttp相应content-type
metricstart方法的返回值

metric=cla.scope().metric()/metric.startSpan(spanName)/metric.isRecording()/metric.endSpan(spanName)

需要结合cla.routes.notify使用

Performance Monit

  • web框架中,每次路由可能包含的耗时操作有:sql执行、redis存取等,通过metric计算耗时操作,在routes.notify中带上来,就能分析这些中间件的耗时情况了

Attention

  • 引用和初始化sdk放在程序执行的第一步,让后续操作产生的日志都能通过sdk进行上报
  • sdk默认会捕获uncaughtExceptionunhandledRejection,如果发现有些异常没有主动上报,检查业务中是否有try/catch的逻辑
  • 统计数据上报,cla.stat('event', {param: 'from news'})
  • 使用koaexpress中间件时,使用makeMiddleware,sdk自动收集并上报请求的cookie中的uuid字段
  • 使用koaexpress中间件时,使用makeMiddleware,sdk自动生成requestId并且在response header中以X-Request-Id字段返回;如果在http context中执行console.log({requestId: ctx.requestId})(koa)或console.log({requestId: req.requestId})(express),requestId信息也会出现在console日志中
  • 为了保证服务端接收数据的完整性,pb文件在维护时只能新增字段,不能删减字段

TODO

  • 自定义instrument开发文档
  • ?node sdk与web sdk的uid共享(web sdk将uuid写入cookie中)
  • 加入requestId,一次request的整个流程都带上这个id
  • 加入日志级别level
  • stat字段支持:(上报运营数据:pv、点击流等)
  • 调用链
  • 优化日志字段,去掉不重要或取不到的字段
  • lint code
  • 更新cla-node sdk的部分到fbi-project-fly-node模板中
  • 日志过滤
    • context.userAgent中包含curl的,这种日志大概率是健康检查探测包
    • context.httpMethodHEAD
0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago