Skip to content

Commit c65a566

Browse files
authored
Merge branch 'main' into cijothomas/tracingd
2 parents 7ead543 + 2070e6c commit c65a566

File tree

14 files changed

+269
-241
lines changed

14 files changed

+269
-241
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ you're more than welcome to participate!
181181

182182
* [Cijo Thomas](https://github.com/cijothomas)
183183
* [Harold Dost](https://github.com/hdost)
184-
* [Julian Tescher](https://github.com/jtescher)
185184
* [Lalit Kumar Bhasin](https://github.com/lalitb)
186185
* [Utkarsh Umesan Pillai](https://github.com/utpilla)
187186
* [Zhongyang Wu](https://github.com/TommyCpp)
@@ -195,6 +194,7 @@ you're more than welcome to participate!
195194

196195
* [Dirkjan Ochtman](https://github.com/djc)
197196
* [Jan Kühle](https://github.com/frigus02)
197+
* [Julian Tescher](https://github.com/jtescher)
198198
* [Isobel Redelmeier](https://github.com/iredelmeier)
199199
* [Mike Goldsmith](https://github.com/MikeGoldsmith)
200200

examples/tracing-jaeger/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/tracing-jaeger/README.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/tracing-jaeger/jaeger.png

-165 KB
Binary file not shown.

examples/tracing-jaeger/src/main.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

opentelemetry-otlp/examples/basic-otlp-http/src/main.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,27 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
164164

165165
info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99);
166166

167-
tracer_provider.shutdown()?;
168-
meter_provider.shutdown()?;
169-
logger_provider.shutdown()?;
167+
// Collect all shutdown errors
168+
let mut shutdown_errors = Vec::new();
169+
if let Err(e) = tracer_provider.shutdown() {
170+
shutdown_errors.push(format!("tracer provider: {}", e));
171+
}
172+
173+
if let Err(e) = meter_provider.shutdown() {
174+
shutdown_errors.push(format!("meter provider: {}", e));
175+
}
170176

177+
if let Err(e) = logger_provider.shutdown() {
178+
shutdown_errors.push(format!("logger provider: {}", e));
179+
}
180+
181+
// Return an error if any shutdown failed
182+
if !shutdown_errors.is_empty() {
183+
return Err(format!(
184+
"Failed to shutdown providers:{}",
185+
shutdown_errors.join("\n")
186+
)
187+
.into());
188+
}
171189
Ok(())
172190
}

opentelemetry-otlp/examples/basic-otlp/src/main.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,29 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
156156
});
157157

158158
info!(name: "my-event", target: "my-target", "hello from {}. My price is {}", "apple", 1.99);
159-
tracer_provider.shutdown()?;
160-
meter_provider.shutdown()?;
161-
logger_provider.shutdown()?;
159+
160+
// Collect all shutdown errors
161+
let mut shutdown_errors = Vec::new();
162+
if let Err(e) = tracer_provider.shutdown() {
163+
shutdown_errors.push(format!("tracer provider: {}", e));
164+
}
165+
166+
if let Err(e) = meter_provider.shutdown() {
167+
shutdown_errors.push(format!("meter provider: {}", e));
168+
}
169+
170+
if let Err(e) = logger_provider.shutdown() {
171+
shutdown_errors.push(format!("logger provider: {}", e));
172+
}
173+
174+
// Return an error if any shutdown failed
175+
if !shutdown_errors.is_empty() {
176+
return Err(format!(
177+
"Failed to shutdown providers:{}",
178+
shutdown_errors.join("\n")
179+
)
180+
.into());
181+
}
162182

163183
Ok(())
164184
}

opentelemetry-otlp/src/exporter/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ mod tests {
342342
#[cfg(feature = "logs")]
343343
#[cfg(any(feature = "http-proto", feature = "http-json"))]
344344
#[test]
345+
#[ignore = "Unstable due to interference from env variable tests. Re-enable after https://github.com/open-telemetry/opentelemetry-rust/issues/2818 is resolved."]
345346
fn export_builder_error_invalid_http_endpoint() {
346347
use std::time::Duration;
347348

@@ -358,15 +359,20 @@ mod tests {
358359
.with_export_config(ex_config)
359360
.build();
360361

361-
assert!(matches!(
362-
exporter_result,
363-
Err(crate::exporter::ExporterBuildError::InvalidUri(_, _))
364-
));
362+
assert!(
363+
matches!(
364+
exporter_result,
365+
Err(crate::exporter::ExporterBuildError::InvalidUri(_, _))
366+
),
367+
"Expected InvalidUri error, but got {:?}",
368+
exporter_result
369+
);
365370
}
366371

367372
#[cfg(feature = "grpc-tonic")]
368-
#[test]
369-
fn export_builder_error_invalid_grpc_endpoint() {
373+
#[tokio::test]
374+
#[ignore = "Unstable due to interference from env variable tests. Re-enable after https://github.com/open-telemetry/opentelemetry-rust/issues/2818 is resolved."]
375+
async fn export_builder_error_invalid_grpc_endpoint() {
370376
use std::time::Duration;
371377

372378
use crate::{ExportConfig, LogExporter, Protocol, WithExportConfig};

opentelemetry-otlp/src/lib.rs

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,68 @@
1-
//! The OTLP Exporter supports exporting logs, metrics and traces in the OTLP
2-
//! format to the OpenTelemetry collector or other compatible backend.
1+
//! # OpenTelemetry OTLP Exporter
32
//!
4-
//! The OpenTelemetry Collector offers a vendor-agnostic implementation on how
5-
//! to receive, process, and export telemetry data. In addition, it removes
6-
//! the need to run, operate, and maintain multiple agents/collectors in
7-
//! order to support open-source telemetry data formats (e.g. Jaeger,
8-
//! Prometheus, etc.) sending to multiple open-source or commercial back-ends.
3+
//! The OTLP Exporter enables exporting telemetry data (logs, metrics, and traces) in the
4+
//! OpenTelemetry Protocol (OTLP) format to compatible backends. These backends include:
95
//!
10-
//! Currently, this crate supports sending telemetry in OTLP
11-
//! via gRPC and http (binary and json).
6+
//! - OpenTelemetry Collector
7+
//! - Open-source observability tools (Prometheus, Jaeger, etc.)
8+
//! - Vendor-specific monitoring platforms
129
//!
13-
//! # Quickstart
10+
//! This crate supports sending OTLP data via:
11+
//! - gRPC
12+
//! - HTTP (binary protobuf or JSON)
1413
//!
15-
//! First make sure you have a running version of the opentelemetry collector
16-
//! you want to send data to:
14+
//! ## Quickstart with OpenTelemetry Collector
15+
//!
16+
//! ### HTTP Transport (Port 4318)
17+
//!
18+
//! Run the OpenTelemetry Collector:
1719
//!
1820
//! ```shell
19-
//! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest
21+
//! $ docker run -p 4318:4318 otel/opentelemetry-collector:latest
22+
//! ```
23+
//!
24+
//! Configure your application to export traces via HTTP:
25+
//!
26+
//! ```no_run
27+
//! # #[cfg(all(feature = "trace", feature = "http-proto"))]
28+
//! # {
29+
//! use opentelemetry::global;
30+
//! use opentelemetry::trace::Tracer;
31+
//! use opentelemetry_otlp::Protocol;
32+
//! use opentelemetry_otlp::WithExportConfig;
33+
//!
34+
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
35+
//! // Initialize OTLP exporter using HTTP binary protocol
36+
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
37+
//! .with_http()
38+
//! .with_protocol(Protocol::HttpBinary)
39+
//! .build()?;
40+
//!
41+
//! // Create a tracer provider with the exporter
42+
//! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder()
43+
//! .with_simple_exporter(otlp_exporter)
44+
//! .build();
45+
//!
46+
//! // Get a tracer and create spans
47+
//! let tracer = global::tracer("my_tracer");
48+
//! tracer.in_span("doing_work", |_cx| {
49+
//! // Your application logic here...
50+
//! });
51+
//!
52+
//! Ok(())
53+
//! # }
54+
//! }
2055
//! ```
2156
//!
22-
//! Then create a new `Exporter`, and `Provider` with the recommended defaults to start exporting
23-
//! telemetry.
57+
//! ### gRPC Transport (Port 4317)
58+
//!
59+
//! Run the OpenTelemetry Collector:
2460
//!
25-
//! You will have to build a OTLP exporter first. Create the correct exporter based on the signal
26-
//! you are looking to export `SpanExporter::builder()`, `MetricExporter::builder()`,
27-
//! `LogExporter::builder()` respectively for traces, metrics, and logs.
61+
//! ```shell
62+
//! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest
63+
//! ```
2864
//!
29-
//! Once you have the exporter, you can create your `Provider` by starting with `TracerProvider::builder()`,
30-
//! `SdkMeterProvider::builder()`, and `LoggerProvider::builder()` respectively for traces, metrics, and logs.
65+
//! Configure your application to export traces via gRPC:
3166
//!
3267
//! ```no_run
3368
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
@@ -36,22 +71,41 @@
3671
//! use opentelemetry::trace::Tracer;
3772
//!
3873
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
39-
//! // First, create a OTLP exporter builder. Configure it as you need.
40-
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?;
41-
//! // Then pass it into provider builder
74+
//! // Initialize OTLP exporter using gRPC (Tonic)
75+
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
76+
//! .with_tonic()
77+
//! .build()?;
78+
//!
79+
//! // Create a tracer provider with the exporter
4280
//! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder()
4381
//! .with_simple_exporter(otlp_exporter)
4482
//! .build();
83+
//!
84+
//! // Get a tracer and create spans
4585
//! let tracer = global::tracer("my_tracer");
46-
//! tracer.in_span("doing_work", |cx| {
47-
//! // Traced app logic here...
86+
//! tracer.in_span("doing_work", |_cx| {
87+
//! // Your application logic here...
4888
//! });
4989
//!
5090
//! Ok(())
51-
//! # }
91+
//! # }
5292
//! }
5393
//! ```
5494
//!
95+
//! ## Using with Jaeger
96+
//!
97+
//! Jaeger natively supports the OTLP protocol, making it easy to send traces directly:
98+
//!
99+
//! ```shell
100+
//! $ docker run -p 16686:16686 -p 4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest
101+
//! ```
102+
//!
103+
//! After running your application configured with the OTLP exporter, view traces at:
104+
//! `http://localhost:16686`
105+
//!
106+
//! ## Using with Prometheus (TODO)
107+
//! ## Show Logs, Metrics too (TODO)
108+
//!
55109
//! ## Performance
56110
//!
57111
//! For optimal performance, a batch exporting processor is recommended as the simple

opentelemetry/src/context.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! Execution-scoped context propagation.
2+
//!
3+
//! The `context` module provides mechanisms for propagating values across API boundaries and between
4+
//! logically associated execution units. It enables cross-cutting concerns to access their data in-process
5+
//! using a shared context object.
6+
//!
7+
//! # Main Types
8+
//!
9+
//! - [`Context`]: An immutable, execution-scoped collection of values.
10+
//!
11+
112
use crate::otel_warn;
213
#[cfg(feature = "trace")]
314
use crate::trace::context::SynchronizedSpan;
@@ -9,6 +20,10 @@ use std::hash::{BuildHasherDefault, Hasher};
920
use std::marker::PhantomData;
1021
use std::sync::Arc;
1122

23+
mod future_ext;
24+
25+
pub use future_ext::FutureExt;
26+
1227
thread_local! {
1328
static CURRENT_CONTEXT: RefCell<ContextStack> = RefCell::new(ContextStack::default());
1429
}
@@ -78,7 +93,7 @@ thread_local! {
7893
#[derive(Clone, Default)]
7994
pub struct Context {
8095
#[cfg(feature = "trace")]
81-
pub(super) span: Option<Arc<SynchronizedSpan>>,
96+
pub(crate) span: Option<Arc<SynchronizedSpan>>,
8297
entries: Option<Arc<EntryMap>>,
8398
}
8499

@@ -314,15 +329,15 @@ impl Context {
314329
}
315330

316331
#[cfg(feature = "trace")]
317-
pub(super) fn current_with_synchronized_span(value: SynchronizedSpan) -> Self {
332+
pub(crate) fn current_with_synchronized_span(value: SynchronizedSpan) -> Self {
318333
Context {
319334
span: Some(Arc::new(value)),
320335
entries: Context::map_current(|cx| cx.entries.clone()),
321336
}
322337
}
323338

324339
#[cfg(feature = "trace")]
325-
pub(super) fn with_synchronized_span(&self, value: SynchronizedSpan) -> Self {
340+
pub(crate) fn with_synchronized_span(&self, value: SynchronizedSpan) -> Self {
326341
Context {
327342
span: Some(Arc::new(value)),
328343
entries: self.entries.clone(),

0 commit comments

Comments
 (0)