Skip to content

Commit

Permalink
docs: update README basic example (tokio-rs#47)
Browse files Browse the repository at this point in the history
## Motivation

Address tokio-rs#46

## Solution

Update example to use opentelemetry-stdout with Cargo.toml options
  • Loading branch information
ymgyt authored Aug 9, 2023
1 parent 7bb3e56 commit 42a3c73
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ The crate provides the following types:
### Basic Usage

```rust
use opentelemetry::sdk::export::trace::stdout;
use opentelemetry::sdk::trace::TracerProvider;
use opentelemetry::trace::TracerProvider as _;
use tracing::{error, span};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;

fn main() {
// Install a new OpenTelemetry trace pipeline
let tracer = stdout::new_pipeline().install_simple();
// Create a new OpenTelemetry trace pipeline that prints to stdout
let provider = TracerProvider::builder()
.with_simple_exporter(opentelemetry_stdout::SpanExporter::default())
.build();
let tracer = provider.tracer("readme_example");

// Create a tracing layer with the configured tracer
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
Expand All @@ -86,6 +90,16 @@ fn main() {
}
```

`Cargo.toml`
```toml
[dependencies]
opentelemetry = "0.20"
opentelemetry-stdout = { version = "0.1.0", features = ["trace"] }
tracing = "0.1"
tracing-opentelemetry = "0.20"
tracing-subscriber = "0.3"
```

### Visualization example

```console
Expand Down

0 comments on commit 42a3c73

Please sign in to comment.