|
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 |
4 | 2 | //! |
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) |
7 | 13 | //! |
8 | | -//! Currently, this crate supports sending telemetry in OTLP via gRPC and HTTP (binary and JSON). |
| 14 | +//! ## Quickstart with OpenTelemetry Collector |
9 | 15 | //! |
10 | | -//! # Quickstart with OpenTelemetry Collector (HTTP) |
| 16 | +//! ### HTTP Transport (Port 4318) |
11 | 17 | //! |
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: |
14 | 19 | //! |
15 | 20 | //! ```shell |
16 | 21 | //! $ docker run -p 4318:4318 otel/opentelemetry-collector:latest |
17 | 22 | //! ``` |
18 | 23 | //! |
| 24 | +//! Configure your application to export traces via HTTP: |
| 25 | +//! |
19 | 26 | //! ```no_run |
20 | 27 | //! # #[cfg(all(feature = "trace", feature = "http-proto"))] |
21 | 28 | //! # { |
22 | 29 | //! use opentelemetry::global; |
23 | 30 | //! use opentelemetry::trace::Tracer; |
| 31 | +//! use opentelemetry_otlp::Protocol; |
24 | 32 | //! |
25 | 33 | //! 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 |
27 | 41 | //! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder() |
28 | 42 | //! .with_simple_exporter(otlp_exporter) |
29 | 43 | //! .build(); |
| 44 | +//! |
| 45 | +//! // Get a tracer and create spans |
30 | 46 | //! 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... |
33 | 49 | //! }); |
34 | 50 | //! |
35 | 51 | //! Ok(()) |
36 | | -//! # } |
| 52 | +//! # } |
37 | 53 | //! } |
38 | 54 | //! ``` |
39 | | -//! # Quickstart with OpenTelemetry Collector (gRPC) |
40 | 55 | //! |
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: |
43 | 59 | //! |
44 | 60 | //! ```shell |
45 | 61 | //! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest |
46 | 62 | //! ``` |
47 | 63 | //! |
| 64 | +//! Configure your application to export traces via gRPC: |
| 65 | +//! |
48 | 66 | //! ```no_run |
49 | 67 | //! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))] |
50 | 68 | //! # { |
51 | 69 | //! use opentelemetry::global; |
52 | 70 | //! use opentelemetry::trace::Tracer; |
53 | 71 | //! |
54 | 72 | //! 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 |
56 | 79 | //! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder() |
57 | 80 | //! .with_simple_exporter(otlp_exporter) |
58 | 81 | //! .build(); |
| 82 | +//! |
| 83 | +//! // Get a tracer and create spans |
59 | 84 | //! 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... |
62 | 87 | //! }); |
63 | 88 | //! |
64 | 89 | //! Ok(()) |
65 | | -//! # } |
| 90 | +//! # } |
66 | 91 | //! } |
67 | 92 | //! ``` |
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 | +//! |
72 | 98 | //! ```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 |
74 | 100 | //! ``` |
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` |
77 | 104 | //! |
78 | 105 | //! ## Performance |
79 | 106 | //! |
|
0 commit comments