]>
git.proxmox.com Git - ceph.git/blob - ceph/src/blkin/babeltrace-plugins/zipkin/src/zipkin_logic/trace.py
8 An L{ITrace} provider which delegates to zero or more L{ITracers} and
9 allows setting a default L{IEndpoint} to associate with L{IAnnotation}s
11 @ivar _tracers: C{list} of one or more L{ITracer} providers.
12 @ivar _endpoint: An L{IEndpoint} provider.
14 def __init__(self
, name
, trace_id
=None, span_id
=None,
15 parent_span_id
=None, tracers
=None):
17 @param name: C{str} describing the current span.
18 @param trace_id: C{int} or C{None}
19 @param span_id: C{int} or C{None}
20 @param parent_span_id: C{int} or C{None}
22 @param tracers: C{list} of L{ITracer} providers, primarily useful
26 # If no trace_id and span_id are given we want to generate new
28 self
.trace_id
= trace_id
29 self
.span_id
= span_id
31 # If no parent_span_id is given then we assume there is no parent span
32 # and leave it as None.
33 self
.parent_span_id
= parent_span_id
35 # If no tracers are given we get the global list of tracers.
36 self
._tracers
= tracers
38 # By default no endpoint will be associated with annotations recorded
42 def __ne__(self
, other
):
43 return not self
== other
47 '{0.__class__.__name__}({0.name!r}, trace_id={0.trace_id!r}, '
48 'span_id={0.span_id!r}, parent_span_id={0.parent_span_id!r})'
51 def set_endpoint(self
, endpoint
):
53 Set a default L{IEndpoint} provider for the current L{Trace}.
54 All annotations recorded after this endpoint is set will use it,
55 unless they provide their own endpoint.
57 self
._endpoint
= endpoint
60 class Endpoint(object):
62 def __init__(self
, ipv4
, port
, service_name
):
64 @param ipv4: C{str} ipv4 address.
65 @param port: C{int} port number.
66 @param service_name: C{str} service name.
70 self
.service_name
= service_name
72 def __ne__(self
, other
):
73 return not self
== other
76 return ('{0.__class__.__name__}({0.ipv4!r}, {0.port!r}, '
77 '{0.service_name!r})').format(self
)
80 class Annotation(object):
82 def __init__(self
, name
, value
, annotation_type
, endpoint
=None):
84 @param name: C{str} name of this annotation.
86 @param value: A value of the appropriate type based on
89 @param annotation_type: C{str} the expected type of our C{value}.
91 @param endpoint: An optional L{IEndpoint} provider to associate with
92 this annotation or C{None}
96 self
.annotation_type
= annotation_type
97 self
.endpoint
= endpoint
99 def __ne__(self
, other
):
100 return not self
== other
104 '{0.__class__.__name__}({0.name!r}, {0.value!r}, '
105 '{0.annotation_type!r}, {0.endpoint})'
109 def timestamp(cls
, name
, timestamp
=None):
110 if timestamp
is None:
111 timestamp
= math
.trunc(time
.time() * 1000 * 1000)
113 return cls(name
, timestamp
, 'timestamp')
116 def client_send(cls
, timestamp
=None):
117 return cls
.timestamp(constants
.CLIENT_SEND
, timestamp
)
120 def client_recv(cls
, timestamp
=None):
121 return cls
.timestamp(constants
.CLIENT_RECV
, timestamp
)
124 def server_send(cls
, timestamp
=None):
125 return cls
.timestamp(constants
.SERVER_SEND
, timestamp
)
128 def server_recv(cls
, timestamp
=None):
129 return cls
.timestamp(constants
.SERVER_RECV
, timestamp
)
132 def string(cls
, name
, value
):
133 return cls(name
, value
, 'string')
136 def bytes(cls
, name
, value
):
137 return cls(name
, value
, 'bytes')