Skip to content

Commit d539bb8

Browse files
authored
Merge branch 'main' into semconv_1.31_0
2 parents 7217551 + 34835a8 commit d539bb8

File tree

15 files changed

+454
-143
lines changed

15 files changed

+454
-143
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ documentation.
3131
| Signal/Component | Overall Status |
3232
| -------------------- | ------------------ |
3333
| Context | Beta |
34-
| Baggage | Beta |
34+
| Baggage | RC |
3535
| Propagators | Beta |
3636
| Logs-API | Stable* |
37-
| Logs-SDK | RC |
37+
| Logs-SDK | Stable |
3838
| Logs-OTLP Exporter | RC |
39-
| Logs-Appender-Tracing | RC |
39+
| Logs-Appender-Tracing | Stable |
4040
| Metrics-API | Stable |
4141
| Metrics-SDK | RC |
4242
| Metrics-OTLP Exporter | RC |

docs/migration_0.29.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Migration Guide from 0.28 to 0.29
2+
3+
OpenTelemetry Rust 0.29 introduces a few breaking changes. This guide aims to
4+
facilitate a smooth migration for common use cases involving the
5+
`opentelemetry`, `opentelemetry_sdk`, `opentelemetry-otlp`, and
6+
`opentelemetry-appender-tracing` crates. For a comprehensive list of changes,
7+
please refer to the detailed changelog for each crate. This document covers only
8+
the most common scenarios. Note that changes that only affect custom
9+
exporter/processor authors are not mentioned in this doc.
10+
11+
OpenTelemetry Metrics API and Log-Bridge API were declared stable in 0.28, and have
12+
no breaking changes.
13+
14+
## Baggage Changes
15+
16+
The Baggage API has been redesigned to align with the OpenTelemetry
17+
specification. While the core API for interacting with Baggage remains the same,
18+
the accepted data types have changed. Baggage Keys now only allow strings (ASCII
19+
printable characters), and Baggage values are restricted to strings.
20+
21+
For detailed changes, see the [changelog](../opentelemetry/CHANGELOG.md). With
22+
version 0.29, the Baggage API has reached "Release Candidate" status, meaning
23+
further breaking changes will be highly restricted.
24+
25+
## Appender-Tracing Changes
26+
27+
The `opentelemetry-appender-tracing` crate, which bridges `tracing` events to
28+
OpenTelemetry logs, has been updated to properly map `tracing` data types to the
29+
OpenTelemetry model. As of version 0.29, this crate is considered "Stable," and
30+
no further breaking changes will be made without a major version bump.
31+
32+
## Configuration via Environment Variables
33+
34+
The 0.29 release aligns OpenTelemetry Rust with the rest of the OpenTelemetry
35+
ecosystem by treating any code-based configuration as final (i.e., it cannot be
36+
overridden by environment variables). This policy was partially true before but
37+
is now applied consistently. If you prefer to configure your application via
38+
environment variables, avoid configuring it programmatically.
39+
40+
## Discontinuing Dedicated Prometheus Exporter
41+
42+
The `opentelemetry-prometheus` crate will be discontinued with the 0.29 release.
43+
Active development on this crate ceased a few months ago. Given that Prometheus
44+
now natively supports OTLP, and considering that the OpenTelemetry Rust project
45+
is still working towards a 1.0 release, we need to focus on essential components
46+
to maintain scope and ensure timely delivery.
47+
48+
Prometheus interoperability remains a key goal for OpenTelemetry. However, the
49+
current `opentelemetry-prometheus` crate requires a major rewrite to eliminate
50+
dependencies on unmaintained crates. We may reintroduce a dedicated Prometheus
51+
exporter in the future once these issues are resolved.
52+
53+
### Migration Guide
54+
55+
For those using Prometheus as a backend, you can integrate with Prometheus using
56+
the following methods:
57+
58+
1. Use the OTLP Exporter to push metrics directly to Prometheus.
59+
2. If you require a pull (scrape) model, push metrics to an OpenTelemetry
60+
Collector using the OTLP Exporter, and configure Prometheus to scrape the
61+
OpenTelemetry Collector.
62+
63+
These alternatives ensure continued Prometheus integration while allowing us to
64+
focus on achieving a stable 1.0 release for OpenTelemetry Rust.
65+
66+
## Next Release
67+
68+
In the [next
69+
release](https://github.com/open-telemetry/opentelemetry-rust/milestone/21), we
70+
expect to stabilize the Metrics SDK and resolve the long-standing question of
71+
`tokio-tracing` vs. `opentelemetry tracing`, which is a prerequisite before
72+
stabilizing Distributed Tracing. Additionally, `Context` is also expected to be
73+
enhanced with the ability to suppress telemetry-induced-telemetry.
74+
75+
## Instrumentation Libraries
76+
77+
Unlike other OpenTelemetry language implementations, OpenTelemetry Rust historically did not
78+
maintain any instrumentations directly. This has recently changed with a
79+
[contribution](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/202)
80+
from one of the founding members of the OpenTelemetry Rust project to the
81+
contrib repository, providing an instrumentation library for
82+
[`actix-web`](https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/actix-web-opentelemetry).
83+
We expect that this instrumentation will serve as a reference implementation demonstrating best practices for
84+
creating OpenTelemetry instrumentations in Rust.
85+
86+
We welcome additional contributions of instrumentation libraries to the contrib repository.
87+
88+
## Thanks
89+
90+
Thank you to everyone who contributed to this milestone. Please share your feedback
91+
through GitHub issues or join the discussion in the OTel-Rust Slack channel
92+
[here](https://cloud-native.slack.com/archives/C03GDP0H023).

opentelemetry-otlp/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
`Error` which contained many variants unrelated to building an exporter, the
1818
new one returns specific variants applicable to building an exporter. Some
1919
variants might be applicable only on select features.
20+
Also, now unused `Error` enum is removed.
2021
- **Breaking** `ExportConfig`'s `timeout` field is now optional(`Option<Duration>`)
2122
- **Breaking** Export configuration done via code is final. ENV variables cannot be used to override the code config.
2223
Do not use code based config, if there is desire to control the settings via ENV variables.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl OtlpHttpClient {
287287
fn build_trace_export_body(
288288
&self,
289289
spans: Vec<SpanData>,
290-
) -> opentelemetry_sdk::trace::TraceResult<(Vec<u8>, &'static str)> {
290+
) -> Result<(Vec<u8>, &'static str), String> {
291291
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
292292
let resource_spans = group_spans_by_resource_and_scope(spans, &self.resource);
293293

@@ -296,7 +296,7 @@ impl OtlpHttpClient {
296296
#[cfg(feature = "http-json")]
297297
Protocol::HttpJson => match serde_json::to_string_pretty(&req) {
298298
Ok(json) => Ok((json.into_bytes(), "application/json")),
299-
Err(e) => Err(opentelemetry_sdk::trace::TraceError::from(e.to_string())),
299+
Err(e) => Err(e.to_string()),
300300
},
301301
_ => Ok((req.encode_to_vec(), "application/x-protobuf")),
302302
}

opentelemetry-otlp/src/lib.rs

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,6 @@ pub use crate::exporter::{
362362
OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT,
363363
};
364364

365-
use opentelemetry_sdk::ExportError;
366-
367365
/// Type to indicate the builder does not have a client set.
368366
#[derive(Debug, Default, Clone)]
369367
pub struct NoExporterBuilderSet;
@@ -391,104 +389,6 @@ pub use crate::exporter::tonic::{TonicConfig, TonicExporterBuilder};
391389
#[cfg(feature = "serialize")]
392390
use serde::{Deserialize, Serialize};
393391

394-
/// Wrap type for errors from this crate.
395-
#[derive(thiserror::Error, Debug)]
396-
pub enum Error {
397-
/// Wrap error from [`tonic::transport::Error`]
398-
#[cfg(feature = "grpc-tonic")]
399-
#[error("transport error {0}")]
400-
Transport(#[from] tonic::transport::Error),
401-
402-
/// Wrap the [`tonic::codegen::http::uri::InvalidUri`] error
403-
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
404-
#[error("invalid URI {0}")]
405-
InvalidUri(#[from] http::uri::InvalidUri),
406-
407-
/// Wrap type for [`tonic::Status`]
408-
#[cfg(feature = "grpc-tonic")]
409-
#[error("the grpc server returns error ({code}): {message}")]
410-
Status {
411-
/// grpc status code
412-
code: tonic::Code,
413-
/// error message
414-
message: String,
415-
},
416-
417-
/// Http requests failed because no http client is provided.
418-
#[cfg(any(feature = "http-proto", feature = "http-json"))]
419-
#[error(
420-
"no http client, you must select one from features or provide your own implementation"
421-
)]
422-
NoHttpClient,
423-
424-
/// Http requests failed.
425-
#[cfg(any(feature = "http-proto", feature = "http-json"))]
426-
#[error("http request failed with {0}")]
427-
RequestFailed(#[from] opentelemetry_http::HttpError),
428-
429-
/// The provided value is invalid in HTTP headers.
430-
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
431-
#[error("http header value error {0}")]
432-
InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
433-
434-
/// The provided name is invalid in HTTP headers.
435-
#[cfg(any(feature = "grpc-tonic", feature = "http-proto", feature = "http-json"))]
436-
#[error("http header name error {0}")]
437-
InvalidHeaderName(#[from] http::header::InvalidHeaderName),
438-
439-
/// Prost encode failed
440-
#[cfg(any(
441-
feature = "http-proto",
442-
all(feature = "http-json", not(feature = "trace"))
443-
))]
444-
#[error("prost encoding error {0}")]
445-
EncodeError(#[from] prost::EncodeError),
446-
447-
/// The lock in exporters has been poisoned.
448-
#[cfg(feature = "metrics")]
449-
#[error("the lock of the {0} has been poisoned")]
450-
PoisonedLock(&'static str),
451-
452-
/// Unsupported compression algorithm.
453-
#[error("unsupported compression algorithm '{0}'")]
454-
UnsupportedCompressionAlgorithm(String),
455-
456-
/// Feature required to use the specified compression algorithm.
457-
#[cfg(any(not(feature = "gzip-tonic"), not(feature = "zstd-tonic")))]
458-
#[error("feature '{0}' is required to use the compression algorithm '{1}'")]
459-
FeatureRequiredForCompressionAlgorithm(&'static str, Compression),
460-
}
461-
462-
#[cfg(feature = "grpc-tonic")]
463-
impl From<tonic::Status> for Error {
464-
fn from(status: tonic::Status) -> Error {
465-
Error::Status {
466-
code: status.code(),
467-
message: {
468-
if !status.message().is_empty() {
469-
let mut result = ", detailed error message: ".to_string() + status.message();
470-
if status.code() == tonic::Code::Unknown {
471-
let source = (&status as &dyn std::error::Error)
472-
.source()
473-
.map(|e| format!("{:?}", e));
474-
result.push(' ');
475-
result.push_str(source.unwrap_or_default().as_ref());
476-
}
477-
result
478-
} else {
479-
String::new()
480-
}
481-
},
482-
}
483-
}
484-
}
485-
486-
impl ExportError for Error {
487-
fn exporter_name(&self) -> &'static str {
488-
"otlp"
489-
}
490-
}
491-
492392
/// The communication protocol to use when exporting data.
493393
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
494394
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

opentelemetry-sdk/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@
7575
- **Breaking** for custom `LogProcessor` authors: Changed `set_resource`
7676
to require mutable ref.
7777
`fn set_resource(&mut self, _resource: &Resource) {}`
78-
- **Breaking** Removed deprecated functions and methods related to `trace::Config`
78+
- **Breaking**: InMemoryExporter's return type change.
79+
- `TraceResult<Vec<SpanData>>` to `Result<Vec<SpanData>, InMemoryExporterError>`
80+
- `MetricResult<Vec<ResourceMetrics>>` to `Result<Vec<ResourceMetrics>, InMemoryExporterError>`
81+
- `LogResult<Vec<LogDataWithResource>>` to `Result<Vec<LogDataWithResource>, InMemoryExporterError>`
7982

8083
## 0.28.0
8184

opentelemetry-sdk/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,24 @@ pub use resource::Resource;
146146

147147
pub mod error;
148148
pub use error::ExportError;
149+
150+
#[cfg(any(feature = "testing", test))]
151+
#[derive(thiserror::Error, Debug)]
152+
/// Errors that can occur during when returning telemetry from InMemoryLogExporter
153+
pub enum InMemoryExporterError {
154+
/// Operation failed due to an internal error.
155+
///
156+
/// The error message is intended for logging purposes only and should not
157+
/// be used to make programmatic decisions. It is implementation-specific
158+
/// and subject to change without notice. Consumers of this error should not
159+
/// rely on its content beyond logging.
160+
#[error("Unable to obtain telemetry. Reason: {0}")]
161+
InternalFailure(String),
162+
}
163+
164+
#[cfg(any(feature = "testing", test))]
165+
impl<T> From<std::sync::PoisonError<T>> for InMemoryExporterError {
166+
fn from(err: std::sync::PoisonError<T>) -> Self {
167+
InMemoryExporterError::InternalFailure(format!("Mutex poison error: {}", err))
168+
}
169+
}

opentelemetry-sdk/src/logs/in_memory_exporter.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use crate::error::{OTelSdkError, OTelSdkResult};
22
use crate::logs::SdkLogRecord;
33
use crate::logs::{LogBatch, LogExporter};
4+
use crate::InMemoryExporterError;
45
use crate::Resource;
56
use opentelemetry::InstrumentationScope;
67
use std::borrow::Cow;
78
use std::sync::atomic::AtomicBool;
89
use std::sync::{Arc, Mutex};
910

10-
type LogResult<T> = Result<T, OTelSdkError>;
11-
1211
/// An in-memory logs exporter that stores logs data in memory..
1312
///
1413
/// This exporter is useful for testing and debugging purposes.
@@ -157,14 +156,9 @@ impl InMemoryLogExporter {
157156
/// let emitted_logs = exporter.get_emitted_logs().unwrap();
158157
/// ```
159158
///
160-
pub fn get_emitted_logs(&self) -> LogResult<Vec<LogDataWithResource>> {
161-
let logs_guard = self
162-
.logs
163-
.lock()
164-
.map_err(|e| OTelSdkError::InternalFailure(format!("Failed to lock logs: {}", e)))?;
165-
let resource_guard = self.resource.lock().map_err(|e| {
166-
OTelSdkError::InternalFailure(format!("Failed to lock resource: {}", e))
167-
})?;
159+
pub fn get_emitted_logs(&self) -> Result<Vec<LogDataWithResource>, InMemoryExporterError> {
160+
let logs_guard = self.logs.lock().map_err(InMemoryExporterError::from)?;
161+
let resource_guard = self.resource.lock().map_err(InMemoryExporterError::from)?;
168162
let logs: Vec<LogDataWithResource> = logs_guard
169163
.iter()
170164
.map(|log_data| LogDataWithResource {

opentelemetry-sdk/src/metrics/in_memory_exporter.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use crate::error::{OTelSdkError, OTelSdkResult};
22
use crate::metrics::data::{self, Gauge, Sum};
33
use crate::metrics::data::{Histogram, Metric, ResourceMetrics, ScopeMetrics};
44
use crate::metrics::exporter::PushMetricExporter;
5-
use crate::metrics::MetricError;
6-
use crate::metrics::MetricResult;
75
use crate::metrics::Temporality;
6+
use crate::InMemoryExporterError;
87
use std::collections::VecDeque;
98
use std::fmt;
109
use std::sync::{Arc, Mutex};
@@ -143,11 +142,13 @@ impl InMemoryMetricExporter {
143142
/// let exporter = InMemoryMetricExporter::default();
144143
/// let finished_metrics = exporter.get_finished_metrics().unwrap();
145144
/// ```
146-
pub fn get_finished_metrics(&self) -> MetricResult<Vec<ResourceMetrics>> {
147-
self.metrics
145+
pub fn get_finished_metrics(&self) -> Result<Vec<ResourceMetrics>, InMemoryExporterError> {
146+
let metrics = self
147+
.metrics
148148
.lock()
149149
.map(|metrics_guard| metrics_guard.iter().map(Self::clone_metrics).collect())
150-
.map_err(MetricError::from)
150+
.map_err(InMemoryExporterError::from)?;
151+
Ok(metrics)
151152
}
152153

153154
/// Clears the internal storage of finished metrics.

opentelemetry-sdk/src/trace/in_memory_exporter.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::error::{OTelSdkError, OTelSdkResult};
22
use crate::resource::Resource;
3-
use crate::trace::error::{TraceError, TraceResult};
43
use crate::trace::{SpanData, SpanExporter};
4+
use crate::InMemoryExporterError;
55
use std::sync::{Arc, Mutex};
66

77
/// An in-memory span exporter that stores span data in memory.
@@ -104,11 +104,13 @@ impl InMemorySpanExporter {
104104
/// let exporter = InMemorySpanExporter::default();
105105
/// let finished_spans = exporter.get_finished_spans().unwrap();
106106
/// ```
107-
pub fn get_finished_spans(&self) -> TraceResult<Vec<SpanData>> {
108-
self.spans
107+
pub fn get_finished_spans(&self) -> Result<Vec<SpanData>, InMemoryExporterError> {
108+
let spans = self
109+
.spans
109110
.lock()
110111
.map(|spans_guard| spans_guard.iter().cloned().collect())
111-
.map_err(TraceError::from)
112+
.map_err(InMemoryExporterError::from)?;
113+
Ok(spans)
112114
}
113115

114116
/// Clears the internal storage of finished spans.

0 commit comments

Comments
 (0)