Giter VIP home page Giter VIP logo

opentelemetry-rust's Introduction

OpenTelemetry Rust

The Rust OpenTelemetry implementation.

Crates.io: opentelemetry Documentation LICENSE GitHub Actions CI codecov Slack

Overview

OpenTelemetry is a collection of tools, APIs, and SDKs used to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior. You can export and analyze them using Prometheus, Jaeger, and other observability tools.

Compiler support: requires rustc 1.65+

Project Status

Signal/Component Overall Status
Logs-API Alpha*
Logs-SDK Alpha
Logs-OTLP Exporter Alpha
Logs-Appender-Tracing Alpha
Metrics-API Alpha
Metrics-SDK Alpha
Metrics-OTLP Exporter Alpha
Traces-API Beta
Traces-SDK Beta
Traces-OTLP Exporter Beta

*OpenTelemetry Rust is not introducing a new end user callable Logging API. Instead, it provides Logs Bridge API, that allows one to write log appenders that can bridge existing logging libraries to the OpenTelemetry log data model. The following log appenders are available:

If you already use the logging APIs from above, continue to use them, and use the appenders above to bridge the logs to OpenTelemetry. If you are using a library not listed here, feel free to contribute a new appender for the same.

If you are starting fresh, then consider using tracing as your logging API. It supports structured logging and is actively maintained.

Project versioning information and stability guarantees can be found here.

Getting Started

use opentelemetry::{
    global,
    trace::{Tracer, TracerProvider as _},
};
use opentelemetry_sdk::trace::TracerProvider;

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

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    // Shutdown trace pipeline
    global::shutdown_tracer_provider();
}

The example above requires the following packages:

# Cargo.toml
[dependencies]
opentelemetry = "0.22"
opentelemetry_sdk = "0.22"
opentelemetry-stdout = { version = "0.3", features = ["trace"] }

See the examples directory for different integration patterns.

Overview of crates

The following crates are maintained in this repo:

In addition, there are several other useful crates in the OTel Rust Contrib repo. A lot of crates maintained outside OpenTelemetry owned repos can be found in the OpenTelemetry Registry.

Supported Rust Versions

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

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.49, the minimum supported version will not be increased past 1.46, 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.

Contributing

See the contributing file.

The Rust special interest group (SIG) meets weekly on Tuesdays at 9 AM Pacific Time. The meeting is subject to change depending on contributors' availability. Check the OpenTelemetry community calendar for specific dates and for Zoom meeting links. "OTel Rust SIG" is the name of meeting for this group.

Meeting notes are available as a public Google doc. If you have trouble accessing the doc, please get in touch on Slack.

The meeting is open for all to join. We invite everyone to join our meeting, regardless of your experience level. Whether you're a seasoned OpenTelemetry developer, just starting your journey, or simply curious about the work we do, you're more than welcome to participate!

Approvers and Maintainers

For GitHub groups see the code owners file.

Maintainers

Approvers

Emeritus

Thanks to all the people who have contributed

contributors

opentelemetry-rust's People

Contributors

bryncooke avatar cijothomas avatar cosminlazar avatar dependabot[bot] avatar djc avatar drexler avatar frigus02 avatar fsmaxb avatar hdost avatar jtescher avatar kalldrexx avatar kichristensen avatar lalitb avatar lzchen avatar markdingram avatar mattbodd avatar morigs avatar ozerovandrei avatar realtimetodie avatar rockin2 avatar shaun-cox avatar sreeo avatar tensorchen avatar tommycpp avatar utpilla avatar valkum avatar vibhavp avatar wperron avatar ymgyt avatar zengxilong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opentelemetry-rust's Issues

Beta readiness tracker

This is a tracking issue for the requirements outlined in the beta release document: https://docs.google.com/document/d/1eviggoIguOS89dgKL-8ntUOCfPP6FLWAoQkGoBDsld0/edit#

Traces

  • Stable API of every spec'd feature
  • SDK Implementation of every spec'd feature
  • Basic tracing
  • Named tracers
  • Tracers use OTEP 66 Context mechanism - This is an implementation detail and does not affect the API

Metrics

Resources

  • Stable API of every spec'd feature #789
  • SDK Implementation of every spec'd feature

Context Propagation

  • Stable API of every spec'd feature #741
  • Basic context mechanism #769
  • Global Propagators API #777 #797
  • Global Context API (get and set active context) #792
  • SDK Implementation of every spec'd feature
  • Basic context mechanism #769
  • Global Propagators #777

Exporters

  • OpenTelemetry Native - Collector Exporter
  • gRPC support
  • Prometheus
  • Jaeger
  • Zipkin

Integrations

  • HTTP
  • gRPC
  • SQL

Examples

  • Manual tracing hello world example
  • HTTP client/server using an instrumented framework
  • gRPC client/server

Update Cargo.toml authors?

@jtescher thoughts on updating the authors to point to something generic, like "OpenTelemetry authors"? Not sure if there's a corresponding email.

Add macros!

This might take some experimentation to get right ergonomically.

Span lifetime / active span state

Currently spans are stored in a thread local span stack, and either manually added and removed via mark_span_as_active / mark_span_as_inactive or for the scope of a given closure by using with_span.

This has certain drawbacks: spans marked as active and not later marked as inactive will not be dropped, marking as inactive is unexpected as it is not part of the spec, etc.

We should investigate if there are more reliable / intuitive / ergonomic ways of coordinating active span information between components. E.g. web framework middleware needing to set the active span for use later in the application.

Trace id not exported correctly on links when using jaeger

