Skip to content

Commit 11af0ae

Browse files
authored
api: clean up trace docs (open-telemetry#765)
1 parent 3140cfd commit 11af0ae

File tree

5 files changed

+99
-38
lines changed

5 files changed

+99
-38
lines changed

opentelemetry-api/src/baggage.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
//! Primitives for sending name-value data across system boundaries.
1+
//! Primitives for sending name/value data across system boundaries.
2+
//!
3+
//! Baggage is used to annotate telemetry, adding context and information to
4+
//! metrics, traces, and logs. It is a set of name/value pairs describing
5+
//! user-defined properties. Each name in Baggage is associated with exactly one
6+
//! value.
27
//!
38
//! Main types in this module are:
49
//!
5-
//! * [`Baggage`]: Baggage is used to annotate telemetry, adding context and
6-
//! information to metrics, traces, and logs.
10+
//! * [`Baggage`]: A set of name/value pairs describing user-defined properties.
711
//! * [`BaggageExt`]: Extensions for managing `Baggage` in a [`Context`].
812
//!
913
//! Baggage can be sent between systems using a baggage propagator in
@@ -22,7 +26,7 @@ const MAX_KEY_VALUE_PAIRS: usize = 180;
2226
const MAX_BYTES_FOR_ONE_PAIR: usize = 4096;
2327
const MAX_LEN_OF_ALL_PAIRS: usize = 8192;
2428

25-
/// A set of name-value pairs describing user-defined properties.
29+
/// A set of name/value pairs describing user-defined properties.
2630
///
2731
/// ### Baggage Names
2832
///
@@ -35,14 +39,14 @@ const MAX_LEN_OF_ALL_PAIRS: usize = 8192;
3539
/// ### Baggage Value Metadata
3640
///
3741
/// Additional metadata can be added to values in the form of a property set,
38-
/// represented as semi-colon `;` delimited list of names and/or name-value pairs,
42+
/// represented as semi-colon `;` delimited list of names and/or name/value pairs,
3943
/// e.g. `;k1=v1;k2;k3=v3`.
4044
///
4145
/// ### Limits
4246
///
43-
/// * Maximum number of name-value pairs: `180`.
44-
/// * Maximum number of bytes per a single name-value pair: `4096`.
45-
/// * Maximum total length of all name-value pairs: `8192`.
47+
/// * Maximum number of name/value pairs: `180`.
48+
/// * Maximum number of bytes per a single name/value pair: `4096`.
49+
/// * Maximum total length of all name/value pairs: `8192`.
4650
///
4751
/// [RFC2616, Section 2.2]: https://tools.ietf.org/html/rfc2616#section-2.2
4852
#[derive(Debug, Default)]
@@ -92,7 +96,7 @@ impl Baggage {
9296
self.inner.get(&key.into())
9397
}
9498

95-
/// Inserts a name-value pair into the baggage.
99+
/// Inserts a name/value pair into the baggage.
96100
///
97101
/// If the name was not present, [`None`] is returned. If the name was present,
98102
/// the value is updated, and the old value is returned.
@@ -116,7 +120,7 @@ impl Baggage {
116120
.map(|pair| pair.0)
117121
}
118122

119-
/// Inserts a name-value pair into the baggage.
123+
/// Inserts a name/value pair into the baggage.
120124
///
121125
/// Same with `insert`, if the name was not present, [`None`] will be returned.
122126
/// If the name is present, the old value and metadata will be returned.
@@ -279,7 +283,7 @@ impl FromIterator<KeyValueMetadata> for Baggage {
279283

280284
/// Methods for sorting and retrieving baggage data in a context.
281285
pub trait BaggageExt {
282-
/// Returns a clone of the given context with the included name-value pairs.
286+
/// Returns a clone of the given context with the included name/value pairs.
283287
///
284288
/// # Examples
285289
///
@@ -299,7 +303,7 @@ pub trait BaggageExt {
299303
baggage: T,
300304
) -> Self;
301305

302-
/// Returns a clone of the current context with the included name-value pairs.
306+
/// Returns a clone of the current context with the included name/value pairs.
303307
///
304308
/// # Examples
305309
///
@@ -317,7 +321,7 @@ pub trait BaggageExt {
317321
baggage: T,
318322
) -> Self;
319323

320-
/// Returns a clone of the given context with the included name-value pairs.
324+
/// Returns a clone of the given context with the included name/value pairs.
321325
///
322326
/// # Examples
323327
///
@@ -370,7 +374,7 @@ impl BaggageExt for Context {
370374
/// An optional property set that can be added to [`Baggage`] values.
371375
///
372376
/// `BaggageMetadata` can be added to values in the form of a property set,
373-
/// represented as semi-colon `;` delimited list of names and/or name-value
377+
/// represented as semi-colon `;` delimited list of names and/or name/value
374378
/// pairs, e.g. `;k1=v1;k2;k3=v3`.
375379
#[derive(Clone, Debug, PartialOrd, PartialEq, Default)]
376380
pub struct BaggageMetadata(String);
@@ -394,7 +398,7 @@ impl From<&str> for BaggageMetadata {
394398
}
395399
}
396400

397-
/// [`Baggage`] name-value pairs with their associated metadata.
401+
/// [`Baggage`] name/value pairs with their associated metadata.
398402
#[derive(Clone, Debug, PartialEq)]
399403
pub struct KeyValueMetadata {
400404
/// Dimension or event key

opentelemetry-api/src/common.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use std::borrow::Cow;
22
use std::fmt;
33

4-
/// Key used for metric `AttributeSet`s and trace `Span` attributes.
4+
/// The key part of attribute [KeyValue] pairs.
5+
///
6+
/// See the [attribute naming] spec for guidelines.
7+
///
8+
/// [attribute naming]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/common/attribute-naming.md
59
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
610
pub struct Key(Cow<'static, str>);
711

@@ -89,7 +93,7 @@ impl fmt::Display for Key {
8993
}
9094
}
9195

92-
/// Array of homogeneous values
96+
/// A [Value::Array] containing homogeneous values.
9397
#[derive(Clone, Debug, PartialEq)]
9498
pub enum Array {
9599
/// Array of bools
@@ -152,7 +156,7 @@ into_array!(
152156
(Vec<Cow<'static, str>>, Array::String),
153157
);
154158

155-
/// Value types for use in `KeyValue` pairs.
159+
/// The value part of attribute [KeyValue] pairs.
156160
#[derive(Clone, Debug, PartialEq)]
157161
pub enum Value {
158162
/// bool values
@@ -231,12 +235,13 @@ impl fmt::Display for Value {
231235
}
232236
}
233237

234-
/// `KeyValue` pairs are used by `AttributeSet`s and `Span` attributes.
238+
/// A key-value pair describing an attribute.
235239
#[derive(Clone, Debug, PartialEq)]
236240
pub struct KeyValue {
237-
/// Dimension or event key
241+
/// The attribute name
238242
pub key: Key,
239-
/// Dimension or event value
243+
244+
/// The attribute value
240245
pub value: Value,
241246
}
242247

@@ -260,26 +265,43 @@ pub trait ExportError: std::error::Error + Send + Sync + 'static {
260265
fn exporter_name(&self) -> &'static str;
261266
}
262267

263-
/// InstrumentationLibrary contains information about instrumentation library.
268+
/// Information about a library or crate providing instrumentation.
264269
///
265-
/// See `Instrumentation Libraries` for more information.
270+
/// An instrumentation library should be named to follow any naming conventions
271+
/// of the instrumented library (e.g. 'middleware' for a web framework).
266272
///
267-
/// [`Instrumentation Libraries`](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#instrumentation-libraries)
273+
/// See the [instrumentation libraries] spec for more information.
274+
///
275+
/// [instrumentation libraries]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/overview.md#instrumentation-libraries
268276
#[derive(Debug, Default, Hash, Clone, PartialEq, Eq)]
269277
#[non_exhaustive]
270278
pub struct InstrumentationLibrary {
271-
/// instrumentation library name, cannot be empty
279+
/// The library name.
280+
///
281+
/// This should be the name of the crate providing the instrumentation.
272282
pub name: Cow<'static, str>,
273-
/// instrumentation library version, can be empty
283+
284+
/// The library version.
285+
///
286+
/// # Examples
287+
///
288+
/// ```
289+
/// let library = opentelemetry_api::InstrumentationLibrary::new(
290+
/// "my-crate",
291+
/// Some(env!("CARGO_PKG_VERSION")),
292+
/// None,
293+
/// );
294+
/// ```
274295
pub version: Option<Cow<'static, str>>,
275-
/// [Schema url] of spans and their events.
296+
297+
/// [Schema url] used by this library.
276298
///
277-
/// [Schema url]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/schemas/overview.md#schema-url
299+
/// [Schema url]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/schemas/overview.md#schema-url
278300
pub schema_url: Option<Cow<'static, str>>,
279301
}
280302

281303
impl InstrumentationLibrary {
282-
/// Create an InstrumentationLibrary from name and version.
304+
/// Create an new instrumentation library.
283305
pub fn new<T>(name: T, version: Option<T>, schema_url: Option<T>) -> InstrumentationLibrary
284306
where
285307
T: Into<Cow<'static, str>>,

opentelemetry-api/src/global/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! use opentelemetry_api::global;
2323
//!
2424
//! fn init_tracer() {
25+
//! // Swap this no-op provider for your tracing service of choice (jaeger, zipkin, etc)
2526
//! let provider = NoopTracerProvider::new();
2627
//!
2728
//! // Configure the global `TracerProvider` singleton when your app starts
@@ -39,7 +40,7 @@
3940
//! }
4041
//!
4142
//! // in main or other app start
42-
//! let _ = init_tracer();
43+
//! init_tracer();
4344
//! do_something_tracked();
4445
//! # }
4546
//! ```

opentelemetry-api/src/trace/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@
1111
//!
1212
//! ## Getting Started
1313
//!
14+
//! In application code:
15+
//!
16+
//! ```
17+
//! use opentelemetry_api::trace::{Tracer, noop::NoopTracerProvider};
18+
//! use opentelemetry_api::global;
19+
//!
20+
//! fn init_tracer() {
21+
//! // Swap this no-op provider for your tracing service of choice (jaeger, zipkin, etc)
22+
//! let provider = NoopTracerProvider::new();
23+
//!
24+
//! // Configure the global `TracerProvider` singleton when your app starts
25+
//! // (there is a no-op default if this is not set by your application)
26+
//! let _ = global::set_tracer_provider(provider);
27+
//! }
28+
//!
29+
//! fn do_something_tracked() {
30+
//! // Then you can get a named tracer instance anywhere in your codebase.
31+
//! let tracer = global::tracer("my-component");
32+
//!
33+
//! tracer.in_span("doing_work", |cx| {
34+
//! // Traced app logic here...
35+
//! });
36+
//! }
37+
//!
38+
//! // in main or other app start
39+
//! init_tracer();
40+
//! do_something_tracked();
41+
//! ```
42+
//!
43+
//! In library code:
44+
//!
1445
//! ```
1546
//! use opentelemetry_api::{global, trace::{Span, Tracer, TracerProvider}};
1647
//!

opentelemetry-api/src/trace/tracer.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,25 +373,28 @@ impl SpanBuilder {
373373
}
374374
}
375375

376-
/// The result of sampling logic for a given `Span`.
376+
/// The result of sampling logic for a given span.
377377
#[derive(Clone, Debug, PartialEq)]
378378
pub struct SamplingResult {
379-
/// `SamplingDecision` reached by this result
379+
/// The decision about whether or not to sample.
380380
pub decision: SamplingDecision,
381-
/// Extra attributes added by this result
381+
382+
/// Extra attributes to be added to the span by the sampler
382383
pub attributes: Vec<KeyValue>,
383-
/// Trace state from parent context, might be modified by sampler
384+
385+
/// Trace state from parent context, may be modified by samplers.
384386
pub trace_state: TraceState,
385387
}
386388

387389
/// Decision about whether or not to sample
388390
#[derive(Clone, Debug, PartialEq)]
389391
pub enum SamplingDecision {
390-
/// `is_recording() == false`, span will not be recorded and all events and
391-
/// attributes will be dropped.
392+
/// Span will not be recorded and all events and attributes will be dropped.
392393
Drop,
393-
/// `is_recording() == true`, but `Sampled` flag MUST NOT be set.
394+
395+
/// Span data wil be recorded, but not exported.
394396
RecordOnly,
395-
/// `is_recording() == true` AND `Sampled` flag` MUST be set.
397+
398+
/// Span data will be recorded and exported.
396399
RecordAndSample,
397400
}

0 commit comments

Comments
 (0)