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)
- extend/application.js空导出,导致接口返回404 HOT 1
- 文档链接显示错误
- 依照官网初始化项目 HOT 1
- eggjs处理服务端请求有超时时间吗 HOT 3
- 在 service 中 extends egg 暴露的 Service 项目无法启动 HOT 1
- egg-router-plus 根 router 应该支持正则 HOT 1
- 能否将依赖的urllib升级为3.25的系列,而不是现在的2.41.0 HOT 2
- 怎么在没有app上下文的文件中 获取config中的配置? HOT 4
- 使用 oxlint 代替 eslint HOT 5
- egg 运行一段时间后,就会退出 HOT 1
- Track Progress of PR #5332 Towards Merging into Master
- Follow-up on PR #5334: Allow to create httpClient from app
- Track merging PR #5336 into master branch
- 服务器 egg-scrips start 无法启动,一直提示文件找不到。但是本地能正常运行 HOT 5
- Track merging of PR #5339 into master
- Track bugfix for httpclient.safeCurl typing
- eggjs返回的响应头为什么是使用小写? HOT 4
- 初始化项目跑不起来 HOT 1
- 为什么在服务启动命令中添加参数在服务生命周期中获取不到? HOT 2
- enableH2 开启的时候使用 undici v6
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.