Skip to content

Commit c6d6eba

Browse files
authored
Merge branch 'main' into surface-http-status-errors
2 parents 96e1874 + d19187d commit c6d6eba

File tree

9 files changed

+216
-177
lines changed

9 files changed

+216
-177
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ impl LogExporter for OtlpHttpClient {
3131
request.headers_mut().insert(k.clone(), v.clone());
3232
}
3333

34-
client.send(request).await?;
34+
let request_uri = request.uri().to_string();
35+
let response = client.send(request).await?;
36+
37+
if !response.status().is_success() {
38+
let error = format!(
39+
"OpenTelemetry logs export failed. Url: {}, Status Code: {}, Response: {:?}",
40+
response.status().as_u16(),
41+
request_uri,
42+
response.body()
43+
);
44+
return Err(LogError::Other(error.into()));
45+
}
3546

3647
Ok(())
3748
}

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ impl SpanExporter for OtlpHttpClient {
4646
}
4747

4848
Box::pin(async move {
49-
client.send(request).await?;
49+
let request_uri = request.uri().to_string();
50+
let response = client.send(request).await?;
51+
52+
if !response.status().is_success() {
53+
let error = format!(
54+
"OpenTelemetry trace export failed. Url: {}, Status Code: {}, Response: {:?}",
55+
response.status().as_u16(),
56+
request_uri,
57+
response.body()
58+
);
59+
return Err(TraceError::Other(error.into()));
60+
}
5061

5162
Ok(())
5263
})

