Skip to content

Commit 54e526c

Browse files
authored
User-events log exporter - Fix event name and cs version (#175)
1 parent 7acb3c8 commit 54e526c

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

opentelemetry-user-events-logs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
```
1414

1515
- Removed `opentelemetry_user_events_logs::{ExporterConfig, ReentrantLogProcessor, UserEventsExporter}` from the public API. Ability to customize Provider Group, Keyword will be added future.
16+
- `log_record.event_name()` is used to populate EventName. Previous behavior of populating EventName from specially named attributes is removed.
17+
- Fix CommonSchema version to `0x0400` instead of `0x0401`
1618

1719
## v0.9.0
1820

opentelemetry-user-events-logs/examples/basic-logs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() {
5151

5252
while running.load(Ordering::SeqCst) {
5353
error!(
54-
name = "my-event-name",
54+
name: "my-event-name",
5555
event_id = 20,
5656
user_name = "otel user",
5757
user_email = "otel@opentelemetry.io"

opentelemetry-user-events-logs/src/logs/exporter.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ pub struct UserEventsExporter {
5454
}
5555

5656
const EVENT_ID: &str = "event_id";
57-
const EVENT_NAME_PRIMARY: &str = "event_name";
58-
const EVENT_NAME_SECONDARY: &str = "name";
5957

6058
impl UserEventsExporter {
6159
/// Create instance of the exporter
@@ -260,7 +258,7 @@ impl UserEventsExporter {
260258
eb.reset(instrumentation.name().as_ref(), event_tags as u16);
261259
eb.opcode(Opcode::Info);
262260

263-
eb.add_value("__csver__", 0x0401u16, FieldFormat::HexInt, 0);
261+
eb.add_value("__csver__", 0x0400u16, FieldFormat::HexInt, 0);
264262

265263
// populate CS PartA
266264
let mut cs_a_count = 0;
@@ -278,7 +276,6 @@ impl UserEventsExporter {
278276
}
279277
//populate CS PartC
280278
let (mut is_event_id, mut event_id) = (false, 0);
281-
let (mut is_event_name, mut event_name) = (false, "");
282279
let (mut is_part_c_present, mut cs_c_bookmark, mut cs_c_count) = (false, 0, 0);
283280

284281
for (key, value) in log_record.attributes_iter() {
@@ -288,31 +285,24 @@ impl UserEventsExporter {
288285
event_id = *value;
289286
continue;
290287
}
291-
(EVENT_NAME_PRIMARY, AnyValue::String(value)) => {
292-
is_event_name = true;
293-
event_name = value.as_str();
294-
continue;
295-
}
296-
(EVENT_NAME_SECONDARY, AnyValue::String(value)) => {
297-
if !is_event_name {
298-
event_name = value.as_str();
299-
}
300-
continue;
301-
}
302288
_ => {
303289
if !is_part_c_present {
304290
eb.add_struct_with_bookmark("PartC", 1, 0, &mut cs_c_bookmark);
305291
is_part_c_present = true;
306292
}
307293
self.add_attribute_to_event(&mut eb, (key, value));
294+
// TODO: This is buggy and incorrectly increments the count
295+
// even when the attribute is not added to PartC.
296+
// This can occur when the attribute is not a primitive type.
308297
cs_c_count += 1;
309298
}
310299
}
300+
}
311301

312-
if is_part_c_present {
313-
eb.set_struct_field_count(cs_c_bookmark, cs_c_count);
314-
}
302+
if is_part_c_present {
303+
eb.set_struct_field_count(cs_c_bookmark, cs_c_count);
315304
}
305+
316306
// populate CS PartB
317307
let mut cs_b_bookmark: usize = 0;
318308
let mut cs_b_count = 0;
@@ -355,7 +345,7 @@ impl UserEventsExporter {
355345
eb.add_value("eventId", event_id, FieldFormat::SignedInt, 0);
356346
cs_b_count += 1;
357347
}
358-
if !event_name.is_empty() {
348+
if let Some(event_name) = log_record.event_name() {
359349
eb.add_str("name", event_name, FieldFormat::Default, 0);
360350
cs_b_count += 1;
361351
}

0 commit comments

Comments
 (0)