Skip to content

Commit 4dbb16a

Browse files
committed
rearrange
1 parent f5ace44 commit 4dbb16a

File tree

1 file changed

+54
-27
lines changed

1 file changed

+54
-27
lines changed

opentelemetry-otlp/src/lib.rs

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,106 @@
1-
//! The OTLP Exporter allows exporting logs, metrics, and traces in the OTLP
2-
//! format to any backend that supports OTLP. This includes the OpenTelemetry Collector,
3-
//! open-source telemetry solutions like Prometheus and Jaeger, and vendor-specific endpoints.
1+
//! # OpenTelemetry OTLP Exporter
42
//!
5-
//! The OpenTelemetry Collector provides a vendor-neutral way to receive, process, and export telemetry data.
6-
//! It simplifies instrumentation by removing the need to operate multiple agents for different telemetry formats.
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:
5+
//!
6+
//! - OpenTelemetry Collector
7+
//! - Open-source observability tools (Prometheus, Jaeger, etc.)
8+
//! - Vendor-specific monitoring platforms
9+
//!
10+
//! This crate supports sending OTLP data via:
11+
//! - gRPC
12+
//! - HTTP (binary protobuf or JSON)
713
//!
8-
//! Currently, this crate supports sending telemetry in OTLP via gRPC and HTTP (binary and JSON).
14+
//! ## Quickstart with OpenTelemetry Collector
915
//!
10-
//! # Quickstart with OpenTelemetry Collector (HTTP)
16+
//! ### HTTP Transport (Port 4318)
1117
//!
12-
//! The following examples sets up Collector to receive OTLP data over HTTP on port 4318,
13-
//! and the application is configured to send OTLP data to this Collector.
18+
//! Run the OpenTelemetry Collector:
1419
//!
1520
//! ```shell
1621
//! $ docker run -p 4318:4318 otel/opentelemetry-collector:latest
1722
//! ```
1823
//!
24+
//! Configure your application to export traces via HTTP:
25+
//!
1926
//! ```no_run
2027
//! # #[cfg(all(feature = "trace", feature = "http-proto"))]
2128
//! # {
2229
//! use opentelemetry::global;
2330
//! use opentelemetry::trace::Tracer;
31+
//! use opentelemetry_otlp::Protocol;
2432
//!
2533
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
26-
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder().with_http().with_protocol(Protocol::HttpBinary).build()?;
34+
//! // Initialize OTLP exporter using HTTP binary protocol
35+
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
36+
//! .with_http()
37+
//! .with_protocol(Protocol::HttpBinary)
38+
//! .build()?;
39+
//!
40+
//! // Create a tracer provider with the exporter
2741
//! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder()
2842
//! .with_simple_exporter(otlp_exporter)
2943
//! .build();
44+
//!
45+
//! // Get a tracer and create spans
3046
//! let tracer = global::tracer("my_tracer");
31-
//! tracer.in_span("doing_work", |cx| {
32-
//! // Traced application logic here...
47+
//! tracer.in_span("doing_work", |_cx| {
48+
//! // Your application logic here...
3349
//! });
3450
//!
3551
//! Ok(())
36-
//! # }
52+
//! # }
3753
//! }
3854
//! ```
39-
//! # Quickstart with OpenTelemetry Collector (gRPC)
4055
//!
41-
//! The following examples sets up Collector to receive OTLP data over gRPC on port 4317,
42-
//! and the application is configured to send OTLP data to this Collector.
56+
//! ### gRPC Transport (Port 4317)
57+
//!
58+
//! Run the OpenTelemetry Collector:
4359
//!
4460
//! ```shell
4561
//! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest
4662
//! ```
4763
//!
64+
//! Configure your application to export traces via gRPC:
65+
//!
4866
//! ```no_run
4967
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
5068
//! # {
5169
//! use opentelemetry::global;
5270
//! use opentelemetry::trace::Tracer;
5371
//!
5472
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
55-
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?;
73+
//! // Initialize OTLP exporter using gRPC (Tonic)
74+
//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder()
75+
//! .with_tonic()
76+
//! .build()?;
77+
//!
78+
//! // Create a tracer provider with the exporter
5679
//! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder()
5780
//! .with_simple_exporter(otlp_exporter)
5881
//! .build();
82+
//!
83+
//! // Get a tracer and create spans
5984
//! let tracer = global::tracer("my_tracer");
60-
//! tracer.in_span("doing_work", |cx| {
61-
//! // Traced application logic here...
85+
//! tracer.in_span("doing_work", |_cx| {
86+
//! // Your application logic here...
6287
//! });
6388
//!
6489
//! Ok(())
65-
//! # }
90+
//! # }
6691
//! }
6792
//! ```
68-
//!
69-
//! The same application can also send traces to Jaeger, which natively supports OTLP.
70-
//! The following command shows how to run Jaeger with the OTLP endpoint enabled.
71-
//!
93+
//!
94+
//! ## Using with Jaeger
95+
//!
96+
//! Jaeger natively supports the OTLP protocol, making it easy to send traces directly:
97+
//!
7298
//! ```shell
73-
//! docker run -p16686:16686 -p4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest
99+
//! $ docker run -p 16686:16686 -p 4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest
74100
//! ```
75-
//!
76-
//! After running the application, you can view the traces in Jaeger UI at `http://localhost:16686`.
101+
//!
102+
//! After running your application configured with the OTLP exporter, view traces at:
103+
//! `http://localhost:16686`
77104
//!
78105
//! ## Performance
79106
//!

0 commit comments

Comments
 (0)