Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Adjust existing Metrics SDK code to match changes to API #1

Closed
Show file tree
Hide file tree
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 Jun 30, 2023
0876408
Call initialize from API in SDK MeterProvider and set Resource to def…
elias19r Jun 30, 2023
1dd9e6f
Move private_constant :Key from SDK to API in MeterProvider
elias19r Jun 30, 2023
20ead90
Update InstrumentationScope to include schema_url and attributes
elias19r Jun 30, 2023
ca7d03b
Add @instrumentation_scope to Meter in API
elias19r Jun 30, 2023
1555a62
Update Key, the Meter identifier, to include schema_url
elias19r Jun 30, 2023
f5d3f03
Update MeterProvider#meter in SDK
elias19r Jun 30, 2023
159341d
Update ProxyMeterProvider to match API
elias19r Jun 30, 2023
c33b137
Update ProxyMeter to match API
elias19r Jun 30, 2023
f25ce0b
Make Proxy Instruments inherit from API Instruments
elias19r Jun 30, 2023
f21c303
Require ProxyInstrument files
elias19r Jun 30, 2023
30854b3
Adjust SDK Meter to use register_instrument
elias19r Jul 1, 2023
508e19f
Add method #build_key_for_meter
elias19r Jul 1, 2023
5db4749
Remove SDK's SynchronousInstrument class
elias19r Jul 1, 2023
d8d929b
Add #kind method to instruments
elias19r Jul 1, 2023
f7041b4
Not passing meter_provider down to meter and instruments
elias19r Jul 1, 2023
d442a9d
Move default_aggregation to MeterProvider
elias19r Jul 1, 2023
94bcd68
Make SDK metric Instruments inherit from API Instruments
elias19r Jul 1, 2023
7590c1d
Remove initialize methods from SDK async instruments
elias19r Jul 1, 2023
838c516
Remove require for SDK synchronous_instrument
elias19r Jul 1, 2023
a216f51
Add comment with agregation link to docs
elias19r Jul 7, 2023
06b3c01
Keep InstrumentationScope in SDK
elias19r Jul 7, 2023
a2ebb48
Add mutex for @delegate
elias19r Jul 7, 2023
f438baf
Trying to understando MetricData
elias19r Jul 7, 2023
8c21fed
Merge branch 'elias/meter-and-instrument-creation-api' into elias/adj…
elias19r Aug 11, 2023
722035b
Add more details to SDK Meter test
elias19r Aug 11, 2023
acf5815
Add more details to MeterProvider test
elias19r Aug 11, 2023
34fa220
Make Meter hold a reference to MeterProvider
elias19r Aug 11, 2023
cef1294
Build and create metric stream in Meter whenever a sync instrument is…
elias19r Aug 11, 2023
a76cb3e
Add empty LastValue aggregation class
elias19r Aug 13, 2023
e0b50ef
Define default aggregation for instruments
elias19r Aug 13, 2023
19addcc
Make add_metric_stream methods similiar
elias19r Aug 13, 2023
63b6015
Make Aggregation::Sum test examples more verbose
elias19r Aug 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions metrics_api/lib/opentelemetry/internal/proxy_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,18 @@
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
module Internal
# @api private
class ProxyInstrument
def initialize(kind, name, unit, desc, callable)
@kind = kind
@name = name
@unit = unit
@desc = desc
@callable = callable
@delegate = nil
end

def upgrade_with(meter)
@delegate = case @kind
when :counter, :histogram, :up_down_counter
meter.send("create_#{@kind}", @name, unit: @unit, description: @desc)
when :observable_counter, :observable_gauge, :observable_up_down_counter
meter.send("create_#{@kind}", @name, unit: @unit, description: @desc, callback: @callback)
end
end

def add(amount, attributes: nil)
@delegate&.add(amount, attributes: attributes)
end

def record(amount, attributes: nil)
@delegate&.record(amount, attributes: attributes)
end
module Metrics
module ProxyInstrument
end
end
end

require 'opentelemetry/internal/proxy_instrument/delegate_synchronous_instrument'
require 'opentelemetry/internal/proxy_instrument/counter'
require 'opentelemetry/internal/proxy_instrument/histogram'
require 'opentelemetry/internal/proxy_instrument/up_down_counter'

require 'opentelemetry/internal/proxy_instrument/delegate_asynchronous_instrument'
require 'opentelemetry/internal/proxy_instrument/observable_counter'
require 'opentelemetry/internal/proxy_instrument/observable_gauge'
require 'opentelemetry/internal/proxy_instrument/observable_up_down_counter'
Comment on lines +8 to +22
Copy link
Author

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.

26 changes: 26 additions & 0 deletions metrics_api/lib/opentelemetry/internal/proxy_instrument/counter.rb
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
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
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
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
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
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
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
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
Loading