Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Gauge metrics exporter encoding #1780

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,17 @@ def encode(metrics_data)
end

# metrics_pb has following type of data: :gauge, :sum, :histogram, :exponential_histogram, :summary
# current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram
# current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram, :gauge -> :gauge
#
# metrics [MetricData]
def as_otlp_metrics(metrics)
case metrics.instrument_kind
when :observable_gauge
when :observable_gauge, :gauge
Opentelemetry::Proto::Metrics::V1::Metric.new(
name: metrics.name,
description: metrics.description,
unit: metrics.unit,
gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new(
aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality),
data_points: metrics.data_points.map do |ndp|
number_data_point(ndp)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,16 @@
stub_request(:post, 'http://localhost:4318/v1/metrics').to_return(status: 200)
meter_provider.add_metric_reader(exporter)
meter = meter_provider.meter('test')

counter = meter.create_counter('test_counter', unit: 'smidgen', description: 'a small amount of something')
counter.add(5, attributes: { 'foo' => 'bar' })

histogram = meter.create_histogram('test_histogram', unit: 'smidgen', description: 'a small amount of something')
histogram.record(10, attributes: { 'oof' => 'rab' })

gauge = meter.create_gauge('test_gauge', unit: 'smidgen', description: 'a small amount of something')
gauge.record(15, attributes: { 'baz' => 'qux' })

exporter.pull
meter_provider.shutdown

Expand Down Expand Up @@ -644,6 +649,24 @@
],
aggregation_temporality: Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA
)
),
Opentelemetry::Proto::Metrics::V1::Metric.new(
name: 'test_gauge',
description: 'a small amount of something',
unit: 'smidgen',
gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new(
data_points: [
Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(
attributes: [
Opentelemetry::Proto::Common::V1::KeyValue.new(key: 'baz', value: Opentelemetry::Proto::Common::V1::AnyValue.new(string_value: 'qux'))
],
as_int: 15,
start_time_unix_nano: 1_699_593_427_329_946_585,
time_unix_nano: 1_699_593_427_329_946_586,
exemplars: nil
)
]
)
)
]
)
Expand Down
1 change: 1 addition & 0 deletions exporter/otlp-metrics/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def collect(start_time, end_time, data_points)

OpenTelemetry::SDK::Metrics::Aggregation::Sum.prepend(MockSum)
OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.prepend(MockSum)
OpenTelemetry::SDK::Metrics::Aggregation::LastValue.prepend(MockSum)

def create_metrics_data(name: '', description: '', unit: '', instrument_kind: :counter, resource: nil,
instrumentation_scope: OpenTelemetry::SDK::InstrumentationScope.new('', 'v0.0.1'),
Expand Down
Loading