Skip to content

Commit

Permalink
Merge branch 'master' into otlp-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
fbogsany authored Jun 25, 2020
2 parents 78170ec + 5ec6ff5 commit d8ccf45
Show file tree
Hide file tree
Showing 39 changed files with 854 additions and 73 deletions.
2 changes: 1 addition & 1 deletion adapters/all/lib/opentelemetry/adapters/all/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module OpenTelemetry
module Adapters
module All
VERSION = '0.4.0'
VERSION = '0.4.1'
end
end
end
2 changes: 1 addition & 1 deletion adapters/all/opentelemetry-adapters-all.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'opentelemetry-adapters-redis', '~> 0.4.0'
spec.add_dependency 'opentelemetry-adapters-restclient', '~> 0.4.0'
spec.add_dependency 'opentelemetry-adapters-sidekiq', '~> 0.4.0'
spec.add_dependency 'opentelemetry-adapters-sinatra', '~> 0.4.0'
spec.add_dependency 'opentelemetry-adapters-sinatra', '~> 0.4.1'

spec.add_development_dependency 'bundler', '>= 1.17'
spec.add_development_dependency 'minitest', '~> 5.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def stub_response(options)
_(easy.instance_eval { @otel_span }).must_be_nil
_(
easy.instance_eval { @otel_original_headers['traceparent'] }
).must_equal "00-#{span.trace_id}-#{span.span_id}-01"
).must_equal "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01"
end
end

Expand All @@ -112,7 +112,7 @@ def stub_response(options)
_(easy.instance_eval { @otel_span }).must_be_nil
_(
easy.instance_eval { @otel_original_headers['traceparent'] }
).must_equal "00-#{span.trace_id}-#{span.span_id}-01"
).must_equal "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01"
end
end

