|
7 | 7 | //! order to support open-source telemetry data formats (e.g. Jaeger,
|
8 | 8 | //! Prometheus, etc.) sending to multiple open-source or commercial back-ends.
|
9 | 9 | //!
|
10 |
| -//! Currently, this crate only support sending telemetry in OTLP |
11 |
| -//! via grpc and http (in binary format). Supports for other format and protocol |
12 |
| -//! will be added in the future. The details of what's currently offering in this |
13 |
| -//! crate can be found in this doc. |
| 10 | +//! Currently, this crate supports sending telemetry in OTLP |
| 11 | +//! via gRPC and http (binary and json). |
14 | 12 | //!
|
15 | 13 | //! # Quickstart
|
16 | 14 | //!
|
|
56 | 54 | //!
|
57 | 55 | //! ## Performance
|
58 | 56 | //!
|
59 |
| -//! For optimal performance, a batch exporter is recommended as the simple |
60 |
| -//! exporter will export each span synchronously on dropping. You can enable the |
61 |
| -//! [`rt-tokio`], [`rt-tokio-current-thread`] or [`rt-async-std`] features and |
62 |
| -//! specify a runtime on the pipeline builder to have a batch exporter |
63 |
| -//! configured for you automatically. |
| 57 | +//! For optimal performance, a batch exporting processor is recommended as the simple |
| 58 | +//! processor will export each span synchronously on dropping, and is only good |
| 59 | +//! for test/debug purposes. |
64 | 60 | //!
|
65 | 61 | //! ```toml
|
66 | 62 | //! [dependencies]
|
67 |
| -//! opentelemetry_sdk = { version = "*", features = ["async-std"] } |
68 | 63 | //! opentelemetry-otlp = { version = "*", features = ["grpc-tonic"] }
|
69 | 64 | //! ```
|
70 | 65 | //!
|
71 | 66 | //! ```no_run
|
72 | 67 | //! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
|
73 | 68 | //! # {
|
74 |
| -//! # fn main() -> Result<(), opentelemetry::trace::TraceError> { |
75 |
| -//! let tracer = opentelemetry_sdk::trace::TracerProvider::builder() |
76 |
| -//! .with_batch_exporter( |
77 |
| -//! opentelemetry_otlp::SpanExporter::builder() |
78 |
| -//! .with_tonic() |
79 |
| -//! .build()?, |
80 |
| -//! opentelemetry_sdk::runtime::Tokio, |
81 |
| -//! ) |
82 |
| -//! .build(); |
| 69 | +//! use opentelemetry::global; |
| 70 | +//! use opentelemetry::trace::Tracer; |
83 | 71 | //!
|
84 |
| -//! # Ok(()) |
85 |
| -//! # } |
86 |
| -//! # } |
| 72 | +//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { |
| 73 | +//! // First, create a OTLP exporter builder. Configure it as you need. |
| 74 | +//! let otlp_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?; |
| 75 | +//! // Then pass it into provider builder |
| 76 | +//! let _ = opentelemetry_sdk::trace::TracerProvider::builder() |
| 77 | +//! .with_batch_exporter(otlp_exporter) |
| 78 | +//! .build(); |
| 79 | +//! let tracer = global::tracer("my_tracer"); |
| 80 | +//! tracer.in_span("doing_work", |cx| { |
| 81 | +//! // Traced app logic here... |
| 82 | +//! }); |
| 83 | +//! |
| 84 | +//! Ok(()) |
| 85 | +//! # } |
| 86 | +//! } |
87 | 87 | //! ```
|
88 | 88 | //!
|
89 | 89 | //! [`tokio`]: https://tokio.rs
|
|
92 | 92 | //! # Feature Flags
|
93 | 93 | //! The following feature flags can enable exporters for different telemetry signals:
|
94 | 94 | //!
|
95 |
| -//! * `trace`: Includes the trace exporters (enabled by default). |
| 95 | +//! * `trace`: Includes the trace exporters. |
96 | 96 | //! * `metrics`: Includes the metrics exporters.
|
97 | 97 | //! * `logs`: Includes the logs exporters.
|
98 | 98 | //!
|
|
101 | 101 | //!
|
102 | 102 | //! The following feature flags offer additional configurations on gRPC:
|
103 | 103 | //!
|
104 |
| -//! For users uses `tonic` as grpc layer: |
105 |
| -//! * `grpc-tonic`: Use `tonic` as grpc layer. This is enabled by default. |
| 104 | +//! For users using `tonic` as grpc layer: |
| 105 | +//! * `grpc-tonic`: Use `tonic` as grpc layer. |
106 | 106 | //! * `gzip-tonic`: Use gzip compression for `tonic` grpc layer.
|
107 | 107 | //! * `zstd-tonic`: Use zstd compression for `tonic` grpc layer.
|
108 | 108 | //! * `tls-roots`: Adds system trust roots to rustls-based gRPC clients using the rustls-native-certs crate
|
109 | 109 | //! * `tls-webpki-roots`: Embeds Mozilla's trust roots to rustls-based gRPC clients using the webpki-roots crate
|
110 | 110 | //!
|
111 | 111 | //! The following feature flags offer additional configurations on http:
|
112 | 112 | //!
|
113 |
| -//! * `http-proto`: Use http as transport layer, protobuf as body format. |
114 |
| -//! * `reqwest-blocking-client`: Use reqwest blocking http client. |
| 113 | +//! * `http-proto`: Use http as transport layer, protobuf as body format. This feature is enabled by default. |
| 114 | +//! * `reqwest-blocking-client`: Use reqwest blocking http client. This feature is enabled by default. |
115 | 115 | //! * `reqwest-client`: Use reqwest http client.
|
116 | 116 | //! * `reqwest-rustls`: Use reqwest with TLS with system trust roots via `rustls-native-certs` crate.
|
117 | 117 | //! * `reqwest-rustls-webpki-roots`: Use reqwest with TLS with Mozilla's trust roots via `webpki-roots` crate.
|
|
152 | 152 | //! .build()?;
|
153 | 153 | //!
|
154 | 154 | //! let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder()
|
155 |
| -//! .with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio) |
| 155 | +//! .with_batch_exporter(exporter) |
156 | 156 | //! .with_config(
|
157 | 157 | //! trace::Config::default()
|
158 | 158 | //! .with_sampler(Sampler::AlwaysOn)
|
|
162 | 162 | //! .with_max_events_per_span(16)
|
163 | 163 | //! .with_resource(Resource::builder_empty().with_attributes([KeyValue::new("service.name", "example")]).build()),
|
164 | 164 | //! ).build();
|
165 |
| -//! global::set_tracer_provider(tracer_provider); |
| 165 | +//! global::set_tracer_provider(tracer_provider.clone()); |
166 | 166 | //! let tracer = global::tracer("tracer-name");
|
167 | 167 | //! # tracer
|
168 | 168 | //! # };
|
|
179 | 179 | //!
|
180 | 180 | //! let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter)
|
181 | 181 | //! .with_interval(std::time::Duration::from_secs(3))
|
182 |
| -//! .with_timeout(Duration::from_secs(10)) |
| 182 | +//! .with_timeout(Duration::from_secs(10)) |
183 | 183 | //! .build();
|
184 | 184 | //!
|
185 | 185 | //! let provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder()
|
|
0 commit comments