This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
forked from open-telemetry/opentelemetry-ruby
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Adjust existing Metrics SDK code to match changes to API #1
Closed
elias19r
wants to merge
33
commits into
elias/meter-and-instrument-creation-api
from
elias/adjust-existing-metrics-sdk-code-to-match-api
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d6c26fd
Move attr_reader from SDK to API in MeterProvider
elias19r 0876408
Call initialize from API in SDK MeterProvider and set Resource to def…
elias19r 1dd9e6f
Move private_constant :Key from SDK to API in MeterProvider
elias19r 20ead90
Update InstrumentationScope to include schema_url and attributes
elias19r ca7d03b
Add @instrumentation_scope to Meter in API
elias19r 1555a62
Update Key, the Meter identifier, to include schema_url
elias19r f5d3f03
Update MeterProvider#meter in SDK
elias19r 159341d
Update ProxyMeterProvider to match API
elias19r c33b137
Update ProxyMeter to match API
elias19r f25ce0b
Make Proxy Instruments inherit from API Instruments
elias19r f21c303
Require ProxyInstrument files
elias19r 30854b3
Adjust SDK Meter to use register_instrument
elias19r 508e19f
Add method #build_key_for_meter
elias19r 5db4749
Remove SDK's SynchronousInstrument class
elias19r d8d929b
Add #kind method to instruments
elias19r f7041b4
Not passing meter_provider down to meter and instruments
elias19r d442a9d
Move default_aggregation to MeterProvider
elias19r 94bcd68
Make SDK metric Instruments inherit from API Instruments
elias19r 7590c1d
Remove initialize methods from SDK async instruments
elias19r 838c516
Remove require for SDK synchronous_instrument
elias19r a216f51
Add comment with agregation link to docs
elias19r 06b3c01
Keep InstrumentationScope in SDK
elias19r a2ebb48
Add mutex for @delegate
elias19r f438baf
Trying to understando MetricData
elias19r 8c21fed
Merge branch 'elias/meter-and-instrument-creation-api' into elias/adj…
elias19r 722035b
Add more details to SDK Meter test
elias19r acf5815
Add more details to MeterProvider test
elias19r 34fa220
Make Meter hold a reference to MeterProvider
elias19r cef1294
Build and create metric stream in Meter whenever a sync instrument is…
elias19r a76cb3e
Add empty LastValue aggregation class
elias19r e0b50ef
Define default aggregation for instruments
elias19r 19addcc
Make add_metric_stream methods similiar
elias19r 63b6015
Make Aggregation::Sum test examples more verbose
elias19r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions
26
metrics_api/lib/opentelemetry/internal/proxy_instrument/counter.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
class Counter < Metrics::Instrument::Counter | ||
include DelegateSynchronousInstrument | ||
|
||
def add(increment, attributes: nil) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
super | ||
else | ||
@delegate.add(increment, attributes: attributes) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
metrics_api/lib/opentelemetry/internal/proxy_instrument/delegate_asynchronous_instrument.rb
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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
module DelegateAsynchronousInstrument | ||
def initialize(*args, **kwargs) | ||
super | ||
|
||
@delegate_mutex = Mutex.new | ||
@delegate = nil | ||
end | ||
|
||
def delegate=(instrument) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
@delegate = instrument | ||
else | ||
OpenTelemetry.logger.warn( | ||
'Attempt to reset delegate in Asynchronous ProxyInstrument ignored' | ||
) | ||
end | ||
end | ||
end | ||
|
||
def register_callbacks(*callbacks) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
super | ||
else | ||
@delegate.register_callbacks(*callbacks) | ||
end | ||
end | ||
end | ||
|
||
def unregister_callbacks(*callbacks) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
super | ||
else | ||
@delegate.unregister_callbacks(*callbacks) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
metrics_api/lib/opentelemetry/internal/proxy_instrument/delegate_synchronous_instrument.rb
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
module DelegateSynchronousInstrument | ||
def initialize(*args, **kwargs) | ||
super | ||
|
||
@delegate_mutex = Mutex.new | ||
@delegate = nil | ||
end | ||
|
||
def delegate=(instrument) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
@delegate = instrument | ||
else | ||
OpenTelemetry.logger.warn(' | ||
Attempt to reset delegate in Synchronous ProxyInstrument ignored' | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
metrics_api/lib/opentelemetry/internal/proxy_instrument/histogram.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
class Histogram < Metrics::Instrument::Histogram | ||
include DelegateSynchronousInstrument | ||
|
||
def record(amount, attributes: nil) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
super | ||
else | ||
@delegate.record(amount, attributes: attributes) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
metrics_api/lib/opentelemetry/internal/proxy_instrument/observable_counter.rb
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
class ObservableCounter < Metrics::Instrument::ObservableCounter | ||
include DelegateAsynchronousInstrument | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
metrics_api/lib/opentelemetry/internal/proxy_instrument/observable_gauge.rb
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
class ObservableGauge < Metrics::Instrument::ObservableGauge | ||
include DelegateAsynchronousInstrument | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
metrics_api/lib/opentelemetry/internal/proxy_instrument/observable_up_down_counter.rb
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
class ObservableUpDownCounter < Metrics::Instrument::ObservableUpDownCounter | ||
include DelegateAsynchronousInstrument | ||
end | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
metrics_api/lib/opentelemetry/internal/proxy_instrument/up_down_counter.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Internal | ||
module ProxyInstrument | ||
# @api private | ||
class UpDownCounter < Metrics::Instrument::UpDownCounter | ||
include DelegateSynchronousInstrument | ||
|
||
def add(amount, attributes: nil) | ||
@delegate_mutex.synchronize do | ||
if @delegate.nil? | ||
super | ||
else | ||
@delegate.add(amount, attributes: attributes) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to make Proxy Instruments inherit from API Instrument classes, I've created a Proxy Instrument class for each Instrument. They include the
delegate=
setter from a module.