Skip to content

Commit f4a2080

Browse files
authored
Merge branch 'main' into 2726-clonebreaking
2 parents 09989bb + 8b3fc06 commit f4a2080

19 files changed

+82
-48
lines changed

.github/workflows/benchmark.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ on:
1313
branches:
1414
- main
1515
name: benchmark pull requests
16-
permissions: read-all
16+
permissions:
17+
contents: read
1718

1819
jobs:
1920
runBenchmark:

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: CI
22
env:
33
CI: true
4-
permissions: read-all
4+
permissions:
5+
contents: read
56
on:
67
pull_request:
78
push:

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: "CodeQL Analysis"
33
env:
44
CODEQL_ENABLE_EXPERIMENTAL_FEATURES : true # CodeQL support for Rust is experimental
55

6-
permissions: read-all
6+
permissions:
7+
contents: read
78

89
on:
10+
pull_request:
911
push:
1012
branches: [main]
11-
schedule:
12-
- cron: '0 0 * * *' # once in a day at 00:00
1313
workflow_dispatch:
1414

1515
jobs:

.github/workflows/fossa.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
branches:
66
- main
77

8-
permissions: read-all
8+
permissions:
9+
contents: read
910

1011
jobs:
1112
fossa:

.github/workflows/integration_tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
pull_request:
66
types: [ labeled, synchronize, opened, reopened ]
77

8-
permissions: read-all
8+
permissions:
9+
contents: read
910

1011
jobs:
1112
integration_tests:

.github/workflows/markdown-link-check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88
paths:
99
- '**/*.md'
1010

11-
permissions: read-all
11+
permissions:
12+
contents: read
1213

1314
jobs:
1415
markdown-link-check:

.github/workflows/ossf-scorecard.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88
- cron: "50 3 * * 0" # once a week
99
workflow_dispatch:
1010

11-
permissions: read-all
11+
permissions:
12+
contents: read
1213

1314
jobs:
1415
analysis:

.github/workflows/pr_naming.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
pull_request:
55
types: [opened, synchronize, reopened, edited]
66

7-
permissions: read-all
7+
permissions:
8+
contents: read
89

910
jobs:
1011
validate-pr-title:

