Skip to content

Commit

Permalink
Adjust tracer to use instrumentation library
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlaurin committed May 25, 2020
1 parent c012c60 commit ec04cac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
9 changes: 5 additions & 4 deletions sdk/lib/opentelemetry/sdk/trace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ module SDK
module Trace
# {Tracer} is the SDK implementation of {OpenTelemetry::Trace::Tracer}.
class Tracer < OpenTelemetry::Trace::Tracer
attr_reader :resource
attr_reader :name
attr_reader :version

# @api private
#
# Returns a new {Tracer} instance.
#
# @param [Resource] resource Containing name and version arguments supplied to the TracerProvider
# @param [InstrumentationLibrary] resource Containing name and version arguments supplied to the TracerProvider
#
# @return [Tracer]
def initialize(name, version)
@name = name
@version = version
@resource = Resources::Resource.create('name' => name, 'version' => version)
@instrumentation_library = InstrumentationLibrary.new(name, version)
end

Expand Down Expand Up @@ -54,7 +54,8 @@ def internal_create_span(result, name, kind, trace_id, span_id, parent_span_id,
attributes = attributes&.merge(result.attributes) || result.attributes
active_trace_config = OpenTelemetry.tracer_provider.active_trace_config
active_span_processor = OpenTelemetry.tracer_provider.active_span_processor
Span.new(context, name, kind, parent_span_id, active_trace_config, active_span_processor, attributes, links, start_timestamp || Time.now, @resource, @instrumentation_library)
resource = OpenTelemetry.tracer_provider.resource
Span.new(context, name, kind, parent_span_id, active_trace_config, active_span_processor, attributes, links, start_timestamp || Time.now, resource, @instrumentation_library)
else
OpenTelemetry::Trace::Span.new(span_context: OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id))
end
Expand Down
6 changes: 2 additions & 4 deletions sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class TracerProvider < OpenTelemetry::Trace::TracerProvider
private_constant(:Key)

attr_accessor :active_trace_config
attr_reader :active_span_processor
attr_reader :stopped
attr_reader :active_span_processor, :stopped, :resource
alias stopped? stopped

# Returns a new {TracerProvider} instance.
Expand All @@ -39,8 +38,7 @@ def initialize(resource = OpenTelemetry::SDK::Resources::Resource.create)
def tracer(name = nil, version = nil)
name ||= ''
version ||= ''
resource = @resource.merge(OpenTelemetry::SDK::Resources::Resource.create('name' => name, 'version' => version))
@mutex.synchronize { @registry[Key.new(name, version)] ||= Tracer.new(resource) }
@mutex.synchronize { @registry[Key.new(name, version)] ||= Tracer.new(name, version) }
end

# Attempts to stop all the activity for this {Tracer}. Calls
Expand Down
3 changes: 2 additions & 1 deletion sdk/test/opentelemetry/sdk/trace/tracer_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@

it 'returns a default name-less version-less tracer' do
tracer = tracer_provider.tracer
_(tracer.resource.label_enumerator.to_h).must_equal('name' => '', 'version' => '')
_(tracer.name).must_equal('')
_(tracer.version).must_equal('')
end

it 'returns different tracers for different names' do
Expand Down
8 changes: 0 additions & 8 deletions sdk/test/opentelemetry/sdk/trace/tracer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
->(trace_id:, span_id:, parent_context:, links:, name:, kind:, attributes:) { Result.new(decision: Decision::RECORD) } # rubocop:disable Lint/UnusedBlockArgument
end

describe '#resource' do
let(:resource) { OpenTelemetry::SDK::Resources::Resource.create('name' => 'component', 'version' => 'semver:1.0') }

it 'reflects the resource passed in' do
_(Tracer.new(resource).resource).must_equal(resource)
end
end

describe '#start_root_span' do
it 'provides a default name' do
_(tracer.start_root_span(nil).name).wont_be_nil
Expand Down

0 comments on commit ec04cac

Please sign in to comment.