本文整理汇总了Python中tryfer.trace.Annotation类的典型用法代码示例。如果您正苦于以下问题:Python Annotation类的具体用法?Python Annotation怎么用?Python Annotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Annotation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: fetch
def fetch(self, request, *args, **kwargs):
method, url = _request_info(request)
ZipkinTracer.record(Annotation.string('Url', url))
ZipkinTracer.record(Annotation.client_send())
response = super(HTTPClient, self).fetch(request, *args, **kwargs)
ZipkinTracer.record(Annotation.client_recv())
return response
开发者ID:iambocai,项目名称:tornado_tracing,代码行数:7,代码来源:recording.py
示例2: __init__
def __init__(self, method, uri, version="HTTP/1.0", headers=None,
body=None, remote_ip=None, protocol=None, host=None,
files=None, connection=None):
self.method = method
self.uri = uri
self.version = version
self.headers = headers or httputil.HTTPHeaders()
self.body = body or ""
self.trace = None
# set remote IP and protocol
self.remote_ip = remote_ip
if protocol:
self.protocol = protocol
elif connection and isinstance(connection.stream,
iostream.SSLIOStream):
self.protocol = "https"
else:
self.protocol = "http"
# xheaders can override the defaults
if connection and connection.xheaders:
# Squid uses X-Forwarded-For, others use X-Real-Ip
ip = self.headers.get("X-Forwarded-For", self.remote_ip)
ip = ip.split(',')[-1].strip()
ip = self.headers.get(
"X-Real-Ip", ip)
if netutil.is_valid_ip(ip):
self.remote_ip = ip
# AWS uses X-Forwarded-Proto
proto = self.headers.get(
"X-Scheme", self.headers.get("X-Forwarded-Proto", self.protocol))
if proto in ("http", "https"):
self.protocol = proto
# Zipkin users
if options.server_trace:
parent_span_id = self.headers.get("X-B3-ParentSpanId", None)
trace_id = self.headers.get("X-B3-TraceId", None)
span_id = self.headers.get("X-B3-SpanId", None)
name = method
endpoint = Endpoint(ipv4=socket.gethostbyname(socket.gethostname()), port=port, service_name=service_name)
self.trace = Trace(name=name, trace_id=trace_id, span_id=span_id, parent_span_id=parent_span_id)
self.trace.set_endpoint(endpoint)
self.host = host or self.headers.get("Host") or "127.0.0.1"
self.files = files or {}
self.connection = connection
self._start_time = time.time()
self._finish_time = None
self.path, sep, self.query = uri.partition('?')
self.arguments = parse_qs_bytes(self.query, keep_blank_values=True)
self.query_arguments = copy.deepcopy(self.arguments)
self.body_arguments = {}
if options.server_trace:
self.trace.record(Annotation.string('Url', uri))
self.trace.record(Annotation.string('Header', self.headers))
self.trace.record(Annotation.server_recv())
开发者ID:iambocai,项目名称:tornado,代码行数:60,代码来源:httpserver.py
示例3: test_handles_batched_traces
def test_handles_batched_traces(self):
t1 = Trace('test', 1, 2)
t2 = Trace('test2', 3, 4)
cs1 = Annotation.client_send(1)
cs2 = Annotation.client_send(2)
cr1 = Annotation.client_recv(3)
cr2 = Annotation.client_recv(4)
self.tracer.record([(t1, [cs1, cr1]), (t2, [cs2, cr2])])
self.assertEqual(self.scribe.log.call_count, 1)
args = self.scribe.log.mock_calls[0][1]
self.assertEqual('restkin', args[0])
entries = args[1]
self.assertEqual(len(entries), 1)
self.assertEqual(
json.loads(entries[0]),
[{'trace_id': '0000000000000001',
'span_id': '0000000000000002',
'name': 'test',
'annotations': [
{'type': 'timestamp', 'value': 1, 'key': 'cs'},
{'type': 'timestamp', 'value': 3, 'key': 'cr'}]},
{'trace_id': '0000000000000003',
'span_id': '0000000000000004',
'name': 'test2',
'annotations': [
{'type': 'timestamp', 'value': 2, 'key': 'cs'},
{'type': 'timestamp', 'value': 4, 'key': 'cr'}]}])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:33,代码来源:test_tracers.py
示例4: render_POST
def render_POST(self, request):
print "For CORS by john"
request.setHeader('Access-Control-Allow-Origin', '*')
request.setHeader('Access-Control-Allow-Methods', 'POST')
request.setHeader('Access-Control-Allow-Headers', 'authorization, content-type')
request.responseHeaders.setRawHeaders(
'content-type', ['application/json'])
body = request.content.read()
try:
spans = json.loads(body)
except ValueError:
log.err(None, 'Failed to decode request body')
msg = 'Could not decode request body (invalid JSON)'
return json.dumps({'error': msg})
succeeded, failed = 0, 0
for json_span in spans:
trace_id = None
span_id = None
try:
trace_id = decode_hex_number('trace_id', json_span['trace_id'])
span_id = decode_hex_number('span_id', json_span['span_id'])
parent_span_id = json_span.get('parent_span_id', None)
if parent_span_id is not None:
parent_span_id = decode_hex_number('parent_span_id',
parent_span_id)
t = Trace(json_span['name'], trace_id, span_id, parent_span_id)
for json_annotation in json_span['annotations']:
annotation = Annotation(
json_annotation['key'],
json_annotation['value'],
json_annotation['type'])
host = json_annotation.get('host', None)
if host:
annotation.endpoint = Endpoint(
host['ipv4'], host['port'], host['service_name'])
t.record(annotation)
succeeded = succeeded + 1
except Exception:
log.err(None,
'Failed to insert a trace: trace_id=%r,span_id=%r' %
(trace_id, span_id))
failed = failed + 1
continue
return json.dumps({'succeeded': succeeded, 'failed': failed})
开发者ID:zhaoxuan,项目名称:restkin,代码行数:59,代码来源:api.py
示例5: _finished
def _finished(resp):
# TODO: It may be advantageous here to return a wrapped response
# whose deliverBody can wrap it's protocol and record when the
# application has finished reading the contents.
trace.record(Annotation.string(
'http.responsecode',
'{0} {1}'.format(resp.code, resp.phrase)))
trace.record(Annotation.client_recv())
return resp
开发者ID:andrew-plunk,项目名称:tryfer,代码行数:9,代码来源:http.py
示例6: test_traces_buffered_until_max_idle_time
def test_traces_buffered_until_max_idle_time(self):
completed_trace = (Trace('completed'), [Annotation.client_send(1),
Annotation.client_recv(2)])
self.tracer.record([completed_trace])
self.assertEqual(self.record_function.call_count, 0)
self.clock.advance(10)
self.assertEqual(self.record_function.call_count, 1)
开发者ID:jaredlwong,项目名称:tryfer,代码行数:10,代码来源:test_tracers.py
示例7: test_logs_to_scribe_with_non_default_category
def test_logs_to_scribe_with_non_default_category(self):
tracer = RawZipkinTracer(self.scribe, 'not-zipkin')
t = Trace('test_raw_zipkin', 1, 2, tracers=[tracer])
t.record(Annotation.client_send(1), Annotation.client_recv(2))
self.scribe.log.assert_called_once_with(
'not-zipkin',
['CgABAAAAAAAAAAELAAMAAAAPdGVzdF9yYXdfemlwa2luCgAEAAAAAAAAAAIPAAY'
'MAAAAAgoAAQAA\nAAAAAAABCwACAAAAAmNzAAoAAQAAAAAAAAACCwACAAAAAmNy'
'AA8ACAwAAAAAAA=='])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:11,代码来源:test_tracers.py
示例8: test_delegates_on_end_annotation
def test_delegates_on_end_annotation(self):
tracer = EndAnnotationTracer(self.tracer)
t = Trace('test_delegation', tracers=[tracer])
cs = Annotation.client_send()
ce = Annotation.client_recv()
t.record(cs)
t.record(ce)
self.tracer.record.assert_called_once_with([(t, [cs, ce])])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:12,代码来源:test_tracers.py
示例9: request
def request(self, method, uri, headers=None, bodyProducer=None):
"""
Send a client request following HTTP redirects.
@see: L{Agent.request}.
"""
if self._parent_trace is None:
trace = Trace(method)
else:
trace = self._parent_trace.child(method)
if self._endpoint is not None:
trace.set_endpoint(self._endpoint)
if headers is None:
headers = Headers({})
# These headers are based on the headers used by finagle's tracing
# http Codec.
#
# https://github.com/twitter/finagle/blob/master/finagle-http/
#
# Currently not implemented are X-B3-Sampled and X-B3-Flags
# Tryfer's underlying Trace implementation has no notion of a Sampled
# trace and I haven't figured out what flags are for.
headers.setRawHeaders('X-B3-TraceId', [hex_str(trace.trace_id)])
headers.setRawHeaders('X-B3-SpanId', [hex_str(trace.span_id)])
if trace.parent_span_id is not None:
headers.setRawHeaders('X-B3-ParentSpanId',
[hex_str(trace.parent_span_id)])
# Similar to the headers above we use the annotation 'http.uri' for
# because that is the standard set forth in the finagle http Codec.
trace.record(Annotation.string('http.uri', uri))
trace.record(Annotation.client_send())
def _finished(resp):
# TODO: It may be advantageous here to return a wrapped response
# whose deliverBody can wrap it's protocol and record when the
# application has finished reading the contents.
trace.record(Annotation.string(
'http.responsecode',
'{0} {1}'.format(resp.code, resp.phrase)))
trace.record(Annotation.client_recv())
return resp
d = self._agent.request(method, uri, headers, bodyProducer)
d.addBoth(_finished)
return d
开发者ID:andrew-plunk,项目名称:tryfer,代码行数:51,代码来源:http.py
示例10: test_non_default_end
def test_non_default_end(self):
tracer = EndAnnotationTracer(self.tracer, end_annotations=['timeout'])
t = Trace('test_non-default', tracers=[tracer])
cs = Annotation.client_send()
t.record(cs)
timeout = Annotation.timestamp('timeout')
t.record(timeout)
self.tracer.record.assert_called_once_with([(t, [cs, timeout])])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:14,代码来源:test_tracers.py
示例11: test_traces_bufferred_until_max_traces
def test_traces_bufferred_until_max_traces(self):
completed_traces = [
(Trace('completed'), [Annotation.client_send(1),
Annotation.client_recv(2)])
for x in xrange(50)]
self.tracer.record(completed_traces[:10])
self.clock.advance(1)
self.assertEqual(self.record_function.call_count, 0)
self.tracer.record(completed_traces[10:])
self.clock.advance(1)
self.assertEqual(self.record_function.call_count, 1)
开发者ID:jaredlwong,项目名称:tryfer,代码行数:15,代码来源:test_tracers.py
示例12: handle_response
def handle_response(response):
if response.error:
future.set_exception(response.error)
else:
future.set_result(response)
if options.client_trace:
request.trace.record(Annotation.client_recv())
开发者ID:iambocai,项目名称:tornado,代码行数:7,代码来源:httpclient.py
示例13: getChildWithDefault
def getChildWithDefault(self, path, request):
headers = request.requestHeaders
# Construct and endpoint from the requested host and port and the
# passed service name.
host = request.getHost()
endpoint = Endpoint(host.host, host.port, self._service_name)
# Construct the trace using the headers X-B3-* headers that the
# TracingAgent will send.
trace = Trace(
request.method,
int_or_none(headers.getRawHeaders('X-B3-TraceId', [None])[0]),
int_or_none(headers.getRawHeaders('X-B3-SpanId', [None])[0]),
int_or_none(headers.getRawHeaders('X-B3-ParentSpanId', [None])[0]))
trace.set_endpoint(endpoint)
# twisted.web.server.Request is a subclass of Componentized this
# allows us to use ITrace(request) to get the trace and object (and
# create children of this trace) in the wrapped resource.
request.setComponent(ITrace, trace)
trace.record(Annotation.server_recv())
def _record_finish(_ignore):
trace.record(Annotation.server_send())
# notifyFinish returns a deferred that fires when the request is
# finished this will allow us to record server_send regardless of if
# the wrapped resource us using deferred rendering.
request.notifyFinish().addCallback(_record_finish)
return self._wrapped.getChildWithDefault(path, request)
开发者ID:andrew-plunk,项目名称:tryfer,代码行数:35,代码来源:http.py
示例14: test_record_invokes_tracer
def test_record_invokes_tracer(self):
tracer = mock.Mock()
t = Trace('test_trace', trace_id=1, span_id=1, tracers=[tracer])
annotation = Annotation.client_send(timestamp=0)
t.record(annotation)
tracer.record.assert_called_with([(t, (annotation,))])
开发者ID:andrew-plunk,项目名称:tryfer,代码行数:8,代码来源:test_trace.py
示例15: test_logs_to_scribe_immediately
def test_logs_to_scribe_immediately(self):
tracer = RawZipkinTracer(self.scribe)
t = Trace('test_raw_zipkin', 1, 2, tracers=[tracer])
t.record(Annotation.client_send(1))
self.scribe.log.assert_called_once_with(
'zipkin',
['CgABAAAAAAAAAAELAAMAAAAPdGVzdF9yYXdfemlwa2luCgAEAAAAAAAAAAIPAAY'
'MAAAAAQoAAQAA\nAAAAAAABCwACAAAAAmNzAA8ACAwAAAAAAA=='])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:9,代码来源:test_tracers.py
示例16: test_writes_trace
def test_writes_trace(self):
t = Trace('test', 1, 2, tracers=[self.tracer])
t.record(Annotation.client_send(1))
self.assertEqual(
json.loads(self.destination.getvalue()),
[{'trace_id': '0000000000000001',
'span_id': '0000000000000002',
'name': 'test',
'annotations': [
{'type': 'timestamp', 'value': 1, 'key': 'cs'}]}])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:11,代码来源:test_tracers.py
示例17: test_record_sets_annotation_endpoint
def test_record_sets_annotation_endpoint(self):
tracer = mock.Mock()
web_endpoint = Endpoint('127.0.0.1', 8080, 'web')
t = Trace('test_trace', trace_id=1, span_id=1, tracers=[tracer])
t.set_endpoint(web_endpoint)
annotation = Annotation.client_send(timestamp=1)
t.record(annotation)
tracer.record.assert_called_with([(t, (annotation,))])
self.assertEqual(annotation.endpoint, web_endpoint)
开发者ID:andrew-plunk,项目名称:tryfer,代码行数:12,代码来源:test_trace.py
示例18: finish
def finish(self):
"""Finishes this HTTP request on the open connection."""
if options.server_trace:
self.headers.set("X-B3-TraceId", [hex_str(self.trace.trace_id)])
self.headers.set("X-B3-SpanId", [hex_str(self.trace.span_id)])
if self.trace.parent_span_id is not None:
self.headers.set("X-B3-ParentSpanId", [hex_str(self.trace.parent_span_id)])
self.trace.record(Annotation.server_send())
self.connection.finish()
self._finish_time = time.time()
开发者ID:iambocai,项目名称:tornado,代码行数:13,代码来源:httpserver.py
示例19: fetch
def fetch(self, request, callback=None, **kwargs):
"""Executes a request, asynchronously returning an `HTTPResponse`.
The request may be either a string URL or an `HTTPRequest` object.
If it is a string, we construct an `HTTPRequest` using any additional
kwargs: ``HTTPRequest(request, **kwargs)``
This method returns a `.Future` whose result is an
`HTTPResponse`. The ``Future`` wil raise an `HTTPError` if
the request returned a non-200 response code.
If a ``callback`` is given, it will be invoked with the `HTTPResponse`.
In the callback interface, `HTTPError` is not automatically raised.
Instead, you must check the response's ``error`` attribute or
call its `~HTTPResponse.rethrow` method.
"""
if not isinstance(request, HTTPRequest):
request = HTTPRequest(url=request, **kwargs)
# We may modify this (to add Host, Accept-Encoding, etc),
# so make sure we don't modify the caller's object. This is also
# where normal dicts get converted to HTTPHeaders objects.
request.headers = httputil.HTTPHeaders(request.headers)
if options.client_trace:
request.trace.record(Annotation.client_send())
request = _RequestProxy(request, self.defaults)
future = TracebackFuture()
if callback is not None:
callback = stack_context.wrap(callback)
def handle_future(future):
exc = future.exception()
if isinstance(exc, HTTPError) and exc.response is not None:
response = exc.response
elif exc is not None:
response = HTTPResponse(
request, 599, error=exc,
request_time=time.time() - request.start_time)
else:
response = future.result()
self.io_loop.add_callback(callback, response)
future.add_done_callback(handle_future)
def handle_response(response):
if response.error:
future.set_exception(response.error)
else:
future.set_result(response)
if options.client_trace:
request.trace.record(Annotation.client_recv())
self.fetch_impl(request, handle_response)
return future
开发者ID:iambocai,项目名称:tornado,代码行数:51,代码来源:httpclient.py
示例20: test_posts_immediately
def test_posts_immediately(self):
self.trace.record(Annotation.client_send(1))
self.assertEqual(self.agent.request.call_count, 1)
args = self.agent.request.mock_calls[0][1]
self.assertEqual(('POST', 'http://trace.it', Headers({})), args[:3])
bodyProducer = args[3]
return self.assertBodyEquals(
bodyProducer,
[{'trace_id': '0000000000000001',
'span_id': '0000000000000002',
'name': 'test',
'annotations': [
{'type': 'timestamp', 'value': 1, 'key': 'cs'}
]}])
开发者ID:jaredlwong,项目名称:tryfer,代码行数:18,代码来源:test_tracers.py
注:本文中的tryfer.trace.Annotation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论