Skip to content

Commit 27d338d

Browse files
Rockin2lalitb
andauthored
Add new benches for logs (#1450)
Implement new bench ideas from this [PR](https://github.com/open-telemetry/opentelemetry-rust/pull/1431)’s 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 <[email protected]>
1 parent 306286e commit 27d338d

File tree

1 file changed

+163
-5
lines changed
  • opentelemetry-sdk/benches

1 file changed

+163
-5
lines changed

opentelemetry-sdk/benches/log.rs

Lines changed: 163 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
use std::collections::HashMap;
12
use std::time::SystemTime;
23

34
use async_trait::async_trait;
45
use criterion::{criterion_group, criterion_main, Criterion};
56

6-
use opentelemetry::logs::{LogRecord, LogResult, Logger, LoggerProvider as _, Severity};
7+
use opentelemetry::logs::{AnyValue, LogRecord, LogResult, Logger, LoggerProvider as _, Severity};
78
use opentelemetry::trace::Tracer;
89
use opentelemetry::trace::TracerProvider as _;
10+
use opentelemetry::Key;
911
use opentelemetry_sdk::export::logs::{LogData, LogExporter};
1012
use opentelemetry_sdk::logs::LoggerProvider;
1113
use opentelemetry_sdk::trace::{config, Sampler, TracerProvider};
@@ -60,6 +62,129 @@ fn criterion_benchmark(c: &mut Criterion) {
6062
logger.emit(LogRecord::builder().with_body("simple log").build())
6163
});
6264

65+
log_benchmark_group(c, "simple-log-with-int", |logger| {
66+
logger.emit(
67+
LogRecord::builder()
68+
.with_body("simple log")
69+
.with_attribute("testint", 2)
70+
.build(),
71+
)
72+
});
73+
74+
log_benchmark_group(c, "simple-log-with-double", |logger| {
75+
logger.emit(
76+
LogRecord::builder()
77+
.with_body("simple log")
78+
.with_attribute("testdouble", 2.2)
79+
.build(),
80+
)
81+
});
82+
83+
log_benchmark_group(c, "simple-log-with-string", |logger| {
84+
logger.emit(
85+
LogRecord::builder()
86+
.with_body("simple log")
87+
.with_attribute("teststring", "test")
88+
.build(),
89+
)
90+
});
91+
92+
log_benchmark_group(c, "simple-log-with-bool", |logger| {
93+
logger.emit(
94+
LogRecord::builder()
95+
.with_body("simple log")
96+
.with_attribute("testbool", AnyValue::Boolean(true))
97+
.build(),
98+
)
99+
});
100+
101+
let bytes = AnyValue::Bytes(vec![25u8, 30u8, 40u8]);
102+
log_benchmark_group(c, "simple-log-with-bytes", |logger| {
103+
logger.emit(
104+
LogRecord::builder()
105+
.with_body("simple log")
106+
.with_attribute("testbytes", bytes.clone())
107+
.build(),
108+
)
109+
});
110+
111+
let bytes = AnyValue::Bytes(vec![
112+
25u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
113+
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8,
114+
40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
115+
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8,
116+
40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
117+
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
118+
]);
119+
log_benchmark_group(c, "simple-log-with-a-lot-of-bytes", |logger| {
120+
logger.emit(
121+
LogRecord::builder()
122+
.with_body("simple log")
123+
.with_attribute("testbytes", bytes.clone())
124+
.build(),
125+
)
126+
});
127+
128+
let vec_any_values = AnyValue::ListAny(vec![AnyValue::Int(25), "test".into(), true.into()]);
129+
log_benchmark_group(c, "simple-log-with-vec-any-value", |logger| {
130+
logger.emit(
131+
LogRecord::builder()
132+
.with_body("simple log")
133+
.with_attribute("testvec", vec_any_values.clone())
134+
.build(),
135+
)
136+
});
137+
138+
let vec_any_values = AnyValue::ListAny(vec![AnyValue::Int(25), "test".into(), true.into()]);
139+
let vec_any_values = AnyValue::ListAny(vec![
140+
AnyValue::Int(25),
141+
"test".into(),
142+
true.into(),
143+
vec_any_values,
144+
]);
145+
log_benchmark_group(c, "simple-log-with-inner-vec-any-value", |logger| {
146+
logger.emit(
147+
LogRecord::builder()
148+
.with_body("simple log")
149+
.with_attribute("testvec", vec_any_values.clone())
150+
.build(),
151+
)
152+
});
153+
154+
let map_any_values = AnyValue::Map(HashMap::from([
155+
("testint".into(), 2.into()),
156+
("testdouble".into(), 2.2.into()),
157+
("teststring".into(), "test".into()),
158+
]));
159+
log_benchmark_group(c, "simple-log-with-map-any-value", |logger| {
160+
logger.emit(
161+
LogRecord::builder()
162+
.with_body("simple log")
163+
.with_attribute("testmap", map_any_values.clone())
164+
.build(),
165+
)
166+
});
167+
168+
let map_any_values = AnyValue::Map(HashMap::from([
169+
("testint".into(), 2.into()),
170+
("testdouble".into(), 2.2.into()),
171+
("teststring".into(), "test".into()),
172+
]));
173+
let map_any_values = AnyValue::Map(HashMap::from([
174+
("testint".into(), 2.into()),
175+
("testdouble".into(), 2.2.into()),
176+
("teststring".into(), "test".into()),
177+
("testmap".into(), map_any_values),
178+
]));
179+
log_benchmark_group(c, "simple-log-with-inner-map-any-value", |logger| {
180+
logger.emit(
181+
LogRecord::builder()
182+
.with_body("simple log")
183+
.with_attribute("testmap", map_any_values.clone())
184+
.build(),
185+
)
186+
});
187+
63188
log_benchmark_group(c, "long-log", |logger| {
64189
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())
65190
});
@@ -105,14 +230,47 @@ fn criterion_benchmark(c: &mut Criterion) {
105230
.with_attribute("event.id", 20)
106231
.with_attribute("user.name", "otel")
107232
.with_attribute("user.email", "[email protected]")
108-
.with_attribute("log.source.file.name", "log.rs")
109-
.with_attribute("log.source.file.path", "opentelemetry_sdk/benches/log.rs")
110-
.with_attribute("log.source.file.line", 96)
111-
.with_attribute("log.module.path", "opentelemetry_sdk::benches::log")
233+
.with_attribute("code.filename", "log.rs")
234+
.with_attribute("code.filepath", "opentelemetry_sdk/benches/log.rs")
235+
.with_attribute("code.lineno", 96)
236+
.with_attribute("code.namespace", "opentelemetry_sdk::benches::log")
112237
.with_attribute("log.target", "opentelemetry_sdk::benches::log")
113238
.build(),
114239
)
115240
});
241+
242+
let attributes: Vec<(Key, AnyValue)> = vec![
243+
("name".into(), "my-event-name".into()),
244+
("event-id".into(), 20.into()),
245+
("user.name".into(), "otel".into()),
246+
("user.email".into(), "[email protected]".into()),
247+
("code.filename".into(), "log.rs".into()),
248+
(
249+
"code.filepath".into(),
250+
"opentelemetry_sdk/benches/log.rs".into(),
251+
),
252+
("code.lineno".into(), 96.into()),
253+
(
254+
"code.namespace".into(),
255+
"opentelemetry_sdk::benches::log".into(),
256+
),
257+
(
258+
"log.target".into(),
259+
"opentelemetry_sdk::benches::log".into(),
260+
),
261+
];
262+
log_benchmark_group(c, "full-log-with-attributes", |logger| {
263+
logger.emit(
264+
LogRecord::builder()
265+
.with_body("full log")
266+
.with_timestamp(now)
267+
.with_observed_timestamp(now)
268+
.with_severity_number(Severity::Warn)
269+
.with_severity_text(Severity::Warn.name())
270+
.with_attributes(attributes.clone())
271+
.build(),
272+
)
273+
});
116274
}
117275

118276
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)