-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright 2019 OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Trace | ||
# No-op implementation of a tracer factory. | ||
class TracerFactory | ||
# Returns a {Tracer} instance. | ||
# | ||
# @param [optional String] name Instrumentation package name | ||
# @param [optional String] version Instrumentation package version | ||
# | ||
# @return [Tracer] | ||
def tracer(name = nil, version = nil) | ||
@tracer ||= Tracer.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright 2019 OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::Trace::TracerFactory do | ||
let(:tracer_factory) { OpenTelemetry::Trace::TracerFactory.new } | ||
|
||
describe '.tracer' do | ||
it 'returns the same tracer for the same arguments' do | ||
tracer1 = tracer_factory.tracer('component', 'semver:1.0') | ||
tracer2 = tracer_factory.tracer('component', 'semver:1.0') | ||
_(tracer1).must_equal(tracer2) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright 2019 OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module SDK | ||
module Trace | ||
# No-op implementation of a tracer factory. | ||
class TracerFactory | ||
Key = Struct.new(:name, :version) | ||
private_constant(:Key) | ||
|
||
# Returns a new {TracerFactory} instance. | ||
# | ||
# @return [TracerFactory] | ||
def initialize | ||
@mutex = Mutex.new | ||
@registry = {} | ||
end | ||
|
||
# Returns a {Tracer} instance. | ||
# | ||
# @param [optional String] name Instrumentation package name | ||
# @param [optional String] version Instrumentation package version | ||
# | ||
# @return [Tracer] | ||
def tracer(name = nil, version = nil) | ||
name ||= '' | ||
version ||= '' | ||
@mutex.synchronize { @registry[Key.new(name, version)] ||= Tracer.new(name, version) } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright 2019 OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::SDK::Trace::TracerFactory do | ||
let(:tracer_factory) { OpenTelemetry::SDK::Trace::TracerFactory.new } | ||
|
||
describe '.tracer' do | ||
it 'returns the same tracer for the same arguments' do | ||
tracer1 = tracer_factory.tracer('component', 'semver:1.0') | ||
tracer2 = tracer_factory.tracer('component', 'semver:1.0') | ||
_(tracer1).must_equal(tracer2) | ||
end | ||
|
||
it 'returns a default name-less version-less tracer' do | ||
tracer = tracer_factory.tracer | ||
_(tracer.name).must_equal('') | ||
_(tracer.version).must_equal('') | ||
end | ||
|
||
it 'returns different tracers for different names' do | ||
tracer1 = tracer_factory.tracer('component1', 'semver:1.0') | ||
tracer2 = tracer_factory.tracer('component2', 'semver:1.0') | ||
_(tracer1).wont_equal(tracer2) | ||
end | ||
|
||
it 'returns different tracers for different versions' do | ||
tracer1 = tracer_factory.tracer('component', 'semver:1.0') | ||
tracer2 = tracer_factory.tracer('component', 'semver:2.0') | ||
_(tracer1).wont_equal(tracer2) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters