Skip to content

Commit 6e959c2

Browse files
authored
Merge branch 'main' into cijothomas/stdout-hist
2 parents c88fc95 + 3ec4c18 commit 6e959c2

File tree

2 files changed

+45
-40
lines changed
  • opentelemetry-otlp/src
  • opentelemetry-sdk/src/resource

2 files changed

+45
-40
lines changed

opentelemetry-otlp/src/lib.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
//! order to support open-source telemetry data formats (e.g. Jaeger,
88
//! Prometheus, etc.) sending to multiple open-source or commercial back-ends.
99
//!
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).
1412
//!
1513
//! # Quickstart
1614
//!
@@ -56,34 +54,36 @@
5654
//!
5755
//! ## Performance
5856
//!
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.
6460
//!
6561
//! ```toml
6662
//! [dependencies]
67-
//! opentelemetry_sdk = { version = "*", features = ["async-std"] }
6863
//! opentelemetry-otlp = { version = "*", features = ["grpc-tonic"] }
6964
//! ```
7065
//!
7166
//! ```no_run
7267
//! # #[cfg(all(feature = "trace", feature = "grpc-tonic"))]
7368
//! # {
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;
8371
//!
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+
//! }
8787
//! ```
8888
//!
8989
//! [`tokio`]: https://tokio.rs
@@ -92,7 +92,7 @@
9292
//! # Feature Flags
9393
//! The following feature flags can enable exporters for different telemetry signals:
9494
//!
95-
//! * `trace`: Includes the trace exporters (enabled by default).
95+
//! * `trace`: Includes the trace exporters.
9696
//! * `metrics`: Includes the metrics exporters.
9797
//! * `logs`: Includes the logs exporters.
9898
//!
@@ -101,17 +101,17 @@
101101
//!
102102
//! The following feature flags offer additional configurations on gRPC:
103103
//!
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.
106106
//! * `gzip-tonic`: Use gzip compression for `tonic` grpc layer.
107107
//! * `zstd-tonic`: Use zstd compression for `tonic` grpc layer.
108108
//! * `tls-roots`: Adds system trust roots to rustls-based gRPC clients using the rustls-native-certs crate
109109
//! * `tls-webpki-roots`: Embeds Mozilla's trust roots to rustls-based gRPC clients using the webpki-roots crate
110110
//!
111111
//! The following feature flags offer additional configurations on http:
112112
//!
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.
115115
//! * `reqwest-client`: Use reqwest http client.
116116
//! * `reqwest-rustls`: Use reqwest with TLS with system trust roots via `rustls-native-certs` crate.
117117
//! * `reqwest-rustls-webpki-roots`: Use reqwest with TLS with Mozilla's trust roots via `webpki-roots` crate.
@@ -152,7 +152,7 @@
152152
//! .build()?;
153153
//!
154154
//! let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder()
155-
//! .with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio)
155+
//! .with_batch_exporter(exporter)
156156
//! .with_config(
157157
//! trace::Config::default()
158158
//! .with_sampler(Sampler::AlwaysOn)
@@ -162,7 +162,7 @@
162162
//! .with_max_events_per_span(16)
163163
//! .with_resource(Resource::builder_empty().with_attributes([KeyValue::new("service.name", "example")]).build()),
164164
//! ).build();
165-
//! global::set_tracer_provider(tracer_provider);
165+
//! global::set_tracer_provider(tracer_provider.clone());
166166
//! let tracer = global::tracer("tracer-name");
167167
//! # tracer
168168
//! # };
@@ -179,7 +179,7 @@
179179
//!
180180
//! let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter)
181181
//! .with_interval(std::time::Duration::from_secs(3))
182-
//! .with_timeout(Duration::from_secs(10))
182+
//! .with_timeout(Duration::from_secs(10))
183183
//! .build();
184184
//!
185185
//! let provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder()

opentelemetry-sdk/src/resource/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ impl Resource {
9191

9292
/// Create a new `Resource` from key value pairs.
9393
///
94-
/// Values are de-duplicated by key, and the first key-value pair with a non-empty string value
95-
/// will be retained
94+
/// Values are de-duplicated by key, and the last key-value pair will be retained
9695
pub(crate) fn new<T: IntoIterator<Item = KeyValue>>(kvs: T) -> Self {
9796
let mut attrs = HashMap::new();
9897
for kv in kvs {
@@ -331,18 +330,24 @@ mod tests {
331330

332331
use super::*;
333332

334-
#[test]
335-
fn new_resource() {
336-
let args_with_dupe_keys = [KeyValue::new("a", ""), KeyValue::new("a", "final")];
337-
338-
let mut expected_attrs = HashMap::new();
339-
expected_attrs.insert(Key::new("a"), Value::from("final"));
333+
#[rstest]
334+
#[case([KeyValue::new("a", ""), KeyValue::new("a", "final")], [(Key::new("a"), Value::from("final"))])]
335+
#[case([KeyValue::new("a", "final"), KeyValue::new("a", "")], [(Key::new("a"), Value::from(""))])]
336+
fn new_resource(
337+
#[case] given_attributes: [KeyValue; 2],
338+
#[case] expected_attrs: [(Key, Value); 1],
339+
) {
340+
// Arrange
341+
let expected = HashMap::from_iter(expected_attrs.into_iter());
340342

343+
// Act
341344
let resource = Resource::builder_empty()
342-
.with_attributes(args_with_dupe_keys)
345+
.with_attributes(given_attributes)
343346
.build();
344347
let resource_inner = Arc::try_unwrap(resource.inner).expect("Failed to unwrap Arc");
345-
assert_eq!(resource_inner.attrs, expected_attrs);
348+
349+
// Assert
350+
assert_eq!(resource_inner.attrs, expected);
346351
assert_eq!(resource_inner.schema_url, None);
347352
}
348353

0 commit comments

Comments
 (0)