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

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,11 +214,23 @@ 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 :gauge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that possible to combine :observable_gauge and :gauge something like when :observable_gauge, :gauge since they are using same Proto::Metrics::V1::Gauge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I split them out because Proto::Metrics::V1::Gauge doesn't actually implement aggregation_temporality. Seems like that was just a mistake in the :observable_gauge implementation 😋 c32f2c0

Copy link
Contributor

@xuan-cao-swi xuan-cao-swi Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, make sense, thanks!

Opentelemetry::Proto::Metrics::V1::Metric.new(
name: metrics.name,
description: metrics.description,
unit: metrics.unit,
gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new(
data_points: metrics.data_points.map do |ndp|
number_data_point(ndp)
end
)
)

when :observable_gauge
Opentelemetry::Proto::Metrics::V1::Metric.new(
name: metrics.name,
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,7 +649,25 @@
],
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