Skip to content

Commit

Permalink
Add new benches for logs (#1450)
Browse files Browse the repository at this point in the history
Implement new bench ideas from this
[PR](#1431
comments.

Please provide a brief description of the changes here.

## Merge requirement checklist

* [ ]
[CONTRIBUTING](https://github.com/open-telemetry/opentelemetry-rust/blob/main/CONTRIBUTING.md)
guidelines followed
* [ ] Unit tests added/updated (if applicable)
* [ ] Appropriate `CHANGELOG.md` files updated for non-trivial,
user-facing changes
* [ ] Changes in public API reviewed (if applicable)

Co-authored-by: Lalit Kumar Bhasin <lalit_fin@yahoo.com>
  • Loading branch information
Rockin2 and lalitb committed Jan 8, 2024
1 parent 306286e commit 27d338d
Showing 1 changed file with 163 additions and 5 deletions.
168 changes: 163 additions & 5 deletions opentelemetry-sdk/benches/log.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::collections::HashMap;
use std::time::SystemTime;

use async_trait::async_trait;
use criterion::{criterion_group, criterion_main, Criterion};

use opentelemetry::logs::{LogRecord, LogResult, Logger, LoggerProvider as _, Severity};
use opentelemetry::logs::{AnyValue, LogRecord, LogResult, Logger, LoggerProvider as _, Severity};
use opentelemetry::trace::Tracer;
use opentelemetry::trace::TracerProvider as _;
use opentelemetry::Key;
use opentelemetry_sdk::export::logs::{LogData, LogExporter};
use opentelemetry_sdk::logs::LoggerProvider;
use opentelemetry_sdk::trace::{config, Sampler, TracerProvider};
Expand Down Expand Up @@ -60,6 +62,129 @@ fn criterion_benchmark(c: &mut Criterion) {
logger.emit(LogRecord::builder().with_body("simple log").build())
});

log_benchmark_group(c, "simple-log-with-int", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testint", 2)
.build(),
)
});

log_benchmark_group(c, "simple-log-with-double", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testdouble", 2.2)
.build(),
)
});

log_benchmark_group(c, "simple-log-with-string", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("teststring", "test")
.build(),
)
});

log_benchmark_group(c, "simple-log-with-bool", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testbool", AnyValue::Boolean(true))
.build(),
)
});

let bytes = AnyValue::Bytes(vec![25u8, 30u8, 40u8]);
log_benchmark_group(c, "simple-log-with-bytes", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testbytes", bytes.clone())
.build(),
)
});

let bytes = AnyValue::Bytes(vec![
25u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8,
40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8,
40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
]);
log_benchmark_group(c, "simple-log-with-a-lot-of-bytes", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testbytes", bytes.clone())
.build(),
)
});

let vec_any_values = AnyValue::ListAny(vec![AnyValue::Int(25), "test".into(), true.into()]);
log_benchmark_group(c, "simple-log-with-vec-any-value", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testvec", vec_any_values.clone())
.build(),
)
});

let vec_any_values = AnyValue::ListAny(vec![AnyValue::Int(25), "test".into(), true.into()]);
let vec_any_values = AnyValue::ListAny(vec![
AnyValue::Int(25),
"test".into(),
true.into(),
vec_any_values,
]);
log_benchmark_group(c, "simple-log-with-inner-vec-any-value", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testvec", vec_any_values.clone())
.build(),
)
});

let map_any_values = AnyValue::Map(HashMap::from([
("testint".into(), 2.into()),
("testdouble".into(), 2.2.into()),
("teststring".into(), "test".into()),
]));
log_benchmark_group(c, "simple-log-with-map-any-value", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testmap", map_any_values.clone())
.build(),
)
});

let map_any_values = AnyValue::Map(HashMap::from([
("testint".into(), 2.into()),
("testdouble".into(), 2.2.into()),
("teststring".into(), "test".into()),
]));
let map_any_values = AnyValue::Map(HashMap::from([
("testint".into(), 2.into()),
("testdouble".into(), 2.2.into()),
("teststring".into(), "test".into()),
("testmap".into(), map_any_values),
]));
log_benchmark_group(c, "simple-log-with-inner-map-any-value", |logger| {
logger.emit(
LogRecord::builder()
.with_body("simple log")
.with_attribute("testmap", map_any_values.clone())
.build(),
)
});

log_benchmark_group(c, "long-log", |logger| {
logger.emit(LogRecord::builder().with_body("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Gravida in fermentum et sollicitudin ac orci phasellus. Ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. Magna etiam tempor orci eu. Sed tempus urna et pharetra pharetra massa.").build())
});
Expand Down Expand Up @@ -105,14 +230,47 @@ fn criterion_benchmark(c: &mut Criterion) {
.with_attribute("event.id", 20)
.with_attribute("user.name", "otel")
.with_attribute("user.email", "otel@opentelemetry.io")
.with_attribute("log.source.file.name", "log.rs")
.with_attribute("log.source.file.path", "opentelemetry_sdk/benches/log.rs")
.with_attribute("log.source.file.line", 96)
.with_attribute("log.module.path", "opentelemetry_sdk::benches::log")
.with_attribute("code.filename", "log.rs")
.with_attribute("code.filepath", "opentelemetry_sdk/benches/log.rs")
.with_attribute("code.lineno", 96)
.with_attribute("code.namespace", "opentelemetry_sdk::benches::log")
.with_attribute("log.target", "opentelemetry_sdk::benches::log")
.build(),
)
});

let attributes: Vec<(Key, AnyValue)> = vec![
("name".into(), "my-event-name".into()),
("event-id".into(), 20.into()),
("user.name".into(), "otel".into()),
("user.email".into(), "otel@opentelemetry.io".into()),
("code.filename".into(), "log.rs".into()),
(
"code.filepath".into(),
"opentelemetry_sdk/benches/log.rs".into(),
),
("code.lineno".into(), 96.into()),
(
"code.namespace".into(),
"opentelemetry_sdk::benches::log".into(),
),
(
"log.target".into(),
"opentelemetry_sdk::benches::log".into(),
),
];
log_benchmark_group(c, "full-log-with-attributes", |logger| {
logger.emit(
LogRecord::builder()
.with_body("full log")
.with_timestamp(now)
.with_observed_timestamp(now)
.with_severity_number(Severity::Warn)
.with_severity_text(Severity::Warn.name())
.with_attributes(attributes.clone())
.build(),
)
});
}

criterion_group!(benches, criterion_benchmark);
Expand Down

0 comments on commit 27d338d

Please sign in to comment.