Jaeger exporter serialises the trace id in 2 64bit chunks. Unfortunately when exporting links the high and low chunks are in reverse order so downstream systems receiving the events cannot construct correct links to the correlated traces.

#117 fixes this.

Opentelemetry-jaeger: Problems using Collector Client in conjunection with Actix-Web

This is an amazing project and I am attempting to use it in conjunction with the tracing crate. I have posted my initialization code below. I am getting traces to my collector for things that are running in tokio outside of Actix but the actix-web handlers don't work. My best guess after digging through the code is the problem is due to the use of the blocking reqwest client. For reference this is how I am instrumenting my actix-web handlers

#[tracing::instrument(skip(app))]
#[get("/health")]
pub async fn health(app: Data<Application>) -> Result<HttpResponse, ApplicationError> {
thread 'tokio-runtime-worker' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.', /home/glade/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.20/src/runtime/enter.rs:38:5
use opentelemetry::{global, sdk, api::Provider};
use tracing_subscriber::layer::SubscriberExt;
use tracing_opentelemetry::OpenTelemetryLayer;

pub fn init_tracer(collector_endpoint: &str, collector_username: &str, collector_password: &str) -> std::io::Result<()> {
    let exporter: opentelemetry_jaeger::Exporter = opentelemetry_jaeger::Exporter::builder()
        .with_collector_endpoint(collector_endpoint)
        .with_collector_username(collector_username)
        .with_collector_password(collector_password)
        .with_process(opentelemetry_jaeger::Process {
            service_name: "service".to_string(),
            tags: vec![opentelemetry::api::core::KeyValue::new("environment", "dev")],
        })
        .init()
        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;

    let provider = sdk::Provider::builder()
        .with_simple_exporter(exporter)
        .with_config(sdk::Config {
            default_sampler: Box::new(sdk::Sampler::Always),
            ..Default::default()
        })
        .build();


    global::set_provider(provider);
    let tracer = global::trace_provider().get_tracer("service");
    let telemetry = OpenTelemetryLayer::with_tracer(tracer);
    let subscriber = tracing_subscriber::Registry::default().with(telemetry);

    tracing::subscriber::set_global_default(subscriber).expect("Could not set global subscriber");

    tracing::trace_span!("tracing_startup");

    Ok(())
}

Add api::context::propagation::Carrier implementation for http::header::HeaderMap

Hey, I'm loving the direction this is going, I think it's really going to help me with my microservices backend written in tonic. I've already got my individual services reporting to Jaeger, now I'm trying to get context propagation working. tonic exposes a trace_fn that gives you a http::header::HeaderMap. I'm trying to use a B3Propagator to extract the context from the HeaderMap, but Carrier is only implemented for HashMap with &'static str as the key.
Could you make an implementation of Carrier for http::header::HeaderMap please? Because of Rust's rules around implementations, I can't make an implementation of a foreign trait on a foreign type.
Also in general, it seems like Carrier shouldn't be using &'static str, but should instead just be using &str. I can take a stab at a pull request if you like.

Swap out rustracing_jaeger for jaeger exporter

Currently the span exporter infrastructure is bypassed because of rustracing_jaeger's implementation which reports spans on drop by sending them over a crossbeam-channel.

We should consider switching to use the thrift crate directly and generate a client as that would provide the majority of the implementation that the exporter requires. This could look very similar to the go jaeger exporter implementation.

This could be a separate crate as suggested in #4.

Metric option configuration

Current MetricOptions implementation does not work for with_monotonic. The issue is the options do not know which instrument they are being created for.

We could consider moving to returning builders instead of accepting all options here?

Expose async exporter interface

Currently batch exporters must go through a blocking interface, they should be able to export spans using entirely async interfaces.

Add initial set of benchmarks

It would be great to have a set of benchmarks that we can reference as we make changes so we are aware of performance advancements and regressions.

Sampler::Probability will never sample orphaned spans

According to the documentation of the Probability variant of opentelemetry::sdk::trace::sampler::Sampler,

Fractions >= 1 will always sample. If the parent span is sampled, then it's child spans will automatically be sampled.

This implies that a span may be sampled if its parent is not sampled, if a probability condition is met. Here is a link to the referenced documentation in the code:

/// Sample a given fraction of traces. Fractions >= 1 will always sample.
/// If the parent span is sampled, then it's child spans will automatically
/// be sampled. Fractions <0 are treated as zero, but spans may still be
/// sampled if their parent is.
Probability(f64),

In practice however, using the probability variant of Sampler will not sample any spans. Due to the implementation of should_sample which conflicts with the above documentation:

if parent_context.map(|ctx| ctx.is_sampled()).unwrap_or(false) && *prob > 0.0 {
if *prob > 1.0 || *prob > rand::random() {

The implementation here first checks to see if the parent span was sampled, and only if it was, performs the probability check to see if the current span will be sampled. This does not match with the documentation shown above. If this behavior is intentional, the documentation should call out that the probability will only be tested, and spans will only be sampled if their parent span was sampled. I would expect the implementation to look more like this if the documentation is correct:

 if  *prob > 0.0 { 
     if *prob > 1.0 || parent_context.map(|ctx| ctx.is_sampled()).unwrap_or(false) || *prob > rand::random() { 
        // Mark span as sampled

Store span kind

Currently span kind can only be assigned by setting the span.kind attribute. Span kind should be explicitly assignable when creating spans.

Configure CI

Note that we'll need an admin to configure the repo for this, e.g., to require that PRs pass checks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.