.github/workflows/semver.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Semver compliance
22
env:
33
CI: true
4-
permissions: read-all
4+
permissions:
5+
contents: read
56
on:
67
pull_request:
78
types: [ labeled, synchronize, opened, reopened ]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
The Rust [OpenTelemetry](https://opentelemetry.io/) implementation.
44

55
[![Crates.io: opentelemetry](https://img.shields.io/crates/v/opentelemetry.svg)](https://crates.io/crates/opentelemetry)
6-
[![Documentation](https://docs.rs/opentelemetry/badge.svg)](https://docs.rs/opentelemetry)
76
[![LICENSE](https://img.shields.io/crates/l/opentelemetry)](./LICENSE)
87
[![GitHub Actions CI](https://github.com/open-telemetry/opentelemetry-rust/workflows/CI/badge.svg)](https://github.com/open-telemetry/opentelemetry-rust/actions?query=workflow%3ACI+branch%3Amain)
8+
[![Documentation](https://docs.rs/opentelemetry/badge.svg)](https://docs.rs/opentelemetry)
99
[![codecov](https://codecov.io/gh/open-telemetry/opentelemetry-rust/branch/main/graph/badge.svg)](https://codecov.io/gh/open-telemetry/opentelemetry-rust)
10+
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/open-telemetry/opentelemetry-rust/badge)](https://scorecard.dev/viewer/?uri=github.com/open-telemetry/opentelemetry-rust)
1011
[![Slack](https://img.shields.io/badge/slack-@cncf/otel/rust-brightgreen.svg?logo=slack)](https://cloud-native.slack.com/archives/C03GDP0H023)
1112

1213
## Overview

opentelemetry-otlp/src/exporter/http/metrics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ impl MetricsClient for OtlpHttpClient {
1919
_ => Err(OTelSdkError::AlreadyShutdown),
2020
})?;
2121

22-
let (body, content_type) = self.build_metrics_export_body(metrics).map_err(|e| {
23-
OTelSdkError::InternalFailure(format!("Failed to serialize metrics: {e:?}"))
22+
let (body, content_type) = self.build_metrics_export_body(metrics).ok_or_else(|| {
23+
OTelSdkError::InternalFailure("Failed to serialize metrics".to_string())
2424
})?;
2525
let mut request = http::Request::builder()
2626
.method(Method::POST)

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use super::{
44
};
55
use crate::{ExportConfig, Protocol, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS};
66
use http::{HeaderName, HeaderValue, Uri};
7+
#[cfg(feature = "http-json")]
8+
use opentelemetry::otel_debug;
79
use opentelemetry_http::HttpClient;
810
use opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema;
911
#[cfg(feature = "logs")]
@@ -325,20 +327,21 @@ impl OtlpHttpClient {
325327
fn build_metrics_export_body(
326328
&self,
327329
metrics: &mut ResourceMetrics,
328-
) -> opentelemetry_sdk::metrics::MetricResult<(Vec<u8>, &'static str)> {
330+
) -> Option<(Vec<u8>, &'static str)> {
329331
use opentelemetry_proto::tonic::collector::metrics::v1::ExportMetricsServiceRequest;
330332

331333
let req: ExportMetricsServiceRequest = (&*metrics).into();
332334

333335
match self.protocol {
334336
#[cfg(feature = "http-json")]
335337
Protocol::HttpJson => match serde_json::to_string_pretty(&req) {
336-
Ok(json) => Ok((json.into(), "application/json")),
337-
Err(e) => Err(opentelemetry_sdk::metrics::MetricError::Other(
338-
e.to_string(),
339-
)),
338+
Ok(json) => Some((json.into(), "application/json")),
339+
Err(e) => {
340+
otel_debug!(name: "JsonSerializationFaied", error = e.to_string());
341+
None
342+
}
340343
},
341-
_ => Ok((req.encode_to_vec(), "application/x-protobuf")),
344+
_ => Some((req.encode_to_vec(), "application/x-protobuf")),
342345
}
343346
}
344347
}

opentelemetry-sdk/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ also modified to suppress telemetry before invoking exporters.
1818
- This feature was previously removed in version 0.28 due to the lack of
1919
configurability but has now been reintroduced with the ability to configure
2020
the limit.
21-
- There is ability to configure cardinality limits via Instrument
21+
- There is ability to configure cardinality limits via Instrument
2222
advisory. [#2903](https://github.com/open-telemetry/opentelemetry-rust/pull/2903)
23+
- Fixed the overflow attribute to correctly use the boolean value `true`
24+
instead of the string `"true"`.
25+
[#2878](https://github.com/open-telemetry/opentelemetry-rust/issues/2878)
2326

2427
- *Breaking* change for custom `MetricReader` authors.
2528
The `shutdown_with_timeout` method is added to `MetricReader` trait.
2629
`collect` method on `MetricReader` modified to return `OTelSdkResult`.
30+
[#2905](https://github.com/open-telemetry/opentelemetry-rust/pull/2905)
31+
- *Breaking* `MetricError`, `MetricResult` no longer public (except when
32+
`spec_unstable_metrics_views` feature flag is enabled). `OTelSdkResult` should
33+
be used instead, wherever applicable.
34+
[#2905](https://github.com/open-telemetry/opentelemetry-rust/pull/2905)
2735

2836
## 0.29.0
2937

opentelemetry-sdk/src/metrics/aggregation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

3+
use crate::metrics::error::{MetricError, MetricResult};
34
use crate::metrics::internal::{EXPO_MAX_SCALE, EXPO_MIN_SCALE};
4-
use crate::metrics::{MetricError, MetricResult};
55

66
/// The way recorded measurements are summarized.
77
#[derive(Clone, Debug, PartialEq)]
@@ -109,7 +109,8 @@ impl fmt::Display for Aggregation {
109109

110110
impl Aggregation {
111111
/// Validate that this aggregation has correct configuration
112-
pub fn validate(&self) -> MetricResult<()> {
112+
#[allow(unused)]
113+
pub(crate) fn validate(&self) -> MetricResult<()> {
113114
match self {
114115
Aggregation::Drop => Ok(()),
115116
Aggregation::Default => Ok(()),
@@ -149,11 +150,11 @@ impl Aggregation {
149150

150151
#[cfg(test)]
151152
mod tests {
153+
use crate::metrics::error::{MetricError, MetricResult};
152154
use crate::metrics::{
153155
internal::{EXPO_MAX_SCALE, EXPO_MIN_SCALE},
154156
Aggregation,
155157
};
156-
use crate::metrics::{MetricError, MetricResult};
157158

158159
#[test]
159160
fn validate_aggregation() {

opentelemetry-sdk/src/metrics/error.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use std::result;
22
use std::sync::PoisonError;
33
use thiserror::Error;
44

5-
use crate::ExportError;
6-
75
/// A specialized `Result` type for metric operations.
6+
#[cfg(feature = "spec_unstable_metrics_views")]
87
pub type MetricResult<T> = result::Result<T, MetricError>;
8+
#[cfg(not(feature = "spec_unstable_metrics_views"))]
9+
pub(crate) type MetricResult<T> = result::Result<T, MetricError>;
910

1011
/// Errors returned by the metrics API.
12+
#[cfg(feature = "spec_unstable_metrics_views")]
1113
#[derive(Error, Debug)]
1214
#[non_exhaustive]
1315
pub enum MetricError {
@@ -17,20 +19,27 @@ pub enum MetricError {
1719
/// Invalid configuration
1820
#[error("Config error {0}")]
1921
Config(String),
20-
/// Fail to export metrics
21-
#[error("Metrics exporter {0} failed with {name}", name = .0.exporter_name())]
22-
ExportErr(Box<dyn ExportError>),
2322
/// Invalid instrument configuration such invalid instrument name, invalid instrument description, invalid instrument unit, etc.
2423
/// See [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#general-characteristics)
2524
/// for full list of requirements.
2625
#[error("Invalid instrument configuration: {0}")]
2726
InvalidInstrumentConfiguration(&'static str),
2827
}
2928

30-
impl<T: ExportError> From<T> for MetricError {
31-
fn from(err: T) -> Self {
32-
MetricError::ExportErr(Box::new(err))
33-
}
29+
#[cfg(not(feature = "spec_unstable_metrics_views"))]
30+
#[derive(Error, Debug)]
31+
pub(crate) enum MetricError {
32+
/// Other errors not covered by specific cases.
33+
#[error("Metrics error: {0}")]
34+
Other(String),
35+
/// Invalid configuration
36+
#[error("Config error {0}")]
37+
Config(String),
38+
/// Invalid instrument configuration such invalid instrument name, invalid instrument description, invalid instrument unit, etc.
39+
/// See [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#general-characteristics)
40+
/// for full list of requirements.
41+
#[error("Invalid instrument configuration: {0}")]
42+
InvalidInstrumentConfiguration(&'static str),
3443
}
3544

3645
impl<T> From<PoisonError<T>> for MetricError {

opentelemetry-sdk/src/metrics/internal/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) static STREAM_OVERFLOW_ATTRIBUTES: OnceLock<Vec<KeyValue>> = OnceLock
2323

2424
#[inline]
2525
fn stream_overflow_attributes() -> &'static Vec<KeyValue> {
26-
STREAM_OVERFLOW_ATTRIBUTES.get_or_init(|| vec![KeyValue::new("otel.metric.overflow", "true")])
26+
STREAM_OVERFLOW_ATTRIBUTES.get_or_init(|| vec![KeyValue::new("otel.metric.overflow", true)])
2727
}
2828

2929
pub(crate) trait Aggregator {

opentelemetry-sdk/src/metrics/meter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use opentelemetry::{
1212
};
1313

1414
use crate::metrics::{
15+
error::{MetricError, MetricResult},
1516
instrument::{Instrument, InstrumentKind, Observable, ResolvedMeasures},
1617
internal::{self, Number},
1718
pipeline::{Pipelines, Resolver},
18-
MetricError, MetricResult,
1919
};
2020

2121
use super::noop::NoopSyncInstrument;

opentelemetry-sdk/src/metrics/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub mod in_memory_exporter;
6666
pub use in_memory_exporter::{InMemoryMetricExporter, InMemoryMetricExporterBuilder};
6767

6868
pub use aggregation::*;
69+
#[cfg(feature = "spec_unstable_metrics_views")]
6970
pub use error::{MetricError, MetricResult};
7071
pub use manual_reader::*;
7172
pub use meter_provider::*;
@@ -122,6 +123,7 @@ mod tests {
122123
use data::GaugeDataPoint;
123124
use opentelemetry::metrics::{Counter, Meter, UpDownCounter};
124125
use opentelemetry::InstrumentationScope;
126+
use opentelemetry::Value;
125127
use opentelemetry::{metrics::MeterProvider as _, KeyValue};
126128
use rand::{rngs, Rng, SeedableRng};
127129
use std::cmp::{max, min};
@@ -2399,8 +2401,7 @@ mod tests {
23992401
assert_eq!(sum.data_points.len(), 2002);
24002402

24012403
let data_point =
2402-
find_sum_datapoint_with_key_value(&sum.data_points, "otel.metric.overflow", "true")
2403-
.expect("overflow point expected");
2404+
find_overflow_sum_datapoint(&sum.data_points).expect("overflow point expected");
24042405
assert_eq!(data_point.value, 300);
24052406

24062407
// let empty_attrs_data_point = &sum.data_points[0];
@@ -2448,8 +2449,7 @@ mod tests {
24482449
// For cumulative, overflow should still be there, and new points should not be added.
24492450
assert_eq!(sum.data_points.len(), 2002);
24502451
let data_point =
2451-
find_sum_datapoint_with_key_value(&sum.data_points, "otel.metric.overflow", "true")
2452-
.expect("overflow point expected");
2452+
find_overflow_sum_datapoint(&sum.data_points).expect("overflow point expected");
24532453
assert_eq!(data_point.value, 600);
24542454

24552455
let data_point = find_sum_datapoint_with_key_value(&sum.data_points, "A", "foo");
@@ -2505,8 +2505,7 @@ mod tests {
25052505
assert_eq!(sum.data_points.len(), cardinality_limit + 1 + 1);
25062506

25072507
let data_point =
2508-
find_sum_datapoint_with_key_value(&sum.data_points, "otel.metric.overflow", "true")
2509-
.expect("overflow point expected");
2508+
find_overflow_sum_datapoint(&sum.data_points).expect("overflow point expected");
25102509
assert_eq!(data_point.value, 300);
25112510

25122511
// let empty_attrs_data_point = &sum.data_points[0];
@@ -2554,8 +2553,7 @@ mod tests {
25542553
// For cumulative, overflow should still be there, and new points should not be added.
25552554
assert_eq!(sum.data_points.len(), cardinality_limit + 1 + 1);
25562555
let data_point =
2557-
find_sum_datapoint_with_key_value(&sum.data_points, "otel.metric.overflow", "true")
2558-
.expect("overflow point expected");
2556+
find_overflow_sum_datapoint(&sum.data_points).expect("overflow point expected");
25592557
assert_eq!(data_point.value, 600);
25602558

25612559
let data_point = find_sum_datapoint_with_key_value(&sum.data_points, "A", "foo");
@@ -2604,8 +2602,7 @@ mod tests {
26042602
assert_eq!(sum.data_points.len(), cardinality_limit + 1 + 1);
26052603

26062604
let data_point =
2607-
find_sum_datapoint_with_key_value(&sum.data_points, "otel.metric.overflow", "true")
2608-
.expect("overflow point expected");
2605+
find_overflow_sum_datapoint(&sum.data_points).expect("overflow point expected");
26092606
assert_eq!(data_point.value, 300);
26102607

26112608
// let empty_attrs_data_point = &sum.data_points[0];
@@ -2653,8 +2650,7 @@ mod tests {
26532650
// For cumulative, overflow should still be there, and new points should not be added.
26542651
assert_eq!(sum.data_points.len(), cardinality_limit + 1 + 1);
26552652
let data_point =
2656-
find_sum_datapoint_with_key_value(&sum.data_points, "otel.metric.overflow", "true")
2657-
.expect("overflow point expected");
2653+
find_overflow_sum_datapoint(&sum.data_points).expect("overflow point expected");
26582654
assert_eq!(data_point.value, 600);
26592655

26602656
let data_point = find_sum_datapoint_with_key_value(&sum.data_points, "A", "foo");
@@ -2837,6 +2833,14 @@ mod tests {
28372833
})
28382834
}
28392835

2836+
fn find_overflow_sum_datapoint<T>(data_points: &[SumDataPoint<T>]) -> Option<&SumDataPoint<T>> {
2837+
data_points.iter().find(|&datapoint| {
2838+
datapoint.attributes.iter().any(|kv| {
2839+
kv.key.as_str() == "otel.metric.overflow" && kv.value == Value::Bool(true)
2840+
})
2841+
})
2842+
}
2843+
28402844
fn find_gauge_datapoint_with_key_value<'a, T>(
28412845
data_points: &'a [GaugeDataPoint<T>],
28422846
key: &str,

opentelemetry-sdk/src/metrics/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use crate::{
1212
metrics::{
1313
aggregation,
1414
data::{Metric, ResourceMetrics, ScopeMetrics},
15+
error::{MetricError, MetricResult},
1516
instrument::{Instrument, InstrumentId, InstrumentKind, Stream},
1617
internal::{self, AggregateBuilder, Number},
1718
reader::{MetricReader, SdkProducer},
1819
view::View,
19-
MetricError, MetricResult,
2020
},
2121
Resource,
2222
};

0 commit comments

Comments
 (0)