Twisted Zipkin 跟踪库
项目描述
Zipkin 是一个分布式跟踪系统,tryfer 是一个用于 Zipkin 的 Python/Twisted 客户端库。
它的设计深受 Finagle 跟踪库的影响。
HTTP 跟踪
Tryfer 本地支持客户端和服务器上 HTTP 请求的跟踪,并通过传递一系列 HTTP 标头与请求相关联。
客户端
这个对话的客户端是 TracingAgent,它使用 Twisted 的可组合 HTTP/1.1 客户端架构来记录您的请求的 CLIENT_SEND 和 CLIENT_RECV 标注。此外,它还将完整的请求 URL 作为名为 http.uri 的字符串标注记录。
服务器
在服务器上,您可以将应用程序的根资源包裹在 TracingWrapperResource 中,并且它将自动记录 SERVER_RECV 和 SERVER_SEND 标注。它还通过请求参数提供对跟踪的访问,因此您可以记录额外的标注。
def render(self, request): trace = request.getComponent(ITrace) trace.record(Annotation.string('name', 'value'))
头部
TracingAgent 和 TracingWrapperResource 支持由 Finagle 定义的头部子集。
X-B3-TraceId - 十六进制编码的跟踪ID。
X-B3-SpanId - 十六进制编码的跨度ID。
X-B3-ParentSpanId - 父跨度ID的十六进制编码。
示例
在 examples/ 子目录中,你可以找到两个 Python 脚本(一个客户端和一个服务器),它们演示了用法和预期的输出。
首先,打开两个终端,进入 tryfer 源代码目录。
在终端 #1 中,我们可以使用 twistd 启动服务器
tryfer> twistd -n -y examples/tracing-server.tac 2012-09-05 13:22:02-0700 [-] Log opened. 2012-09-05 13:22:02-0700 [-] twistd 12.1.0 (/Users/dreid/.virtualenvs/tracing/bin/python 2.7.2) starting up. 2012-09-05 13:22:02-0700 [-] reactor class: twisted.internet.selectreactor.SelectReactor. 2012-09-05 13:22:02-0700 [-] Site starting on 8080 2012-09-05 13:22:02-0700 [-] Starting factory <twisted.web.server.Site instance at 0x100e78680>
在终端 #2 中,我们将运行客户端,该客户端将向服务器发起一个 HTTP 请求
tryfer> python examples/tracing-client.py [ { "annotations": [ { "type": "string", "value": "http://localhost:8080/README.rst", "key": "http.uri" }, { "type": "timestamp", "value": 1346876525257644, "key": "cs" }, { "type": "timestamp", "value": 1346876525270536, "key": "cr" } ], "trace_id": "00e5f721d19e25fa", "name": "GET", "span_id": "007fe79f2c63db97" } ] Received 200 response.
这里显示了 DebugTracer 的一些输出,它简单地以 JSON 格式将请求的所有注释打印到 stdout。这里我们包含了我们的第一个注释,即我们请求的 http.uri。
现在,在终端 #1 中,我们应该看到以下内容
2012-09-05 13:22:05-0700 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - - [05/Sep/2012:20:22:05 +0000] "GET /README.rst HTTP/1.1" 200 4829 "-" "-" 2012-09-05 13:22:05-0700 [EndAnnotationTracer] Sending trace: (64729494289524218, 36001992872811415) w/ (<tryfer.trace.Annotation object at 0x100e7bb90>,) [ { "annotations": [ { "host": { "service_name": "tracing-server-example", "ipv4": "127.0.0.1", "port": 8080 }, "type": "timestamp", "value": 1346876525268525, "key": "sr" }, { "host": { "service_name": "tracing-server-example", "ipv4": "127.0.0.1", "port": 8080 }, "type": "timestamp", "value": 1346876525270173, "key": "ss" } ], "trace_id": "00e5f721d19e25fa", "name": "GET", "span_id": "007fe79f2c63db97" } ]
许可证
Copyright (C) 2012 Rackspace Hosting, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://apache.ac.cn/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
项目详情
tryfer-0.2.2.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 29d9fed69e5be815095d3e0ea329602618844dcf505db6b7a932e389cbb8a2cc |
|
MD5 | 432b0b59aad58cf210dc97845f3449f2 |
|
BLAKE2b-256 | d3e4a9219659904046f0cdd7d47f62e55fabbb0f311d45d2a99456fa934d0c36 |