|
1 | | -//! The OTLP Exporter supports exporting logs, metrics and traces in the OTLP |
2 | | -//! format to the OpenTelemetry collector or other compatible backend. |
| 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. |
3 | 4 | //! |
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. |
| 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. |
9 | 7 | //! |
10 | | -//! Currently, this crate supports sending telemetry in OTLP |
11 | | -//! via gRPC and http (binary and json). |
| 8 | +//! Currently, this crate supports sending telemetry in OTLP via gRPC and HTTP (binary and JSON). |
12 | 9 | //! |
13 | | -//! # Quickstart |
| 10 | +//! # Quickstart with OpenTelemetry Collector (HTTP) |
14 | 11 | //! |
15 | | -//! First make sure you have a running version of the opentelemetry collector |
16 | | -//! you want to send data to: |
| 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. |
17 | 14 | //! |
18 | 15 | //! ```shell |
19 | | -//! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest |
| 16 | +//! $ docker run -p 4318:4318 otel/opentelemetry-collector:latest |
20 | 17 | //! ``` |
21 | 18 | //! |
22 | | -//! Then create a new `Exporter`, and `Provider` with the recommended defaults to start exporting |
23 | | -//! telemetry. |
| 19 | +//! ```no_run |
| 20 | +//! # #[cfg(all(feature = "trace", feature = "http-proto"))] |
| 21 | +//! # { |
| 22 | +//! use opentelemetry::global; |
| 23 | +//! use opentelemetry::trace::Tracer; |
| 24 | +//! |
| 25 | +//! 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()?; |
| 27 | +//! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder() |
| 28 | +//! .with_simple_exporter(otlp_exporter) |
| 29 | +//! .build(); |
| 30 | +//! let tracer = global::tracer("my_tracer"); |
| 31 | +//! tracer.in_span("doing_work", |cx| { |
| 32 | +//! // Traced application logic here... |
| 33 | +//! }); |
| 34 | +//! |
| 35 | +//! Ok(()) |
| 36 | +//! # } |
| 37 | +//! } |
| 38 | +//! ``` |
| 39 | +//! # Quickstart with OpenTelemetry Collector (gRPC) |
24 | 40 | //! |
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. |
| 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. |
28 | 43 | //! |
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. |
| 44 | +//! ```shell |
| 45 | +//! $ docker run -p 4317:4317 otel/opentelemetry-collector:latest |
| 46 | +//! ``` |
31 | 47 | //! |
32 | 48 | //! ```no_run |
33 | 49 | //! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))] |
|
36 | 52 | //! use opentelemetry::trace::Tracer; |
37 | 53 | //! |
38 | 54 | //! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { |
39 | | -//! // First, create a OTLP exporter builder. Configure it as you need. |
40 | 55 | //! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?; |
41 | | -//! // Then pass it into provider builder |
42 | 56 | //! let _ = opentelemetry_sdk::trace::SdkTracerProvider::builder() |
43 | 57 | //! .with_simple_exporter(otlp_exporter) |
44 | 58 | //! .build(); |
45 | 59 | //! let tracer = global::tracer("my_tracer"); |
46 | 60 | //! tracer.in_span("doing_work", |cx| { |
47 | | -//! // Traced app logic here... |
| 61 | +//! // Traced application logic here... |
48 | 62 | //! }); |
49 | 63 | //! |
50 | 64 | //! Ok(()) |
51 | 65 | //! # } |
52 | 66 | //! } |
53 | 67 | //! ``` |
| 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 | +//! |
| 72 | +//! ```shell |
| 73 | +//! docker run -p16686:16686 -p4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest |
| 74 | +//! ``` |
| 75 | +//! |
| 76 | +//! After running the application, you can view the traces in Jaeger UI at `http://localhost:16686`. |
54 | 77 | //! |
55 | 78 | //! ## Performance |
56 | 79 | //! |
|
0 commit comments