Skip to content

Commit

Permalink
Merge branch 'main' into utpilla/Add-test-for-observable-gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Aug 9, 2024
2 parents 1b3a020 + fe2fb96 commit b838fed
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
6 changes: 3 additions & 3 deletions opentelemetry-appender-tracing/benches/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| noop_layer_disabled | 12 ns |
| noop_layer_enabled | 25 ns |
| ot_layer_disabled | 19 ns |
| ot_layer_enabled | 280 ns |
| ot_layer_enabled | 250 ns |
*/

use async_trait::async_trait;
Expand Down Expand Up @@ -116,7 +116,7 @@ fn benchmark_no_subscriber(c: &mut Criterion) {
name = "CheckoutFailed",
book_id = "12345",
book_title = "Rust Programming Adventures",
"Unable to process checkout."
message = "Unable to process checkout."
);
});
});
Expand All @@ -142,7 +142,7 @@ fn benchmark_with_ot_layer(c: &mut Criterion, enabled: bool, bench_name: &str) {
name = "CheckoutFailed",
book_id = "12345",
book_title = "Rust Programming Adventures",
"Unable to process checkout."
message = "Unable to process checkout."
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-appender-tracing/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fn main() {
let layer = layer::OpenTelemetryTracingBridge::new(&provider);
tracing_subscriber::registry().with(layer).init();

error!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]");
error!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]", message = "This is an example message");
let _ = provider.shutdown();
}
10 changes: 9 additions & 1 deletion opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ impl<'a, LR: LogRecord> tracing::field::Visit for EventVisitor<'a, LR> {
if is_duplicated_metadata(field.name()) {
return;
}
//TODO: Consider special casing "message" to populate body and document
// to users to use message field for log message, to avoid going to the
// record_debug, which has dyn dispatch, string allocation and
// formatting cost.

//TODO: Fix heap allocation. Check if lifetime of &str can be used
// to optimize sync exporter scenario.
self.log_record
.add_attribute(Key::new(field.name()), AnyValue::from(value.to_owned()));
}
Expand Down Expand Up @@ -163,8 +170,9 @@ where
#[cfg(not(feature = "experimental_metadata_attributes"))]
let meta = event.metadata();

//let mut log_record: LogRecord = LogRecord::default();
let mut log_record = self.logger.create_log_record();

// TODO: Fix heap allocation
log_record.set_target(meta.target().to_string());
log_record.set_event_name(meta.name());
log_record.set_severity_number(severity_of_level(meta.level()));
Expand Down
28 changes: 28 additions & 0 deletions opentelemetry-sdk/benches/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RAM: 64.0 GB
|--------------------------------|-------------|
| Logger_Creation | 30 ns |
| LoggerProvider_Creation | 909 ns |
| Logging_Comparable_To_Appender | 135 ns |
*/

use std::collections::HashMap;
Expand Down Expand Up @@ -114,9 +115,36 @@ fn logger_creation(c: &mut Criterion) {
});
}

fn logging_comparable_to_appender(c: &mut Criterion) {
let provider = LoggerProvider::builder()
.with_log_processor(NoopProcessor {})
.build();
let logger = provider.logger("benchmark");

// This mimics the logic from opentelemetry-tracing-appender closely, but
// without the overhead of the tracing layer itself.
c.bench_function("Logging_Comparable_To_Appender", |b| {
b.iter(|| {
let mut log_record = logger.create_log_record();
let now = SystemTime::now();
log_record.set_observed_timestamp(now);
log_record.set_target("my-target".to_string());
log_record.set_event_name("CheckoutFailed");
log_record.set_severity_number(Severity::Warn);
log_record.set_severity_text("WARN".into());
log_record.add_attribute("book_id", "12345");
log_record.add_attribute("book_title", "Rust Programming Adventures");
log_record.add_attribute("message", "Unable to process checkout.");

logger.emit(log_record);
});
});
}

fn criterion_benchmark(c: &mut Criterion) {
logger_creation(c);
log_provider_creation(c);
logging_comparable_to_appender(c);
log_benchmark_group(c, "simple-log", |logger| {
let mut log_record = logger.create_log_record();
log_record.set_body("simple log".into());
Expand Down

0 comments on commit b838fed

Please sign in to comment.