Skip to content

Commit 048f574

Browse files
committed
feat: Allow specifying aggregation for SynchronousInstruments
1 parent 86e443a commit 048f574

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/synchronous_instrument.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,28 @@ module Instrument
1111
# {SynchronousInstrument} contains the common functionality shared across
1212
# the synchronous instruments SDK instruments.
1313
class SynchronousInstrument
14-
def initialize(name, unit, description, instrumentation_scope, meter_provider)
14+
def initialize(name, unit, description, instrumentation_scope, meter_provider, aggregation: default_aggregation)
1515
@name = name
1616
@unit = unit
1717
@description = description
1818
@instrumentation_scope = instrumentation_scope
1919
@meter_provider = meter_provider
20+
@aggregation = aggregation
2021
@metric_streams = []
2122

2223
meter_provider.register_synchronous_instrument(self)
2324
end
2425

2526
# @api private
26-
def register_with_new_metric_store(metric_store, aggregation: default_aggregation)
27+
def register_with_new_metric_store(metric_store, aggregation: nil)
2728
ms = OpenTelemetry::SDK::Metrics::State::MetricStream.new(
2829
@name,
2930
@description,
3031
@unit,
3132
instrument_kind,
3233
@meter_provider,
3334
@instrumentation_scope,
34-
aggregation
35+
aggregation || @aggregation
3536
)
3637
@metric_streams << ms
3738
metric_store.add_metric_stream(ms)

metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def add_metric_reader(metric_reader)
3535
end
3636
end
3737

38-
def create_instrument(kind, name, unit, description, callback)
38+
def create_instrument(kind, name, unit, description, callback, **options)
3939
raise InstrumentNameError if name.nil?
4040
raise InstrumentNameError if name.empty?
4141
raise InstrumentNameError unless NAME_REGEX.match?(name)
@@ -44,12 +44,12 @@ def create_instrument(kind, name, unit, description, callback)
4444

4545
super do
4646
case kind
47-
when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider)
47+
when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider, **options)
4848
when :observable_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider)
49-
when :gauge then OpenTelemetry::SDK::Metrics::Instrument::Gauge.new(name, unit, description, @instrumentation_scope, @meter_provider)
50-
when :histogram then OpenTelemetry::SDK::Metrics::Instrument::Histogram.new(name, unit, description, @instrumentation_scope, @meter_provider)
49+
when :gauge then OpenTelemetry::SDK::Metrics::Instrument::Gauge.new(name, unit, description, @instrumentation_scope, @meter_provider, **options)
50+
when :histogram then OpenTelemetry::SDK::Metrics::Instrument::Histogram.new(name, unit, description, @instrumentation_scope, @meter_provider, **options)
5151
when :observable_gauge then OpenTelemetry::SDK::Metrics::Instrument::ObservableGauge.new(name, unit, description, callback, @instrumentation_scope, @meter_provider)
52-
when :up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::UpDownCounter.new(name, unit, description, @instrumentation_scope, @meter_provider)
52+
when :up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::UpDownCounter.new(name, unit, description, @instrumentation_scope, @meter_provider, **options)
5353
when :observable_up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableUpDownCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider)
5454
end
5555
end

0 commit comments

Comments
 (0)