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如何在创建对话框时设置模糊背景   java支持clojure中的xml和json REST响应   java在Android中通过多个JSON对象循环   java如何创建T类型的新对象   Java应用程序的设计   java使用GridView、适配器和毕加索制作流行电影应用程序   java在映射中交换值   java在同一活动/布局中多次使用同一片段   使用FixedLengthTokenizer使用java Spring FlatFileItemReader   javajavax。xml。ws。WebServiceException:javax。xml。肥皂SOAPException:错误代码QName必须是命名空间限定的!在weblogic server 12c中部署时   当我在构造函数中调用java Autowired属性时,该属性为null   线程“main”java中的linux异常。网BindException:地址已在使用中   java检查两个日期周期是否重叠   有没有办法通过安卓应用程序自动检测java服务器应用程序是否在线?   java检查2D数组中4个连续相同的对角线元素(连接4个游戏)   向Java数组添加数据   java组织。弹性搜索。客户运输NoNodeAvailableException:配置的节点均不可用:[]