Skip to content

Commit

Permalink
Appender-Tracing benchmark to pass message as attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Aug 8, 2024
1 parent 2409c18 commit 8fd4765
Show file tree
Hide file tree
Showing 3 changed files with 13 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

0 comments on commit 8fd4765

Please sign in to comment.