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

zhike-zipkin-backend

v0.3.4

Published

Downloads

16

Readme

zipkin后端组件集合

to-do list

  • [x] express支持
  • [x] restify支持
  • [x] koa@2支持
  • [x] request支持
  • [x] rest支持
  • [x] [email protected]支持
  • [x] mongodb支持
  • [ ] sequelize支持
  • [ ] proxy相关支持

更新日志

v0.4.1

  • [x] 修复了之前包装mongodb存在的隐患(实际上算是错误...)
  • [ ] 加入了对find/aggregate的支持(不完善,没找到更好的方案)

v0.4.0

  • [x] 增加了对mongodb的支持
  • [x] 新增了一个过滤器,可以根据需要导出需要的包,而不需要每次导出那些不需要的包。

配置

config = {
    serviceName: String; // 服务名称
    zipkinServiceUrl: String; // zipkin 服务url
    disableTracing: Boolean; // 禁用zipkin, default: false
    remoteServiceName?: String; // 可选
}

// 示例
const zipkinConfig = {
    zipkinServiceUrl: "data.smartstudy.com/api/v1/spans",
    serviceName: "yourProjName",
    disableTracing: false
};

过滤器可以参考下面的示例。

filter = ["mongodbWrapper", "expressMiddleware"]; // array
filter = "expressMiddleware"; // string

使用示例

注意事项

测试用例需要本地起一个数据库和一个zipkin服务,不然会报错。

// 测试
npm test

安装

npm i zhike-zipkin-backend

express中间件

const { expressMiddleware } = require("zhike-zipkin-backend")(config, ["mongodbWrapper", "expressMiddleware"]);
app.use(koaMiddleware)

restify中间件

const { restifyMiddleware } = require("zhike-zipkin-backend")(config, "restifyMiddleware");
app.use(koaMiddleware)

koa@2中间件

const { koaMiddleware } = require("zhike-zipkin-backend")(config);
app.use(koaMiddleware)

[email protected]中间件

const { "[email protected]": koaMiddleware } = require("zhike-zipkin-backend")(config);
app.use(koaMiddleware)

包装request

request, request-promise都支持

const request = require("zhike-zipkin-backend")(config).requestWrapper(require("request"));
const rp = require("zhike-zipkin-backend")(config).requestWrapper(require("request-promise"));

包装rest

const rest = require("zhike-zipkin-backend")(config).restWrapper(require("rest"));

包装mongodb

// 这里建议以服务名称-mongo来命名
const mongodb = require("zhike-zipkin-backend")(config).mongodbWrapper(require("mongodb"), "service-mongo");

这里需要注意,这里的包装是全局性的,每次包装都会覆盖之前的修改,例如下面的例子

const mongodb1 = require("zhike-zipkin-backend")(config).mongodbWrapper(require("mongodb"), "firstMongo");
const mongodb2 = require("zhike-zipkin-backend")(config).mongodbWrapper(require("mongodb"), "secondMongo");

// 后面的过程实际上都是用的mongodb2
mongodb2.should.not.deep.equal(mongodb1);