21 releases

0.11.0-alpha.21 Oct 21, 2024
0.11.0-alpha.20 Oct 20, 2024
0.11.0-alpha.17 Sep 20, 2024
0.11.0-alpha.13 Aug 29, 2024
0.11.0-alpha.6 Jun 28, 2024

#26 in #observability

Download history 122/week @ 2024-07-30 119/week @ 2024-08-13 146/week @ 2024-08-20 537/week @ 2024-08-27 59/week @ 2024-09-03 460/week @ 2024-09-10 217/week @ 2024-09-17 25/week @ 2024-09-24 147/week @ 2024-10-01 16/week @ 2024-10-08 416/week @ 2024-10-15 86/week @ 2024-10-22 8/week @ 2024-10-29 11/week @ 2024-11-05

524 downloads per month

MIT/Apache

2.5MB
7.5K SLoC

Rust 5.5K SLoC // 0.2% comments JavaScript 2K SLoC // 0.0% comments

emit_opentelemetry

opentelemetry

Current docs

Integrate emit with the OpenTelemetry SDK.

This library forwards diagnostic events from emit through the OpenTelemetry SDK as log records and spans.


lib.rs:

Integrate emit with the OpenTelemetry SDK.

This library forwards diagnostic events from emit through the OpenTelemetry SDK as log records and spans. This library is for applications that already use the OpenTelemetry SDK. It's also intended for applications that need to unify multiple instrumentation libraries, like emit, log, and tracing, into a shared pipeline. If you'd just like to send emit diagnostics via OTLP to the OpenTelemetry Collector or other compatible service, then consider emit_otlp.

Getting started

Configure the OpenTelemetry SDK as per its documentation, then add emit and emit_opentelemetry to your Cargo.toml:

[dependencies.emit]
version = "0.11.0-alpha.21"

[dependencies.emit_opentelemetry]
version = "0.11.0-alpha.21"

Initialize emit to send diagnostics to the OpenTelemetry SDK using setup:

fn main() {
// Configure the OpenTelemetry SDK
// See the OpenTelemetry SDK docs for details on configuration
let logger_provider = opentelemetry_sdk::logs::LoggerProvider::builder()
.with_simple_exporter(opentelemetry_stdout::LogExporter::default())
.build();

let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder()
.with_simple_exporter(opentelemetry_stdout::SpanExporter::default())
.build();

// Configure `emit` to point to the OpenTelemetry SDK
let rt = emit_opentelemetry::setup(logger_provider, tracer_provider).init();

// Your app code goes here

rt.blocking_flush(std::time::Duration::from_secs(30));

// Shutdown the OpenTelemetry SDK
}

Diagnostic events produced by the [macro@emit::span] macro are sent to an opentelemetry::trace::Tracer as an opentelemetry::trace::Span on completion. All other emitted events are sent to an opentelemetry::logs::Logger as opentelemetry::logs::LogRecords.

Sampling

By default, emit events will be excluded if they are inside an unsampled OpenTelemetry trace, even if that trace is marked as recorded. You can change this behavior by overriding the filter using emit::Setup::emit_when on the value returned by setup.

Limitations

This library doesn't support emit's metrics as OpenTelemetry metrics. Any metric samples produced by emit will be emitted as log records.

Spans produced manually (without adding their trace ids and span ids to the shared emit::Ctxt) will be emitted as log events instead of as spans.

Troubleshooting

If you're not seeing emit diagnostics flow as expected through the OpenTelemetry SDK, you can try configuring emit's internal logger, and collect metrics from the integration:

use emit::metric::Source;

fn main() {
let logger_provider = opentelemetry_sdk::logs::LoggerProvider::builder()
.with_simple_exporter(opentelemetry_stdout::LogExporter::default())
.build();

let tracer_provider = opentelemetry_sdk::trace::TracerProvider::builder()
.with_simple_exporter(opentelemetry_stdout::SpanExporter::default())
.build();

// 1. Initialize the internal logger
//    Diagnostics produced by `emit_opentelemetry` itself will go here
let internal = emit::setup()
.emit_to(emit_term::stdout())
.init_internal();

let mut reporter = emit::metric::Reporter::new();

let rt = emit_opentelemetry::setup(logger_provider, tracer_provider)
.map_emitter(|emitter| {
// 2. Add `emit_opentelemetry`'s metrics to a reporter so we can see what it's up to
//    You can do this independently of the internal emitter
reporter.add_source(emitter.metric_source());

emitter
})
.init();

// Your app code goes here

rt.blocking_flush(std::time::Duration::from_secs(30));

// 3. Report metrics after attempting to flush
//    You could also do this periodically as your application runs
reporter.emit_metrics(&internal.emitter());
}

Also see the opentelemetry docs for any details on getting diagnostics out of it.

Dependencies

~4MB
~86K SLoC