package
0.0.0-20190422025920-beccf3fe4313
Repository: https://github.com/changwh/go-common.git
Documentation: pkg.go.dev
# README
go-common/net/trace
项目简介
- 提供Trace的接口规范
- 提供 trace 对Tracer接口的实现,供业务接入使用
编译环境
- 请只用golang v1.7.x以上版本编译执行。
依赖包
- 无
编译执行
- 启动接入示例 if conf.Conf.Common.Trace { trace.Init(conf.Conf.tracer) }
- 配置参考 [tracer] proto = "unixgram" addr = "/var/run/dapper-collect/dapper-collect.sock" family = "account-service"
测试
- 执行当前目录下所有测试文件,测试所有功能
特别说明
- trace 需要在conf.common配置family 和设置trace = true 应用才能接入
trace sdk serviceName, operationName, tag 规范
注: serviceName 及之前的 family 字段, operationName 及之前的 title 字段
serviceName 使用 APP_ID 可以通过 caster 上 APP_ID 环境变量获取
全局 Tag
名称 | 类型 | 备注 |
---|---|---|
hostname | string | 主机名 |
ip | string | caster上使用 POD_IP 环境变量,其他环境取第一个外网IP |
zone | string | zone caster 使用 ZONE 环境变量 e.g. sh |
region | string | region caster 使用 REGION 环境变量 e.g. region |
HTTP
HTTP server && client 共同 tag
名称 | 类型 | 备注 |
---|---|---|
http.method | string | GET、POST ... |
http.url | string | http 完整 URL,包含 query |
http.status_code | int | http 状态码 |
HTTP server
operationName 设置:
- 非 restful API 的应用使用 URL path 部分 例如 URL http://api.bilibili.co/x/internal/user/info?mid=123 operationName 为 /x/internal/user/info
- restful API 的使用路由定义,使用 {} 代替可变部分, 例如 URL http://api.bilibili.co/x/internal/user/info/123 其中 123 为 mid,则 operationName 设置为 /x/internal/user/info/{mid}
名称 | 类型 | 备注 |
---|---|---|
span.kind | string | 固定值 server |
component | string | 组件名称 e.g. library/net/http/baldemaster |
HTTP client
operationName 设置:
- 请求内部非 restful 的应用可以直接设置为 URL 的 path 部分
- 请求的三方的服务或者 restful API operationName 可以直接设置为 HTTP:{Method} e.g. HTTP:GET
名称 | 类型 | 备注 |
---|---|---|
span.kind | string | 固定值 client |
component | string | 组件名称 e.g. library/net/http 或者 net/http |
peer.service | string | 请求的服务APP_ID,例如请求 account-service 则应该设置为 main.account.account-service |
_peer.sign | string | URL 的 path 部分不包含 query |
注: peer.service 不知道可以不设置,_peer.sign 用于自定探测 peer.service
gRPC
gRPC server && client 共同 tag
gRPC server
operationName 设置:
名称 | 类型 | 备注 |
---|---|---|
span.kind | string | 固定值 server |
component | string | 固定值 gRPC |
gRPC client
operationName 设置:
名称 | 类型 | 备注 |
---|---|---|
span.kind | string | 固定值 client |
component | string | 固定值 gRPC |
peer.service | string | 请求的服务APP_ID,例如请求 account-service 则应该设置为 main.account.account-service |
_peer.sign | string | gRPC FullMethod |
goRPC
TODO
Memcache
TODO
Redis
TODO
MySQL
TODO
Databus
TODO
HBase
TODO
ElasticSearch
TODO
# Packages
No description provided by the author
# Functions
Bool new tagBool NOTE: use TagBool.
Close trace flush data.
EnableDebug enable debug mode.
Extract returns a Trace instance given `format` and `carrier`.
FromContext returns the trace bound to the context, if any.
Init 兼容以前的 Init 写法.
Inject takes the Trace instance and injects it for propagation within `carrier`.
Int new tag Int.
Log new log.
New trace instance with given operationName.
NewContext new a trace context.
SetGlobalTracer SetGlobalTracer.
String new tag String.
TagBool new bool tag.
TagFloat32 new float64 tag.
TagFloat64 new float64 tag.
TagInt new int tag.
TagInt64 new int64 tag.
TagString new string tag.
TracerFromEnvFlag new tracer from env and flag.
# Constants
Trace key.
trace sdk should use bili_trace_id to get trace info after this code be merged.
GRPCFormat represents Trace as gRPC metadata.
HTTPFormat represents Trace as HTTP header string pairs.
Trace key.
历史遗留的 key 不要轻易修改.
Trace key.
Trace key.
Trace key.
Trace key.
The type or "kind" of an error (only for event="error" logs).
For languages that support such a thing (e.g., Java, Python), the actual Throwable/Exception/Error object instance itself.
A stable identifier for some notable moment in the lifetime of a Span.
A concise, human-readable, one-line message explaining the event.
A stack trace in platform-conventional format; may or may not pertain to an error.
Standard Span tags https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table.
legacy tag.
Standard Span tags https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table.
The software package, framework, library, or module that generated the associated Span.
Database instance name.
A database statement for the given database type.
Database type.
Username for accessing database.
true if and only if the application considers the operation represented by the Span to have failed type bool.
HTTP method of the request for the associated Span.
HTTP response status code for the associated Span.
URL of the request being handled in this segment of the trace, in standard URI format.
An address at which messages can be exchanged.
Remote "address", suitable for use in a networking client library.
Remote hostname.
Remote IPv4 address as a .-separated tuple.
Remote IPv6 address as a string of colon-separated 4-char hex tuples.
Remote port.
Remote service name (for some unspecified definition of "service").
If greater than 0, a hint to the Tracer to do its best to capture the trace.
Either "client" or "server" for the appropriate roles in an RPC, and "producer" or "consumer" for the appropriate roles in a messaging scenario.
# Variables
ErrInvalidCarrier errors occur when Tracer.Inject() or Tracer.Extract() implementations expect a different type of `carrier` than they are given.
ErrInvalidTrace errors occur when Tracer.Inject() is asked to operate on a Trace which it is not prepared to handle (for example, since it was created by a different tracer implementation).
ErrTraceCorrupted occurs when the `carrier` passed to Tracer.Extract() is of the expected type but is corrupted.
ErrTraceNotFound occurs when the `carrier` passed to Tracer.Extract() is valid and uncorrupted but has insufficient information to extract a Trace.
ErrUnsupportedFormat occurs when the `format` passed to Tracer.Inject() or Tracer.Extract() is not recognized by the Tracer implementation.
# Type aliases
BuiltinFormat is used to demarcate the values within package `trace` that are intended for use with the Tracer.Inject() and Tracer.Extract() methods.
Option dapper Option.