opentelemetry-sdk/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- [#1410](https://github.com/open-telemetry/opentelemetry-rust/pull/1410) Add experimental synchronous gauge
88
- [#1471](https://github.com/open-telemetry/opentelemetry-rust/pull/1471) Configure batch log record processor via [`OTEL_BLRP_*`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor) environment variables and via `OtlpLogPipeline::with_batch_config`
9+
- [#1503](https://github.com/open-telemetry/opentelemetry-rust/pull/1503) Make the documentation for In-Memory exporters visible.
910

1011
### Changed
1112

opentelemetry-sdk/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub mod propagation;
136136
pub mod resource;
137137
pub mod runtime;
138138
#[cfg(any(feature = "testing", test))]
139-
#[doc(hidden)]
139+
#[cfg_attr(docsrs, doc(cfg(any(feature = "testing", test))))]
140140
pub mod testing;
141141
#[cfg(feature = "trace")]
142142
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
pub use in_memory_exporter::{InMemoryLogsExporter, InMemoryLogsExporterBuilder};
1+
//! In-Memory log exporter for testing purpose.
22
3-
mod in_memory_exporter;
3+
/// The `in_memory_exporter` module provides in-memory log exporter.
4+
/// For detailed usage and examples, see `in_memory_exporter`.
5+
pub mod in_memory_exporter;
6+
pub use in_memory_exporter::{InMemoryLogsExporter, InMemoryLogsExporterBuilder};
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
pub use in_memory_exporter::{InMemoryMetricsExporter, InMemoryMetricsExporterBuilder};
2-
pub use metric_reader::TestMetricReader;
1+
//! In-Memory metrics exporter for testing purpose.
32
3+
/// The `in_memory_exporter` module provides in-memory metrics exporter.
4+
/// For detailed usage and examples, see `in_memory_exporter`.
45
pub mod in_memory_exporter;
6+
pub use in_memory_exporter::{InMemoryMetricsExporter, InMemoryMetricsExporterBuilder};
7+
8+
#[doc(hidden)]
59
pub mod metric_reader;
10+
pub use metric_reader::TestMetricReader;

opentelemetry-sdk/src/testing/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! In-Memory exporters for testing purpose.
2+
13
#[cfg(all(feature = "testing", feature = "trace"))]
24
pub mod trace;
35

+8-170
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,10 @@
1-
pub use in_memory_exporter::{InMemorySpanExporter, InMemorySpanExporterBuilder};
2-
3-
mod in_memory_exporter;
4-
5-
use crate::{
6-
export::{
7-
trace::{ExportResult, SpanData, SpanExporter},
8-
ExportError,
9-
},
10-
trace::{Config, SpanEvents, SpanLinks},
11-
InstrumentationLibrary,
12-
};
13-
use async_trait::async_trait;
14-
use crossbeam_channel::{unbounded, Receiver, SendError, Sender};
15-
use futures_util::future::BoxFuture;
16-
pub use opentelemetry::testing::trace::TestSpan;
17-
use opentelemetry::trace::{
18-
SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId, TraceState,
19-
};
20-
use std::fmt::{Display, Formatter};
21-
22-
pub fn new_test_export_span_data() -> SpanData {
23-
let config = Config::default();
24-
SpanData {
25-
span_context: SpanContext::new(
26-
TraceId::from_u128(1),
27-
SpanId::from_u64(1),
28-
TraceFlags::SAMPLED,
29-
false,
30-
TraceState::default(),
31-
),
32-
parent_span_id: SpanId::INVALID,
33-
span_kind: SpanKind::Internal,
34-
name: "opentelemetry".into(),
35-
start_time: opentelemetry::time::now(),
36-
end_time: opentelemetry::time::now(),
37-
attributes: Vec::new(),
38-
dropped_attributes_count: 0,
39-
events: SpanEvents::default(),
40-
links: SpanLinks::default(),
41-
status: Status::Unset,
42-
resource: config.resource,
43-
instrumentation_lib: InstrumentationLibrary::default(),
44-
}
45-
}
46-
47-
#[derive(Debug)]
48-
pub struct TestSpanExporter {
49-
tx_export: Sender<SpanData>,
50-
tx_shutdown: Sender<()>,
51-
}
52-
53-
#[async_trait]
54-
impl SpanExporter for TestSpanExporter {
55-
fn export(&mut self, batch: Vec<SpanData>) -> BoxFuture<'static, ExportResult> {
56-
for span_data in batch {
57-
if let Err(err) = self
58-
.tx_export
59-
.send(span_data)
60-
.map_err::<TestExportError, _>(Into::into)
61-
{
62-
return Box::pin(std::future::ready(Err(Into::into(err))));
63-
}
64-
}
65-
Box::pin(std::future::ready(Ok(())))
66-
}
67-
68-
fn shutdown(&mut self) {
69-
let _ = self.tx_shutdown.send(()); // ignore error
70-
}
71-
}
72-
73-
pub fn new_test_exporter() -> (TestSpanExporter, Receiver<SpanData>, Receiver<()>) {
74-
let (tx_export, rx_export) = unbounded();
75-
let (tx_shutdown, rx_shutdown) = unbounded();
76-
let exporter = TestSpanExporter {
77-
tx_export,
78-
tx_shutdown,
79-
};
80-
(exporter, rx_export, rx_shutdown)
81-
}
82-
83-
#[derive(Debug)]
84-
pub struct TokioSpanExporter {
85-
tx_export: tokio::sync::mpsc::UnboundedSender<SpanData>,
86-
tx_shutdown: tokio::sync::mpsc::UnboundedSender<()>,
87-
}
88-
89-
impl SpanExporter for TokioSpanExporter {
90-
fn export(&mut self, batch: Vec<SpanData>) -> BoxFuture<'static, ExportResult> {
91-
for span_data in batch {
92-
if let Err(err) = self
93-
.tx_export
94-
.send(span_data)
95-
.map_err::<TestExportError, _>(Into::into)
96-
{
97-
return Box::pin(std::future::ready(Err(Into::into(err))));
98-
}
99-
}
100-
Box::pin(std::future::ready(Ok(())))
101-
}
1+
//! In-Memory trace exporter for testing purpose.
1022
103-
fn shutdown(&mut self) {
104-
self.tx_shutdown.send(()).unwrap();
105-
}
106-
}
107-
108-
pub fn new_tokio_test_exporter() -> (
109-
TokioSpanExporter,
110-
tokio::sync::mpsc::UnboundedReceiver<SpanData>,
111-
tokio::sync::mpsc::UnboundedReceiver<()>,
112-
) {
113-
let (tx_export, rx_export) = tokio::sync::mpsc::unbounded_channel();
114-
let (tx_shutdown, rx_shutdown) = tokio::sync::mpsc::unbounded_channel();
115-
let exporter = TokioSpanExporter {
116-
tx_export,
117-
tx_shutdown,
118-
};
119-
(exporter, rx_export, rx_shutdown)
120-
}
121-
122-
#[derive(Debug)]
123-
pub struct TestExportError(String);
124-
125-
impl std::error::Error for TestExportError {}
126-
127-
impl ExportError for TestExportError {
128-
fn exporter_name(&self) -> &'static str {
129-
"test"
130-
}
131-
}
132-
133-
impl Display for TestExportError {
134-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
135-
write!(f, "{}", self.0)
136-
}
137-
}
138-
139-
#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))]
140-
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for TestExportError {
141-
fn from(err: tokio::sync::mpsc::error::SendError<T>) -> Self {
142-
TestExportError(err.to_string())
143-
}
144-
}
145-
146-
impl<T> From<crossbeam_channel::SendError<T>> for TestExportError {
147-
fn from(err: SendError<T>) -> Self {
148-
TestExportError(err.to_string())
149-
}
150-
}
151-
152-
/// A no-op instance of an [`SpanExporter`].
153-
///
154-
/// [`SpanExporter`]: crate::export::trace::SpanExporter
155-
#[derive(Debug, Default)]
156-
pub struct NoopSpanExporter {
157-
_private: (),
158-
}
159-
160-
impl NoopSpanExporter {
161-
/// Create a new noop span exporter
162-
pub fn new() -> Self {
163-
NoopSpanExporter { _private: () }
164-
}
165-
}
3+
/// The `in_memory_exporter` module provides in-memory trace exporter.
4+
/// For detailed usage and examples, see `in_memory_exporter`.
5+
pub mod in_memory_exporter;
6+
pub use in_memory_exporter::{InMemorySpanExporter, InMemorySpanExporterBuilder};
1667

167-
#[async_trait::async_trait]
168-
impl SpanExporter for NoopSpanExporter {
169-
fn export(&mut self, _: Vec<SpanData>) -> BoxFuture<'static, ExportResult> {
170-
Box::pin(std::future::ready(Ok(())))
171-
}
172-
}
8+
#[doc(hidden)]
9+
mod span_exporters;
10+
pub use span_exporters::*;

0 commit comments

Comments
 (0)