Skip to content

Commit 124f9cc

Browse files
committed
add gauge
1 parent 3f5453b commit 124f9cc

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"resourceMetrics": [
3+
{
4+
"resource": {
5+
"attributes": [
6+
{
7+
"key": "service.name",
8+
"value": {
9+
"stringValue": "metrics-integration-test"
10+
}
11+
}
12+
]
13+
},
14+
"scopeMetrics": [
15+
{
16+
"scope": {
17+
"name": "test_gauge_meter"
18+
},
19+
"metrics": [
20+
{
21+
"name": "example_gauge",
22+
"sum": {
23+
"dataPoints": [
24+
{
25+
"attributes": [
26+
{
27+
"key": "mykey5",
28+
"value": {
29+
"stringValue": "myvalue5"
30+
}
31+
}
32+
],
33+
"startTimeUnixNano": "1734259947902844000",
34+
"timeUnixNano": "1734259952816822000",
35+
"asDouble": "-1.10"
36+
}
37+
],
38+
"aggregationTemporality": 2
39+
}
40+
}
41+
]
42+
}
43+
]
44+
}
45+
]
46+
}

opentelemetry-otlp/tests/integration_test/tests/metrics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//! OTLP integration tests for metrics. These tests cover various OTel Metric
2+
//! SDK/OTLP Exporter scenarios in particular focusing on ensuring that various
3+
//! async runtimes works well. This also includes validating that shutdown,
4+
//! force_flush are working as expected. Validation is simple in the sense it
5+
//! merely checks the presence of a UUID in the exported metrics, which is good
6+
//! enough to confirm that metrics have been accepted by OTel Collector.
7+
//!
18
#![cfg(unix)]
29

310
use anyhow::{Ok, Result};

opentelemetry-otlp/tests/integration_test/tests/metrics_roundtrip.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
//! OTLP integration tests for metrics
1+
//! OTLP integration tests for metrics. These tests cover the breadth of Metric
2+
//! API by testing all instrument types and ensuring that the data is correctly
3+
//! exported to the collector by validating the exported data against the
4+
//! expected results.
25
//! Note: these are all expressed using Serde types for the deserialized metrics records.
36
//! We might consider changing this once we have fixed the issue identified in the #[ignore]d test
47
//! `test_roundtrip_example_data` - as the roundtripping is currently broken for metrics.
@@ -106,6 +109,24 @@ mod metrictests_roundtrip {
106109

107110
Ok(())
108111
}
112+
113+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
114+
async fn test_gauge() -> Result<()> {
115+
let meter_provider = metric_helpers::setup_metrics_tokio().await;
116+
const METER_NAME: &str = "test_gauge_meter";
117+
118+
// Add data to up_down_counter
119+
let meter = opentelemetry::global::meter_provider().meter(METER_NAME);
120+
let gauge = meter.f64_gauge("example_gauge").build();
121+
gauge.record(-1.10, &[KeyValue::new("mykey5", "myvalue5")]);
122+
123+
meter_provider.shutdown()?;
124+
tokio::time::sleep(SLEEP_DURATION).await;
125+
126+
validate_metrics_against_results(METER_NAME)?;
127+
128+
Ok(())
129+
}
109130
}
110131

111132
///

0 commit comments

Comments
 (0)