Twisted Zipkin跟踪库

tryfer的Python项目详细描述


Zipkin是一个分布式跟踪系统,tryfer是一个python/Twisted客户端 Zipkin图书馆。

它的设计深受Finagle跟踪库的影响。

http跟踪

tryfer本机支持在客户端和 服务器,并通过传递一系列http头来关联这些请求 根据请求。

客户

此对话的客户端是TracingAgent,它使用 twisted的可组合http/1.1客户端架构,用于记录CLIENT_SENDCLIENT_RECV为您的请求添加批注。另外它会记录 请求的完整url作为名为http.uri的字符串批注。

服务器

在服务器上,您可以将应用程序的根资源包装在 TracingWrapperResource,它将自动记录SERVER_RECVSERVER_SEND注释。它还通过 请求参数,以便可以记录额外的注释。

def render(self, request):
  trace = request.getComponent(ITrace)
  trace.record(Annotation.string('name', 'value'))

标题

TracingAgentTracingWrapperResource支持由Finagle定义的头的子集。

  • X-B3-TraceId-十六进制编码的跟踪ID。
  • X-B3-SpanId-hex编码的跨度id.
  • X-B3-ParentSpanId-hex编码的父跨度的跨度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中,我们将运行客户端,该客户端将向 服务器:

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

    http://www.apache.org/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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Clojure关键字在内存中的大小是多少?   Java中有固定长度的通用数组对象吗?   PostgreSQL:通过Java更新我的用户表   错误:使用java解析xml   java Json显示列表中对象的名称   java比较JodaTime时区   与JAVA中的API和包的区别?   java的int值在for循环中不改变   谷歌应用引擎中的java RSA   迁移到spring 5后出现java非法字符错误   java Websphere管理控制台不工作   JavaGSON如何始终在json中包含毫秒?   带有空格和双引号的windows Java ProcessBuilder命令参数失败   java错误:重复的zip条目[43.jar:org/apache/http/annotation/NotThreadSafe.class]