• Stars
    star
    233
  • Rank 172,230 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 1 year ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tracing — Structured, application-level diagnostics

Tracing OpenTelemetry

Utilities for adding OpenTelemetry interoperability to tracing.

Crates.io Documentation Documentation (master) MIT licensed Build Status Discord chat maintenance status

Documentation | Chat

Overview

tracing is a framework for instrumenting Rust programs to collect structured, event-based diagnostic information. This crate provides a subscriber that connects spans from multiple systems into a trace and emits them to OpenTelemetry-compatible distributed tracing systems for processing and visualization.

The crate provides the following types:

Compiler support: requires rustc 1.65+

Examples

Basic Usage

use opentelemetry::trace::TracerProvider as _;
use opentelemetry_sdk::trace::TracerProvider;
use opentelemetry_stdout as stdout;
use tracing::{error, span};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;

fn main() {
    // Create a new OpenTelemetry trace pipeline that prints to stdout
    let provider = TracerProvider::builder()
        .with_simple_exporter(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);

    // Use the tracing subscriber `Registry`, or any other subscriber
    // that impls `LookupSpan`
    let subscriber = Registry::default().with(telemetry);

    // Trace executed code
    tracing::subscriber::with_default(subscriber, || {
        // Spans will be sent to the configured OpenTelemetry exporter
        let root = span!(tracing::Level::TRACE, "app_start", work_units = 2);
        let _enter = root.enter();

        error!("This event will be logged in the root span.");
    });
}

Cargo.toml

[dependencies]
opentelemetry = "0.21"
opentelemetry_sdk = "0.21"
opentelemetry-stdout = { version = "0.2.0", features = ["trace"] }
tracing = "0.1"
tracing-opentelemetry = "0.22"
tracing-subscriber = "0.3"

Visualization example

# Run a supported collector like jaeger in the background
$ docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest

# Run example to produce spans (from parent examples directory)
$ cargo run --example opentelemetry

# View spans (see the image below)
$ firefox http://localhost:16686/

Jaeger UI

Feature Flags

  • metrics: Enables the MetricsLayer type, a layer that exports OpenTelemetry metrics from specifically-named events. This enables the metrics feature flag on the opentelemetry crate.

Supported Rust Versions

Tracing Opentelemetry is built against the latest stable release. The minimum supported version is 1.60. The current Tracing version is not guaranteed to build on Rust versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio project. The current stable Rust compiler and the three most recent minor versions before it will always be supported. For example, if the current stable compiler version is 1.45, the minimum supported version will not be increased past 1.42, three minor versions prior. Increasing the minimum supported compiler version is not considered a semver breaking change as long as doing so complies with this policy.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tracing by you, shall be licensed as MIT, without any additional terms or conditions.

More Repositories

1

tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
Rust
23,031
star
2

axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper
Rust
17,992
star
3

mio

Metal I/O library for Rust.
Rust
6,301
star
4

tracing

Application level tracing for Rust.
Rust
5,365
star
5

mini-redis

Incomplete Redis client and server implementation using Tokio - for learning purposes only
Rust
3,927
star
6

prost

PROST! a Protocol Buffers implementation for the Rust Language
Rust
3,766
star
7

console

a debugger for async rust!
Rust
3,542
star
8

loom

Concurrency permutation testing tool for Rust.
Rust
1,847
star
9

bytes

Utilities for working with bytes
Rust
1,739
star
10

io-uring

The `io_uring` library for Rust
Rust
1,037
star
11

tokio-uring

An io_uring backed runtime for Rust
Rust
946
star
12

turmoil

Add hardship to your tests
Rust
772
star
13

tokio-proto

A network application framework for Rust
Rust
694
star
14

slab

Slab allocator for Rust
Rust
641
star
15

tokio-core

I/O primitives and event loop for async I/O in Rust
Rust
628
star
16

async-stream

Asynchronous streams for Rust using async & await notation
Rust
568
star
17

rdbc

Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers
Rust
558
star
18

tokio-minihttp

Protocol implementation experimentations
Rust
425
star
19

tokio-metrics

Utilities for collecting metrics from a Tokio application
Rust
254
star
20

tls

A collection of Tokio based TLS libraries.
Rust
243
star
21

website

Website for the Tokio project
TypeScript
211
star
22

valuable

Rust
185
star
23

async-backtrace

Rust
162
star
24

tokio-io

Core I/O primitives for asynchronous I/O in Rust.
Rust
124
star
25

tokio-socks5

An example SOCKSv5 server implementation with tokio
Rust
100
star
26

tokio-tls

An implementation of TLS/SSL streams for Tokio
Rust
95
star
27

simulation

Framework for simulating distributed applications
Rust
92
star
28

tokio-timer

Timer facilities for Tokio
Rust
83
star
29

tokio-service

The core `Service` trait in Tokio and support
Rust
81
star
30

tokio-line

Line protocol for Tokio
Rust
64
star
31

tokio-redis

Redis client for Tokio
Rust
58
star
32

tokio-uds

Unix Domain Sockets for tokio
Rust
52
star
33

doc-push

Tokio doc blitz effort - A concerted effort to improve Tokio's documentation.
50
star
34

tokio-compat

Streamline updating a Tokio 0.1 application to Tokio 0.2.
Rust
48
star
35

book

45
star
36

tokio-openssl

OpenSSL bindings for Tokio
Rust
37
star
37

tokio-middleware

A collection of Tokio middleware
Rust
28
star
38

tokio-rfcs

22
star
39

async

Utilities building on top of Rust's async primitives.
Rust
22
star
40

console-gsoc

Google Summer of Code tokio-console prototype
Rust
12
star
41

service-fn

A service implemented by a closure
Rust
11
star
42

gsoc

Organize the Google Summer of Code projects.
6
star
43

cargo-tokio

A cargo subcommand to help building the Tokio project.
Rust
4
star
44

website-next

Next iteration of the Tokio website.
TypeScript
1
star