npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cla-node

v0.0.9

Published

cla node sdk

Downloads

6

Readme

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

| field | comment | | ----------- | ---------- | | error | JS Error instance | | context | error context | | context.userAddr | request ip | | context.userAgent | user agent | | context.url | express request url | | context.httpMethod | http method | | context.component | web framework | | context.history | log history, up to 20 records | | context.route | express route | | context.action | express action | | context.referer | http referer | | params | null allowed | | environment | null allowed | | session | null allowed |

  • error is not object

cla.scope().pushHistory(log)

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

| field | comment | | ----------- | ---------- | | type | log类型 | | severity | log级别 | | arguments | log内容 |

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

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

| field | comment | | ----------- | ---------- | | method | http method | | route | 路由规则 | | statusCode | http相应status码 | | contentType | http相应content-type | | metric | start方法的返回值 |

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