Expand All @@ -131,7 +131,7 @@ def stub_response(options)
_(easy.instance_eval { @otel_span }).must_be_nil
_(
easy.instance_eval { @otel_original_headers['traceparent'] }
).must_equal "00-#{span.trace_id}-#{span.span_id}-01"
).must_equal "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
assert_requested(
:get,
'http://example.com/success',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end

Expand All @@ -75,7 +75,7 @@
assert_requested(
:get,
'http://example.com/failure',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end

Expand All @@ -99,7 +99,7 @@
assert_requested(
:get,
'http://example.com/timeout',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.url']).must_equal 'http://example.com/success'
_(response.env.request_headers['Traceparent']).must_equal(
"00-#{span.trace_id}-#{span.span_id}-01"
"00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01"
)
end

Expand All @@ -66,7 +66,7 @@
_(span.attributes['http.status_code']).must_equal 404
_(span.attributes['http.url']).must_equal 'http://example.com/not_found'
_(response.env.request_headers['Traceparent']).must_equal(
"00-#{span.trace_id}-#{span.span_id}-01"
"00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01"
)
end

Expand All @@ -78,7 +78,7 @@
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.url']).must_equal 'http://example.com/failure'
_(response.env.request_headers['Traceparent']).must_equal(
"00-#{span.trace_id}-#{span.span_id}-01"
"00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01"
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
assert_requested(
:get,
'http://example.com/success',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end

Expand All @@ -77,7 +77,7 @@
assert_requested(
:post,
'http://example.com/failure',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end

Expand All @@ -103,7 +103,7 @@
assert_requested(
:get,
'https://example.com/timeout',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
end

it 'has no parent' do
_(first_span.parent_span_id).must_equal '0000000000000000'
_(first_span.parent_span_id).must_equal OpenTelemetry::Trace::INVALID_SPAN_ID
end

describe 'config[:allowed_request_headers]' do
Expand Down Expand Up @@ -122,7 +122,7 @@
end

it 'does not parent the request_span' do
_(request_span.parent_span_id).must_equal '0000000000000000'
_(request_span.parent_span_id).must_equal OpenTelemetry::Trace::INVALID_SPAN_ID
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
assert_requested(
:get,
'http://example.com/success',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end

Expand All @@ -72,7 +72,7 @@
assert_requested(
:get,
'http://example.com/failure',
headers: { 'Traceparent' => "00-#{span.trace_id}-#{span.span_id}-01" }
headers: { 'Traceparent' => "00-#{span.trace_id.unpack1('H*')}-#{span.span_id.unpack1('H*')}-01" }
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def perform
let(:adapter) { OpenTelemetry::Adapters::Sidekiq::Adapter.instance }
let(:exporter) { EXPORTER }
let(:spans) { exporter.finished_spans }
let(:root_span) { spans.find { |s| s.parent_span_id == '0000000000000000' } }
let(:root_span) { spans.find { |s| s.parent_span_id == OpenTelemetry::Trace::INVALID_SPAN_ID } }

before { exporter.reset }

Expand All @@ -47,7 +47,7 @@ def perform

_(root_span.name).must_equal 'SimpleJob'
_(root_span.kind).must_equal :producer
_(root_span.parent_span_id).must_equal '0000000000000000'
_(root_span.parent_span_id).must_equal OpenTelemetry::Trace::INVALID_SPAN_ID
_(root_span.attributes['messaging.message_id']).must_equal job_id
_(root_span.attributes['messaging.destination']).must_equal 'default'
_(root_span.events.size).must_equal(1)
Expand All @@ -72,7 +72,7 @@ def perform

_(exporter.finished_spans.size).must_equal 4

_(root_span.parent_span_id).must_equal '0000000000000000'
_(root_span.parent_span_id).must_equal OpenTelemetry::Trace::INVALID_SPAN_ID
_(root_span.name).must_equal 'SimpleEnqueueingJob'
_(root_span.kind).must_equal :producer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module OpenTelemetry
module Adapters
module Sinatra
VERSION = '0.4.0'
VERSION = '0.4.1'
end
end
end
26 changes: 12 additions & 14 deletions api/lib/opentelemetry/trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,30 @@ module OpenTelemetry
# single logical operation, consolidated across various components of an
# application.
module Trace
# An invalid trace identifier, a 16-byte array with all zero bytes, encoded
# as a hexadecimal string.
INVALID_TRACE_ID = ('0' * 32).freeze
# An invalid trace identifier, a 16-byte string with all zero bytes.
INVALID_TRACE_ID = ("\0" * 16).b

# An invalid span identifier, an 8-byte array with all zero bytes, encoded
# as a hexadecimal string.
INVALID_SPAN_ID = ('0' * 16).freeze
# An invalid span identifier, an 8-byte string with all zero bytes.
INVALID_SPAN_ID = ("\0" * 8).b

# Generates a valid trace identifier, a 16-byte array with at least one
# non-zero byte, encoded as a hexadecimal string.
# Generates a valid trace identifier, a 16-byte string with at least one
# non-zero byte.
#
# @return [String] a hexadecimal string encoding of a valid trace ID.
# @return [String] a valid trace ID.
def self.generate_trace_id
loop do
id = Random::DEFAULT.bytes(16).unpack1('H*')
id = Random::DEFAULT.bytes(16)
return id unless id == INVALID_TRACE_ID
end
end

# Generates a valid span identifier, an 8-byte array with at least one
# non-zero byte, encoded as a hexadecimal string.
# Generates a valid span identifier, an 8-byte string with at least one
# non-zero byte.
#
# @return [String] a hexadecimal string encoding of a valid span ID.
# @return [String] a valid span ID.
def self.generate_span_id
loop do
id = Random::DEFAULT.bytes(8).unpack1('H*')
id = Random::DEFAULT.bytes(8)
return id unless id == INVALID_SPAN_ID
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class TraceParent
REGEXP = /^(?<version>[A-Fa-f0-9]{2})-(?<trace_id>[A-Fa-f0-9]{32})-(?<span_id>[A-Fa-f0-9]{16})-(?<flags>[A-Fa-f0-9]{2})(?<ignored>-.*)?$/.freeze
private_constant :REGEXP

INVALID_TRACE_ID = OpenTelemetry::Trace::INVALID_TRACE_ID.unpack1('H*')
INVALID_SPAN_ID = OpenTelemetry::Trace::INVALID_SPAN_ID.unpack1('H*')
private_constant :INVALID_TRACE_ID, :INVALID_SPAN_ID

class << self
# Creates a new {TraceParent} from a supplied {Trace::SpanContext}
# @param [SpanContext] ctx The context
Expand Down Expand Up @@ -71,17 +75,17 @@ def parse_version(string)
end

def parse_trace_id(string)
raise InvalidTraceIDError, string if string == OpenTelemetry::Trace::INVALID_TRACE_ID
raise InvalidTraceIDError, string if string == INVALID_TRACE_ID

string.downcase!
string
Array(string).pack('H*')
end

def parse_span_id(string)
raise InvalidSpanIDError, string if string == OpenTelemetry::Trace::INVALID_SPAN_ID
raise InvalidSpanIDError, string if string == INVALID_SPAN_ID

string.downcase!
string
Array(string).pack('H*')
end

def parse_flags(string)
Expand All @@ -102,7 +106,7 @@ def sampled?
# converts this object into a string according to the w3c spec
# @return [String] the serialized trace_parent
def to_s
"00-#{trace_id}-#{span_id}-#{flag_string}"
"00-#{trace_id.unpack1('H*')}-#{span_id.unpack1('H*')}-#{flag_string}"
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
ctx = extractor.extract(carrier, context) { |c, k| c[k] }
span_context = ctx[span_context_key]
_(span_context).must_be :remote?
_(span_context.trace_id).must_equal('000000000000000000000000000000aa')
_(span_context.span_id).must_equal('00000000000000ea')
_(span_context.trace_id).must_equal(("\0" * 15 + "\xaa").b)
_(span_context.span_id).must_equal(("\0" * 7 + "\xea").b)
_(span_context.trace_flags).must_be :sampled?
_(span_context.tracestate).must_equal('vendorname=opaquevalue')
end
Expand All @@ -58,8 +58,8 @@
ctx = extractor.extract(carrier, context)
span_context = ctx[span_context_key]
_(span_context).must_be :remote?
_(span_context.trace_id).must_equal('000000000000000000000000000000aa')
_(span_context.span_id).must_equal('00000000000000ea')
_(span_context.trace_id).must_equal(("\0" * 15 + "\xaa").b)
_(span_context.span_id).must_equal(("\0" * 7 + "\xea").b)
_(span_context.trace_flags).must_be :sampled?
_(span_context.tracestate).must_equal('vendorname=opaquevalue')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
end
let(:tracestate_header) { 'vendorname=opaquevalue' }
let(:context) do
span_context = SpanContext.new(trace_id: 'f' * 32, span_id: '1' * 16)
span_context = SpanContext.new(trace_id: ("\xff" * 16).b, span_id: ("\x11" * 8).b)
span = Span.new(span_context: span_context)
Context.empty.set_value(current_span_key, span)
end
let(:context_with_tracestate) do
span_context = SpanContext.new(trace_id: 'f' * 32, span_id: '1' * 16,
span_context = SpanContext.new(trace_id: ("\xff" * 16).b, span_id: ("\x11" * 8).b,
tracestate: tracestate_header)
span = Span.new(span_context: span_context)
Context.empty.set_value(current_span_key, span)
end
let(:context_without_current_span) do
span_context = SpanContext.new(trace_id: 'f' * 32, span_id: '1' * 16,
span_context = SpanContext.new(trace_id: ("\xff" * 16).b, span_id: ("\x11" * 8).b,
tracestate: tracestate_header)
Context.empty.set_value(extracted_span_context_key, span_context)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe '.to_s' do
it 'formats it correctly' do
expected = "00-#{good.trace_id}-#{good.span_id}-01"
expected = "00-#{good.trace_id.unpack1('H*')}-#{good.span_id.unpack1('H*')}-01"
_(good.to_s).must_equal(expected)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def encoded_span(span_data) # rubocop:disable Metrics/AbcSize
duration = (span_data.end_timestamp.to_f * 1_000_000).to_i - start_time

Thrift::Span.new(
'traceIdLow' => int64(span_data.trace_id[16, 16]),
'traceIdHigh' => int64(span_data.trace_id[0, 16]),
'traceIdLow' => int64(span_data.trace_id[8, 8]),
'traceIdHigh' => int64(span_data.trace_id[0, 8]),
'spanId' => int64(span_data.span_id),
'parentSpanId' => int64(span_data.parent_span_id),
'operationName' => span_data.name,
Expand Down Expand Up @@ -106,8 +106,8 @@ def encoded_tag(key, value)
)
end

def int64(hex_string)
int = hex_string.to_i(16)
def int64(byte_string)
int = byte_string.unpack1('Q>')
int < (1 << 63) ? int : int - (1 << 64)
end
end
Expand Down
26 changes: 26 additions & 0 deletions resource-detectors/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
AllCops:
TargetRubyVersion: '2.5.0'

Bundler/OrderedGems:
Exclude:
- gemfiles/**/*
Lint/UnusedMethodArgument:
Enabled: false
Metrics/AbcSize:
Max: 18
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Style/FrozenStringLiteralComment:
Exclude:
- gemfiles/**/*
Style/ModuleFunction:
Enabled: false
Style/StringLiterals:
Exclude:
- gemfiles/**/*
Metrics/BlockLength:
Enabled: false
Loading

0 comments on commit d8ccf45

Please sign in to comment.