|
| 1 | +use std::collections::HashMap; |
1 | 2 | use std::time::SystemTime;
|
2 | 3 |
|
3 | 4 | use async_trait::async_trait;
|
4 | 5 | use criterion::{criterion_group, criterion_main, Criterion};
|
5 | 6 |
|
6 |
| -use opentelemetry::logs::{LogRecord, LogResult, Logger, LoggerProvider as _, Severity}; |
| 7 | +use opentelemetry::logs::{AnyValue, LogRecord, LogResult, Logger, LoggerProvider as _, Severity}; |
7 | 8 | use opentelemetry::trace::Tracer;
|
8 | 9 | use opentelemetry::trace::TracerProvider as _;
|
| 10 | +use opentelemetry::Key; |
9 | 11 | use opentelemetry_sdk::export::logs::{LogData, LogExporter};
|
10 | 12 | use opentelemetry_sdk::logs::LoggerProvider;
|
11 | 13 | use opentelemetry_sdk::trace::{config, Sampler, TracerProvider};
|
@@ -60,6 +62,129 @@ fn criterion_benchmark(c: &mut Criterion) {
|
60 | 62 | logger.emit(LogRecord::builder().with_body("simple log").build())
|
61 | 63 | });
|
62 | 64 |
|
| 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 | + |
63 | 188 | log_benchmark_group(c, "long-log", |logger| {
|
64 | 189 | 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())
|
65 | 190 | });
|
@@ -105,14 +230,47 @@ fn criterion_benchmark(c: &mut Criterion) {
|
105 | 230 | .with_attribute("event.id", 20)
|
106 | 231 | .with_attribute("user.name", "otel")
|
107 | 232 | .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") |
112 | 237 | .with_attribute("log.target", "opentelemetry_sdk::benches::log")
|
113 | 238 | .build(),
|
114 | 239 | )
|
115 | 240 | });
|
| 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 | + }); |
116 | 274 | }
|
117 | 275 |
|
118 | 276 | criterion_group!(benches, criterion_benchmark);
|
|
0 commit comments