Skip to content

Commit d555741

Browse files
authored
Update sdk trace docs (open-telemetry#769)
1 parent 655b5af commit d555741

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

opentelemetry-sdk/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#![cfg_attr(test, deny(warnings))]
2828

2929
pub mod export;
30-
pub mod instrumentation;
30+
mod instrumentation;
3131
#[cfg(feature = "metrics")]
3232
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
3333
pub mod metrics;
@@ -46,4 +46,5 @@ pub mod trace;
4646
pub mod util;
4747

4848
pub use instrumentation::InstrumentationLibrary;
49+
#[doc(inline)]
4950
pub use resource::Resource;

opentelemetry-sdk/src/resource/mod.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
//! # Resource
1+
//! Representations of entities producing telemetry.
22
//!
3-
//! A `Resource` is an immutable representation of the entity producing telemetry. For example, a
4-
//! process producing telemetry that is running in a container on Kubernetes has a Pod name, it is
5-
//! in a namespace, and possibly is part of a Deployment which also has a name. All three of these
6-
//! attributes can be included in the `Resource`.
3+
//! A [Resource] is an immutable representation of the entity producing
4+
//! telemetry as attributes. For example, a process producing telemetry that is
5+
//! running in a container on Kubernetes has a Pod name, it is in a namespace
6+
//! and possibly is part of a Deployment which also has a name. All three of
7+
//! these attributes can be included in the `Resource`. Note that there are
8+
//! certain ["standard attributes"] that have prescribed meanings.
79
//!
8-
//! The primary purpose of resources as a first-class concept in the SDK is decoupling of discovery
9-
//! of resource information from exporters. This allows for independent development and easy
10-
//! customization for users that need to integrate with closed source environments. When used with
11-
//! distributed tracing, a resource can be associated with the [`TracerProvider`] when it is created.
12-
//! That association cannot be changed later. When associated with a `TracerProvider`, all `Span`s
13-
//! produced by any `Tracer` from the provider are associated with this `Resource`.
14-
//!
15-
//! [`TracerProvider`]: crate::trace::TracerProvider
10+
//! ["standard attributes"]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/resource/semantic_conventions/README.md
1611
//!
1712
//! # Resource detectors
1813
//!
19-
//! `ResourceDetector`s are used to detect resource from runtime or environmental variables. The
20-
//! following `ResourceDetector`s are provided along with this SDK.
14+
//! [`ResourceDetector`]s are used to detect resource from runtime or
15+
//! environmental variables. The following are provided by default with this
16+
//! SDK.
2117
//!
22-
//! - EnvResourceDetector, detect resource from environmental variables.
23-
//! - OsResourceDetector, detect OS from runtime.
24-
//! - ProcessResourceDetector, detect process information
18+
//! - [`EnvResourceDetector`] - detect resource from environmental variables.
19+
//! - [`OsResourceDetector`] - detect OS from runtime.
20+
//! - [`ProcessResourceDetector`] - detect process information.
2521
mod env;
2622
mod os;
2723
mod process;
@@ -38,9 +34,7 @@ use std::collections::{btree_map, BTreeMap};
3834
use std::ops::Deref;
3935
use std::time::Duration;
4036

41-
/// Describes an entity about which identifying information and metadata is exposed.
42-
///
43-
/// Items are sorted by their key, and are only overwritten if the value is an empty string.
37+
/// An immutable representation of the entity producing telemetry as attributes.
4438
#[derive(Clone, Debug, PartialEq)]
4539
pub struct Resource {
4640
attrs: BTreeMap<Key, Value>,

opentelemetry-sdk/src/trace/provider.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,42 @@ impl TracerProvider {
7171
}
7272

7373
/// Force flush all remaining spans in span processors and return results.
74+
///
75+
/// # Examples
76+
///
77+
/// ```
78+
/// use opentelemetry_api::global;
79+
/// use opentelemetry_sdk::trace::TracerProvider;
80+
///
81+
/// fn init_tracing() -> TracerProvider {
82+
/// let provider = TracerProvider::default();
83+
///
84+
/// // Set provider to be used as global tracer provider
85+
/// let _ = global::set_tracer_provider(provider.clone());
86+
///
87+
/// provider
88+
/// }
89+
///
90+
/// fn main() {
91+
/// let provider = init_tracing();
92+
///
93+
/// // create spans..
94+
///
95+
/// // force all spans to flush
96+
/// for result in provider.force_flush() {
97+
/// if let Err(err) = result {
98+
/// // .. handle flush error
99+
/// }
100+
/// }
101+
///
102+
/// // create more spans..
103+
///
104+
/// // dropping provider and shutting down global provider ensure all
105+
/// // remaining spans are exported
106+
/// drop(provider);
107+
/// global::shutdown_tracer_provider();
108+
/// }
109+
/// ```
74110
pub fn force_flush(&self) -> Vec<TraceResult<()>> {
75111
self.span_processors()
76112
.iter()

0 commit comments

Comments
 (0)