Skip to content

Commit 73e86d7

Browse files
committed
docs: improve / fix documentation
Particularly improves tracing-honeycomb's docs & readme. Puts more of the doc examples in rustdoc so they can be automatically tested.
1 parent 27cda1e commit 73e86d7

File tree

4 files changed

+105
-85
lines changed

4 files changed

+105
-85
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
# tracing-honeycomb
44

55
This repo contains the source code for:
6-
- [`tracing-distributed`](tracing-distributed/README.md), which contains generic machinery for publishing distributed trace telemetry to arbitrary backends
7-
- [`tracing-honeycomb`](tracing-honeycomb/README.md), which contains a concrete implementation that uses [honeycomb.io](https://honeycomb.io) as a backend
6+
- [`tracing-distributed`](tracing-distributed/README.md), which contains generic machinery for publishing distributed trace telemetry to arbitrary backends.
7+
- [`tracing-honeycomb`](tracing-honeycomb/README.md), which contains a concrete implementation that uses [honeycomb.io](https://honeycomb.io) as a backend.
8+
- [`tracing-honeycomb`](tracing-jaeger/README.md), which contains a concrete implementation that uses [jaegertraing.io](https://www.jaegertracing.io/) as a backend.
89

910
## Usage
1011

tracing-honeycomb/README.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
# tracing-honeycomb
44

5-
This crate provides:
6-
- A tracing layer, `TelemetryLayer`, that can be used to publish trace data to honeycomb.io
7-
- Utilities for implementing distributed tracing against the honeycomb.io backend
8-
9-
As a tracing layer, `TelemetryLayer` can be composed with other layers to provide stdout logging, filtering, etc.
10-
115
## Usage
126

13-
Add the following to your Cargo.toml to get started.
7+
Add the following to your `Cargo.toml` to get started.
148

159
```toml
16-
tracing-honeycomb = "0.1.0"
10+
tracing-honeycomb = "0.2.0"
1711
```
1812

19-
### Propagating distributed tracing metadata
13+
This crate provides:
14+
- A tracing layer, `TelemetryLayer`, that can be used to publish trace data to [honeycomb.io][].
15+
- Utilities for implementing distributed tracing against the honeycomb.io backend.
16+
17+
As a tracing layer, `TelemetryLayer` can be composed with other layers to provide stdout logging, filtering, etc.
18+
19+
#### Propagating distributed tracing metadata
2020

2121
This crate provides two functions for out of band interaction with the `TelemetryLayer`
2222
- `register_dist_tracing_root` registers the current span as the local root of a distributed trace.
@@ -27,48 +27,57 @@ Here's an example of how they might be used together:
2727
2. A child of that span uses `current_dist_trace_ctx` to fetch the current `TraceId` and `SpanId`. It passes these values along with an RPC request, as metadata.
2828
3. The RPC service handler uses the `TraceId` and remote parent `SpanId` provided in the request's metadata to register the handler function's span as a local root of the distributed trace initiated in step 1.
2929

30-
### Registering a global Subscriber
30+
#### Registering a global Subscriber
3131

3232
The following example shows how to create and register a subscriber created by composing `TelemetryLayer` with other layers and the `Registry` subscriber provided by the `tracing_subscriber` crate.
3333

3434
```rust
35+
use tracing_honeycomb::new_honeycomb_telemetry_layer;
36+
use tracing_subscriber::prelude::*;
37+
use tracing_subscriber::{filter::LevelFilter, fmt, registry::Registry};
38+
3539
let honeycomb_config = libhoney::Config {
3640
options: libhoney::client::Options {
37-
api_key: honeycomb_key,
41+
api_key: std::env::var("HONEYCOMB_WRITEKEY").unwrap(),
3842
dataset: "my-dataset-name".to_string(),
3943
..libhoney::client::Options::default()
4044
},
4145
transmission_options: libhoney::transmission::Options::default(),
4246
};
4347

44-
let telemetry_layer = mk_honeycomb_tracing_layer("my-service-name", honeycomb_config);
48+
let telemetry_layer = new_honeycomb_telemetry_layer("my-service-name", honeycomb_config);
4549

4650
// NOTE: the underlying subscriber MUST be the Registry subscriber
47-
let subscriber = registry::Registry::default() // provide underlying span data store
51+
let subscriber = Registry::default() // provide underlying span data store
4852
.with(LevelFilter::INFO) // filter out low-level debug tracing (eg tokio executor)
49-
.with(tracing_subscriber::fmt::Layer::default()) // log to stdout
53+
.with(fmt::Layer::default()) // log to stdout
5054
.with(telemetry_layer); // publish to honeycomb backend
5155

52-
5356
tracing::subscriber::set_global_default(subscriber).expect("setting global default failed");
5457
```
5558

56-
### Testing
59+
#### Testing
5760

5861
Since `TraceCtx::current_trace_ctx` and `TraceCtx::record_on_current_span` can be expected to return `Ok` as long as some `TelemetryLayer` has been registered as part of the layer/subscriber stack and the current span is active, it's valid to `.expect` them to always succeed & to panic if they do not. As a result, you may find yourself writing code that fails if no distributed tracing context is present. This means that unit and integration tests covering such code must provide a `TelemetryLayer`. However, you probably don't want to publish telemetry while running unit or integration tests. You can fix this problem by registering a `TelemetryLayer` constructed using `BlackholeTelemetry`. `BlackholeTelemetry` discards spans and events without publishing them to any backend.
5962

6063
```rust
61-
let telemetry_layer = mk_honeycomb_blackhole_tracing_layer();
64+
use tracing_honeycomb::new_blackhole_telemetry_layer;
65+
use tracing_subscriber::prelude::*;
66+
use tracing_subscriber::{filter::LevelFilter, fmt, registry::Registry};
67+
68+
let telemetry_layer = new_blackhole_telemetry_layer();
6269

6370
// NOTE: the underlying subscriber MUST be the Registry subscriber
64-
let subscriber = registry::Registry::default() // provide underlying span data store
71+
let subscriber = Registry::default() // provide underlying span data store
6572
.with(LevelFilter::INFO) // filter out low-level debug tracing (eg tokio executor)
66-
.with(tracing_subscriber::fmt::Layer::default()) // log to stdout
73+
.with(fmt::Layer::default()) // log to stdout
6774
.with(telemetry_layer); // publish to blackhole backend
6875

69-
tracing::subscriber::set_global_default(subscriber).expect("setting global default failed");
76+
tracing::subscriber::set_global_default(subscriber).ok();
7077
```
7178

79+
[honeycomb.io]: https://www.honeycomb.io/
80+
7281
## License
7382

7483
MIT

tracing-honeycomb/README.tpl

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,15 @@
22

33
# {{crate}}
44

5-
{{readme}}
6-
75
## Usage
86

9-
Add the following to your Cargo.toml to get started.
7+
Add the following to your `Cargo.toml` to get started.
108

119
```toml
1210
tracing-honeycomb = "{{version}}"
1311
```
1412

15-
### Propagating distributed tracing metadata
16-
17-
This crate provides two functions for out of band interaction with the `TelemetryLayer`
18-
- `register_dist_tracing_root` registers the current span as the local root of a distributed trace.
19-
- `current_dist_trace_ctx` fetches the `TraceId` and `SpanId` associated with the current span.
20-
21-
Here's an example of how they might be used together:
22-
1. Some span is registered as the global tracing root using a newly-generated `TraceId`.
23-
2. A child of that span uses `current_dist_trace_ctx` to fetch the current `TraceId` and `SpanId`. It passes these values along with an RPC request, as metadata.
24-
3. The RPC service handler uses the `TraceId` and remote parent `SpanId` provided in the request's metadata to register the handler function's span as a local root of the distributed trace initiated in step 1.
25-
26-
### Registering a global Subscriber
27-
28-
The following example shows how to create and register a subscriber created by composing `TelemetryLayer` with other layers and the `Registry` subscriber provided by the `tracing_subscriber` crate.
29-
30-
```rust
31-
let honeycomb_config = libhoney::Config {
32-
options: libhoney::client::Options {
33-
api_key: honeycomb_key,
34-
dataset: "my-dataset-name".to_string(),
35-
..libhoney::client::Options::default()
36-
},
37-
transmission_options: libhoney::transmission::Options::default(),
38-
};
39-
40-
let telemetry_layer = mk_honeycomb_tracing_layer("my-service-name", honeycomb_config);
41-
42-
// NOTE: the underlying subscriber MUST be the Registry subscriber
43-
let subscriber = registry::Registry::default() // provide underlying span data store
44-
.with(LevelFilter::INFO) // filter out low-level debug tracing (eg tokio executor)
45-
.with(tracing_subscriber::fmt::Layer::default()) // log to stdout
46-
.with(telemetry_layer); // publish to honeycomb backend
47-
48-
49-
tracing::subscriber::set_global_default(subscriber).expect("setting global default failed");
50-
```
51-
52-
### Testing
53-
54-
Since `TraceCtx::current_trace_ctx` and `TraceCtx::record_on_current_span` can be expected to return `Ok` as long as some `TelemetryLayer` has been registered as part of the layer/subscriber stack and the current span is active, it's valid to `.expect` them to always succeed & to panic if they do not. As a result, you may find yourself writing code that fails if no distributed tracing context is present. This means that unit and integration tests covering such code must provide a `TelemetryLayer`. However, you probably don't want to publish telemetry while running unit or integration tests. You can fix this problem by registering a `TelemetryLayer` constructed using `BlackholeTelemetry`. `BlackholeTelemetry` discards spans and events without publishing them to any backend.
55-
56-
```rust
57-
let telemetry_layer = mk_honeycomb_blackhole_tracing_layer();
58-
59-
// NOTE: the underlying subscriber MUST be the Registry subscriber
60-
let subscriber = registry::Registry::default() // provide underlying span data store
61-
.with(LevelFilter::INFO) // filter out low-level debug tracing (eg tokio executor)
62-
.with(tracing_subscriber::fmt::Layer::default()) // log to stdout
63-
.with(telemetry_layer); // publish to blackhole backend
64-
65-
tracing::subscriber::set_global_default(subscriber).expect("setting global default failed");
66-
```
13+
{{readme}}
6714

6815
## License
6916

tracing-honeycomb/src/lib.rs

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,73 @@
66
)]
77

88
//! This crate provides:
9-
//! - A tracing layer, `TelemetryLayer`, that can be used to publish trace data to honeycomb.io
10-
//! - Utilities for implementing distributed tracing against the honeycomb.io backend
9+
//! - A tracing layer, `TelemetryLayer`, that can be used to publish trace data to [honeycomb.io][].
10+
//! - Utilities for implementing distributed tracing against the honeycomb.io backend.
1111
//!
1212
//! As a tracing layer, `TelemetryLayer` can be composed with other layers to provide stdout logging, filtering, etc.
13+
//!
14+
//! ### Propagating distributed tracing metadata
15+
//!
16+
//! This crate provides two functions for out of band interaction with the `TelemetryLayer`
17+
//! - `register_dist_tracing_root` registers the current span as the local root of a distributed trace.
18+
//! - `current_dist_trace_ctx` fetches the `TraceId` and `SpanId` associated with the current span.
19+
//!
20+
//! Here's an example of how they might be used together:
21+
//! 1. Some span is registered as the global tracing root using a newly-generated `TraceId`.
22+
//! 2. A child of that span uses `current_dist_trace_ctx` to fetch the current `TraceId` and `SpanId`. It passes these values along with an RPC request, as metadata.
23+
//! 3. The RPC service handler uses the `TraceId` and remote parent `SpanId` provided in the request's metadata to register the handler function's span as a local root of the distributed trace initiated in step 1.
24+
//!
25+
//! ### Registering a global Subscriber
26+
//!
27+
//! The following example shows how to create and register a subscriber created by composing `TelemetryLayer` with other layers and the `Registry` subscriber provided by the `tracing_subscriber` crate.
28+
//!
29+
//! ```no_run
30+
//! use tracing_honeycomb::new_honeycomb_telemetry_layer;
31+
//! use tracing_subscriber::prelude::*;
32+
//! use tracing_subscriber::{filter::LevelFilter, fmt, registry::Registry};
33+
//!
34+
//! let honeycomb_config = libhoney::Config {
35+
//! options: libhoney::client::Options {
36+
//! api_key: std::env::var("HONEYCOMB_WRITEKEY").unwrap(),
37+
//! dataset: "my-dataset-name".to_string(),
38+
//! ..libhoney::client::Options::default()
39+
//! },
40+
//! transmission_options: libhoney::transmission::Options::default(),
41+
//! };
42+
//!
43+
//! let telemetry_layer = new_honeycomb_telemetry_layer("my-service-name", honeycomb_config);
44+
//!
45+
//! // NOTE: the underlying subscriber MUST be the Registry subscriber
46+
//! let subscriber = Registry::default() // provide underlying span data store
47+
//! .with(LevelFilter::INFO) // filter out low-level debug tracing (eg tokio executor)
48+
//! .with(fmt::Layer::default()) // log to stdout
49+
//! .with(telemetry_layer); // publish to honeycomb backend
50+
//!
51+
//! tracing::subscriber::set_global_default(subscriber).expect("setting global default failed");
52+
//! ```
53+
//!
54+
//! ### Testing
55+
//!
56+
//! Since `TraceCtx::current_trace_ctx` and `TraceCtx::record_on_current_span` can be expected to return `Ok` as long as some `TelemetryLayer` has been registered as part of the layer/subscriber stack and the current span is active, it's valid to `.expect` them to always succeed & to panic if they do not. As a result, you may find yourself writing code that fails if no distributed tracing context is present. This means that unit and integration tests covering such code must provide a `TelemetryLayer`. However, you probably don't want to publish telemetry while running unit or integration tests. You can fix this problem by registering a `TelemetryLayer` constructed using `BlackholeTelemetry`. `BlackholeTelemetry` discards spans and events without publishing them to any backend.
57+
//!
58+
//! ```
59+
//! use tracing_honeycomb::new_blackhole_telemetry_layer;
60+
//! use tracing_subscriber::prelude::*;
61+
//! use tracing_subscriber::{filter::LevelFilter, fmt, registry::Registry};
62+
//!
63+
//! let telemetry_layer = new_blackhole_telemetry_layer();
64+
//!
65+
//! // NOTE: the underlying subscriber MUST be the Registry subscriber
66+
//! let subscriber = Registry::default() // provide underlying span data store
67+
//! .with(LevelFilter::INFO) // filter out low-level debug tracing (eg tokio executor)
68+
//! .with(fmt::Layer::default()) // log to stdout
69+
//! .with(telemetry_layer); // publish to blackhole backend
70+
//!
71+
//! tracing::subscriber::set_global_default(subscriber).ok();
72+
//! ```
73+
//!
74+
//! [honeycomb.io]: https://www.honeycomb.io/
75+
1376

1477
mod honeycomb;
1578
mod visitor;
@@ -22,7 +85,7 @@ pub use tracing_distributed::{TelemetryLayer, TraceCtxError};
2285

2386
/// Register the current span as the local root of a distributed trace.
2487
///
25-
/// Specialized to the honeycomb.io-specific SpanId and TraceId provided by this crate.
88+
/// Specialized to the honeycomb.io-specific `SpanId` and `TraceId` provided by this crate.
2689
pub fn register_dist_tracing_root(
2790
trace_id: TraceId,
2891
remote_parent_span: Option<SpanId>,
@@ -35,14 +98,14 @@ pub fn register_dist_tracing_root(
3598
/// Returns the `TraceId`, if any, that the current span is associated with along with
3699
/// the `SpanId` belonging to the current span.
37100
///
38-
/// Specialized to the honeycomb.io-specific SpanId and TraceId provided by this crate.
101+
/// Specialized to the honeycomb.io-specific `SpanId` and `TraceId` provided by this crate.
39102
pub fn current_dist_trace_ctx() -> Result<(TraceId, SpanId), TraceCtxError> {
40103
tracing_distributed::current_dist_trace_ctx()
41104
}
42105

43-
/// Construct a TelemetryLayer that does not publish telemetry to any backend.
106+
/// Construct a `TelemetryLayer` that does not publish telemetry to any backend.
44107
///
45-
/// Specialized to the honeycomb.io-specific SpanId and TraceId provided by this crate.
108+
/// Specialized to the honeycomb.io-specific `SpanId` and `TraceId` provided by this crate.
46109
pub fn new_blackhole_telemetry_layer(
47110
) -> TelemetryLayer<tracing_distributed::BlackholeTelemetry<SpanId, TraceId>, SpanId, TraceId> {
48111
let instance_id: u64 = 0;
@@ -56,9 +119,9 @@ pub fn new_blackhole_telemetry_layer(
56119
)
57120
}
58121

59-
/// Construct a TelemetryLayer that publishes telemetry to honeycomb.io using the provided honeycomb config.
122+
/// Construct a `TelemetryLayer` that publishes telemetry to honeycomb.io using the provided honeycomb config.
60123
///
61-
/// Specialized to the honeycomb.io-specific SpanId and TraceId provided by this crate.
124+
/// Specialized to the honeycomb.io-specific `SpanId` and `TraceId` provided by this crate.
62125
pub fn new_honeycomb_telemetry_layer(
63126
service_name: &'static str,
64127
honeycomb_config: libhoney::Config,

0 commit comments

Comments
 (0)