-
Notifications
You must be signed in to change notification settings - Fork 467
/
Copy pathlogs.rs
75 lines (62 loc) · 1.99 KB
/
logs.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Stress test results:
OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
RAM: 64.0 GB
~31 M/sec
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
~40 M /sec
*/
use opentelemetry::InstrumentationScope;
use opentelemetry_appender_tracing::layer;
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LogResult, LoggerProvider};
use tracing::error;
use tracing_subscriber::prelude::*;
mod throughput;
#[derive(Debug, Clone)]
struct MockLogExporter;
impl LogExporter for MockLogExporter {
fn export(
&self,
_batch: LogBatch<'_>,
) -> impl std::future::Future<Output = LogResult<()>> + Send {
async { Ok(()) }
}
}
#[derive(Debug)]
pub struct MockLogProcessor {
exporter: MockLogExporter,
}
impl LogProcessor for MockLogProcessor {
fn emit(&self, record: &mut opentelemetry_sdk::logs::LogRecord, scope: &InstrumentationScope) {
let log_tuple = &[(record as &LogRecord, scope)];
let _ = futures_executor::block_on(self.exporter.export(LogBatch::new(log_tuple)));
}
fn force_flush(&self) -> LogResult<()> {
Ok(())
}
fn shutdown(&self) -> LogResult<()> {
Ok(())
}
}
fn main() {
// LoggerProvider with a no-op processor.
let provider: LoggerProvider = LoggerProvider::builder()
.with_log_processor(MockLogProcessor {
exporter: MockLogExporter {},
})
.build();
// Use the OpenTelemetryTracingBridge to test the throughput of the appender-tracing.
let layer = layer::OpenTelemetryTracingBridge::new(&provider);
tracing_subscriber::registry().with(layer).init();
throughput::test_throughput(test_log);
}
fn test_log() {
error!(
name = "CheckoutFailed",
book_id = "12345",
book_title = "Rust Programming Adventures",
message = "Unable to process checkout."
);
}