Comments (35)
twitter zipkin: http://zipkin.io/
from egg.
http://itszero.github.io/blog/2014/03/03/introduction-to-twitters-zipkin/
Now think about how server handles a request. Let’s say we have a nginx server as frontend, an application server and a database server. When nginx gets a request, it needs to generate a traceId and two spans. The first spans denotes the user requesting nginx, it will have spanId = traceId and parentSpanId = 0 by convention for root spans. The second spans will be generated when nginx initiate the connection to the upstream. It would have a new spanId, parentSpanId set to the first span’s id and reuse the same traceId.
from egg.
https://tech.knewton.com/blog/2016/04/distributed-tracing-design-architecture/
from egg.
traceId: 1, // randomly generated globally unique ID
spanId: 1, // root span shares spanId with traceId
parentSpanId: 0, // root span does not have a parent
from egg.
app1: traceId: 1, spanId: 1, parentSpanId: 0
-> service1: traceId: 1, spanId: 2, parentSpanId: 1
-> service2: traceId: 1, spanId: 3, parentSpanId: 1
-> service3: traceId: 1, spanId: 4, parentSpanId: 3
-> service5: traceId: 1, spanId: 6, parentSpanId: 4
-> service4: traceId: 1, spanId: 5, parentSpanId: 3
=> 鹰眼 rpcId http://www.cnblogs.com/zhengyun_ustc/p/55solution2.html
app1: traceId: 1, rpcId: '0'
-> service1: traceId: 1, rpcId: '0.1'
-> service2: traceId: 1, rpcId: '0.2'
-> service3: traceId: 1, rpcId: '0.2.1'
-> service5: traceId: 1, rpcId: '0.2.1.1'
-> service4: traceId: 1, rpcId: '0.2.2'
from egg.
spanId 和 rpcId 的优劣对比
spanId
优势:
- 只需要基于 traceId 随机生成,算法简单,不入侵调用代码
- 通过配合 parentSpanId,可以将整个调用链连接起来
劣势:
- 通过日志查看到的 traceId + parentSpanId,无法感知到底当前的调用链有多长,需要通过系统才能查看完整的链路长度 (当前应用只知道谁调我)
- traceId 的日志存储字节数会比 rpcId 多很多
rpcId
优势:
- 查看当前 rpcId 日志就能看到当前的调用链深度和次数,对人友好
- rpcId 的日志存储字节数会比 traceId 少很多
劣势:
- 算法有点复杂,需要调用代码实现 rpcId 生成逻辑
from egg.
rpcId 侵入代码逻辑?我的理解好像和 spanId 一样都可以由 rpc 框架封装好对开发者透明的吧。
from egg.
@shaoshuai0102 spanId 只需要请求进来根据 traceId 随机生成(由被调用者生成),而 rpcId 是由调用者在调用服务的时候生成(有调用者生成),因为有逻辑。
from egg.
了解了
from egg.
实现方式以及如何配置自定义 Tracer
Tracer 约定的 api
class Tracer {
get traceId() {}
}
ctx.tracer
get tracer() {
if (!this.__tracer) {
this.__tracer = new this.app.config.tracelog.Tracer(this);
}
return this.__tracer;
}
默认配置
egg-tracelog 的默认 Tracer 配置
exports.tracelog = {
Tracer: Tracer,
};
上层框架自定义配置
继承 Tracer
const Tracer = require('egg-tracelog'). Tracer;
class MyTracer extends Tracer {}
配置修改
exports.tracelog = {
Tracer: MyTracer,
};
from egg.
https://github.com/eggjs/egg-tracer
from egg.
this.app.config.tracelog.Tracer
这种方式好么? 用 view 那种方式怎么样, 即 egg 读取 app 上的某个 约定的 symbol, 框架那边进行覆盖?__tracer
按之前的习惯应该换为 Symbol
// {egg}/app/extend/context.js
const TRACER = Symbol('Context#tracer');
get tracer() {
if (!this[TRACER]) {
this[TRACER] = new this.app[Symbol.for('egg#tracer')];
}
return this[TRACER];
}
// {framework}/app/extend/app.js
module.exports = {
get[Symbol.for('egg#tracer')] () {
return MyTracer;
}
}
from egg.
@atian25 没必要吧,不是所有团队都能写插件的,现在这种方式可以让一个应用便捷地实现自定义的 Tracer,而不需要深入了解 egg 才能实现。
from egg.
按 View 之前的约定, 是纳入到 web 规范了, tracer 如果也需要, 是不是也要类似.
因为觉得 View 和 Tracer 这两个都差不多的, 两种方式都行, 只是需不需要统一?
from egg.
View 不会在应用上改吧,View 应该都是跟框架绑死的。
from egg.
嗯, 主要是出现了两种方式, 需要明确下使用的场景, 至少内部要清晰.
from egg.
这个实现 tracer 就好了?
from egg.
https://github.com/opentracing-contrib/opentracing-specification-zh
有一个开放的规范
OpenTracing是一个跨编程语言的标准,此文档会避免具有语言特性的概念。比如,我们在文档中使用"interface",因为所有的语言都包含"interface"这种概念。
from egg.
https://wu-sheng.gitbooks.io/opentracing-io/content/
from egg.
opentracing 有官方 npm 模块 https://github.com/opentracing/opentracing-javascript
from egg.
基于阿里云 sls + opentracing 封装一个插件实现 https://github.com/opentracing-contrib/opentracing-specification-zh/blob/master/semantic_conventions.md
opentracing 插件支持切换日常存储引擎,默认是文件存储,支持 sls 等云存储。
from egg.
实现在 eggjs/egg-opentracing#1 跟进
from egg.
请问tracer的分布式跟踪有最佳实践的使用案例分享吗?谢谢。
from egg.
sls 还是不要支持在 opentracing 里面比较好
from egg.
主要是想了解egg-tracer是如何实现前后端全链路跟踪的,由于官方文档中没有任何案例提及这一块,让使用者没有方向,不知道怎么使用
from egg.
一般是系统间调用的时候传递 tracer 信息,然后打印日志的时候要包含 tracer 信息,平台收集日志后就可以有整个链路的信息了。opentracing 就是实现如何建立链路关系,egg-tracer 是每个应用的 tracer 信息,包括上下游。
from egg.
https://github.com/openzipkin/zipkin-js
from egg.
默认内置了 opentracing,各个企业框架,根据企业内部需求,将 opentracing 转换成企业需要的格式,再打印日志,或者上报到自己的 apm,都是可行的方式。
from egg.
我们用 egg-opentracing 来替换 egg-tracelog?
from egg.
更新了 RFC
from egg.
opentracing 是否默认集成在 egg 中 @gxcsoccer @fengmk2
如果不集成,那么框架默认的打点就写在 opentracing 插件里了
from egg.
egg-opentracing 插件的功能
- 基础的 opentracing 能力
- 默认支持 httpclient/httpserver 的打点及常用 tag
- 默认的 collector 为日志模式,不区分文件
- 每个 span 包含默认的 tag
- appname
- workerid
- process id
egg-zipkin 插件的功能
- 支持 zipkin 作为 collector
sofa-tracer-node
- 对接 carrier,http/rpc 调用传递(后面还有消息等组件)
- 对接日志格式
from egg.
eggjs/egg-opentracing-zipkin#2
from egg.
有个场景需要讨论一下。
比如 egg-mysql 这个插件, 目前是使用 addSingle 直接加载到了 app 上,没有 context 级别的实例。如果我想做 mysql 调用的自动 trace (类似于 https://github.com/eggjs/egg-opentracing/blob/master/app.js#L58 ) ,目前比较麻烦。没有很好的办法传递 ctx .
一个想法是, addSingle 的时候,同时增加 context 级别的对象:
ctx.mysql.query()
上面这样的调用方式,能够自动注入 ctx 对象,方便做 trace 扩展功能。
from egg.
@popomore 我们PHP服务现有的trace框架是zipKin.那我如果用egg建立一个新的服务,trace使用egg-opentracing-zipkin 可以和PHP服务现有的zipKin兼容吗
from egg.
Related Issues (20)
- GET 请求带 gzip body 会导致非法异常 HOT 4
- multipart多文件上传 HOT 1
- egg_amqplib 连接中断后导致程序异常退出 HOT 1
- 七牛云拉取文件始终返回404 HOT 10
- 使用ts时tsconfig.json文件配置module只能使用CommonJS,使用ES会报错 HOT 1
- 日志切割后不是 .log 后缀, vscode 不高亮啊
- 国际化用voerkai18n实现,在中间件处理切换语言时,yarn test测试环境不生效,请问会不会是eggjs影响的? HOT 1
- 如果使用AsyncLocalStorage,如何能够在不被Egg管理的类中,也能正确地拿到上下文对象 HOT 12
- 如何升级babel 7?
- jsx as tpl HOT 1
- new version available: 2.3.1 → 3.0.0, not compatible, you must update to use this. HOT 4
- egg-bin 5以上的版本设置端口无效
- 传闻Eggjs不再维护了,是真的吗? HOT 4
- new version available: 2.3.1 → 3.0.0, not compatible, you must update to use this. HOT 6
- 同一个方法在放在eggjs服务schedule 定时模块里面执行就可以获取的到inputElem,但是放到controller模块里面通过接口调用时获取不到呢,再express里面也可以成功调用,debug模式可能获取得到 HOT 3
- v3的文档多会更新,EggLogger 怎么用????? HOT 3
- 使用问题: 请问如何在egg应用下运行脚本,以及如何在脚本中使用app中的service,helper,db等能力 HOT 1
- egg-mysql能配置连接断开后自动重连吗
- eggjs 在容器通过前台启动,如何将stdout和stderr日志输出到日志文件 HOT 1
- curl返回值类型缩小 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from egg.