Skip to content

Commit

Permalink
Merge branch 'main' into link-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle authored Jan 8, 2025
2 parents 1fb2f27 + 6099f79 commit 052fcfb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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

0 comments on commit 052fcfb

Please sign in to comment.