Module: OpenCensus::Trace::Exporters::JaegerDriver
- Extended by:
- JaegerDriver
- Included in:
- JaegerDriver
- Defined in:
- lib/opencensus/trace/exporters/jaeger_driver.rb,
lib/opencensus/trace/exporters/jaeger_driver/udp_sender.rb,
lib/opencensus/trace/exporters/jaeger_driver/udp_transport.rb,
lib/opencensus/trace/exporters/jaeger_driver/intermediate_transport.rb
Defined Under Namespace
Classes: IntermediateTransport, UDPSender, UDPTransport
Constant Summary collapse
- MAX_64BIT_SIGNED_INT =
(1 << 63) - 1
- MAX_64BIT_UNSIGNED_INT =
(1 << 64) - 1
- TRACE_ID_UPPER_BOUND =
MAX_64BIT_UNSIGNED_INT + 1
- FIELDS =
::Jaeger::Thrift::Tag::FIELDS
- KEY =
FIELDS[::Jaeger::Thrift::Tag::KEY].fetch(:name)
- VTYPE =
FIELDS[::Jaeger::Thrift::Tag::VTYPE].fetch(:name)
- VLONG =
FIELDS[::Jaeger::Thrift::Tag::VLONG].fetch(:name)
- VDOUBLE =
FIELDS[::Jaeger::Thrift::Tag::VDOUBLE].fetch(:name)
- VBOOL =
FIELDS[::Jaeger::Thrift::Tag::VBOOL].fetch(:name)
- VSTR =
FIELDS[::Jaeger::Thrift::Tag::VSTR].fetch(:name)
Instance Method Summary collapse
- #base16_hex_id_to_uint64(id) ⇒ Object
- #base16_hex_to_int64(id) ⇒ Object
- #build_logs(time_events) ⇒ Object
- #build_references(links) ⇒ Object
- #build_span_ref(type) ⇒ Object
- #build_thrift_tags(attributes) ⇒ Object
- #encode_span(span) ⇒ Object
- #ip_v4 ⇒ Object
-
#uint64_id_to_int64(id) ⇒ Object
Thrift defines ID fields as i64, which is signed, therefore we convert large IDs (> 2^63) to negative longs.
Instance Method Details
#base16_hex_id_to_uint64(id) ⇒ Object
71 72 73 74 75 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 71 def base16_hex_id_to_uint64(id) return nil unless id value = id.to_i(16) value > MAX_64BIT_UNSIGNED_INT || value.negative? ? 0 : value end |
#base16_hex_to_int64(id) ⇒ Object
83 84 85 86 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 83 def base16_hex_to_int64(id) uint64_id = base16_hex_id_to_uint64(id) uint64_id_to_int64(uint64_id) end |
#build_logs(time_events) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 128 def build_logs(time_events) time_events.map do |event| ::Jaeger::Thrift::Log.new( 'timestamp' => (event.time.to_f * 1_000_000).to_i, 'fields' => ( 'message.id': event.id, 'message.type': event.type ) ) end end |
#build_references(links) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 140 def build_references(links) links.map do |link| ::Jaeger::Thrift::SpanRef.new( 'refType' => build_span_ref(link.type), 'traceIdLow' => base16_hex_to_int64( link.trace_id.slice(0, 16) ), 'traceIdHigh' => base16_hex_to_int64( link.trace_id.slice(16) ), 'spanId' => base16_hex_to_int64( link.span_id ) ) end end |
#build_span_ref(type) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 157 def build_span_ref(type) case type when OpenCensus::Trace::CHILD_LINKED_SPAN ::Jaeger::Thrift::SpanRefType::CHILD_OF when OpenTracing::Reference::PARENT_LINKED_SPAN ::Jaeger::Thrift::SpanRefType::FOLLOWS_FROM else logger.error "Cannot build thrift reference with #{ref_type}" end end |
#build_thrift_tags(attributes) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 88 def (attributes) attributes.collect do |key, value| begin if value.is_a?(OpenCensus::Trace::TruncatableString) ::Jaeger::Thrift::Tag.new( KEY => key.to_s, VTYPE => ::Jaeger::Thrift::TagType::STRING, VSTR => value.value ) elsif value.is_a?(Integer) ::Jaeger::Thrift::Tag.new( KEY => key.to_s, VTYPE => ::Jaeger::Thrift::TagType::LONG, VLONG => value ) elsif value.is_a?(Float) ::Jaeger::Thrift::Tag.new( KEY => key.to_s, VTYPE => ::Jaeger::Thrift::TagType::DOUBLE, VDOUBLE => value ) elsif value.is_a?(TrueClass) || value.is_a?(FalseClass) ::Jaeger::Thrift::Tag.new( KEY => key.to_s, VTYPE => ::Jaeger::Thrift::TagType::BOOL, VBOOL => value ) else ::Jaeger::Thrift::Tag.new( KEY => key.to_s, VTYPE => ::Jaeger::Thrift::TagType::STRING, VSTR => value.to_s ) end rescue StandardError => e logger.error "Cannot build thrift tags for #{key}:#{value}, error: #{e}" end end end |
#encode_span(span) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 26 def encode_span(span) = (span.attributes) logs = build_logs(span.time_events) references = build_references(span.links) trace_id = span.trace_id trace_id_high = base16_hex_to_int64( trace_id.slice(0, 16) ) trace_id_low = base16_hex_to_int64( trace_id.slice(16, trace_id.size) ) span_id = base16_hex_to_int64( span.span_id ) parent_span_id = base16_hex_to_int64( span.parent_span_id ) operation_name = span.name.value flags = 0x01 start_time = (span.start_time.to_f * 1_000_000).to_i end_time = (span.end_time.to_f * 1_000_000).to_i duration = end_time - start_time ::Jaeger::Thrift::Span.new( 'traceIdLow': trace_id_low, 'traceIdHigh': trace_id_high, 'spanId': span_id, 'parentSpanId': parent_span_id, 'operationName': operation_name, 'references': references, 'flags': flags, 'startTime': start_time, 'duration': duration, 'tags': , 'logs': logs ) rescue StandardError => e puts "convert error #{e}" end |
#ip_v4 ⇒ Object
66 67 68 69 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 66 def ip_v4 ip_v4 = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? } ip_v4.nil? ? nil : ip_v4.ip_address end |
#uint64_id_to_int64(id) ⇒ Object
Thrift defines ID fields as i64, which is signed, therefore we convert large IDs (> 2^63) to negative longs
79 80 81 |
# File 'lib/opencensus/trace/exporters/jaeger_driver.rb', line 79 def uint64_id_to_int64(id) id > MAX_64BIT_SIGNED_INT ? id - MAX_64BIT_UNSIGNED_INT - 1 : id end |