Skip to content

Commit aad4b60

Browse files
authored
feat(ourlogs): Add event.name to otlp logs transform (#5396)
1 parent a20d245 commit aad4b60

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Support comparing release versions without build code. ([#5376](https://github.com/getsentry/relay/pull/5376))
88
- Support uploading attachments directly to objectstore. ([#5367](https://github.com/getsentry/relay/pull/5367))
99
- Add `span_count` item header to the envelope protocol. ([#5392](https://github.com/getsentry/relay/pull/5392))
10+
- Add `event.name` attribute to OTLP logs. ([#5396](https://github.com/getsentry/relay/pull/5396))
1011

1112
**Internal**:
1213

@@ -54,7 +55,6 @@
5455
- Remove the span kind from the Kafka span schema. ([#5368](https://github.com/getsentry/relay/pull/5368))
5556
- Unconditionally enable span extraction. ([#5308](https://github.com/getsentry/relay/pull/5308))
5657

57-
5858
## 25.10.0
5959

6060
**Features**:

relay-conventions/src/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ convention_attributes!(
2929
DSC_TRACE_ID => "sentry.dsc.trace_id",
3030
DSC_TRANSACTION => "sentry.dsc.transaction",
3131
ENVIRONMENT => "sentry.environment",
32+
EVENT_NAME => "event.name",
3233
FAAS_TRIGGER => "faas.trigger",
3334
GEN_AI_COST_INPUT_TOKENS => "gen_ai.cost.input_tokens",
3435
GEN_AI_COST_OUTPUT_TOKENS => "gen_ai.cost.output_tokens",

relay-ourlogs/src/otel_to_sentry.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use chrono::{TimeZone, Utc};
77
use opentelemetry_proto::tonic::common::v1::InstrumentationScope;
88
use opentelemetry_proto::tonic::common::v1::any_value::Value as OtelValue;
99
use opentelemetry_proto::tonic::logs::v1::LogRecord as OtelLogRecord;
10-
use relay_conventions::ORIGIN;
10+
use relay_conventions::{EVENT_NAME, ORIGIN};
1111

1212
use opentelemetry_proto::tonic::resource::v1::Resource;
1313
use relay_event_schema::protocol::{Attributes, OurLog, OurLogLevel, SpanId, Timestamp, TraceId};
@@ -59,7 +59,10 @@ pub fn otel_to_sentry_log(
5959
attributes,
6060
trace_id,
6161
span_id,
62-
..
62+
event_name,
63+
observed_time_unix_nano: _,
64+
dropped_attributes_count: _,
65+
flags: _,
6366
} = otel_log;
6467

6568
let span_id = match span_id.is_empty() {
@@ -76,6 +79,9 @@ pub fn otel_to_sentry_log(
7679

7780
let mut attribute_data = Attributes::default();
7881
attribute_data.insert(ORIGIN, "auto.otlp.logs".to_owned());
82+
if !event_name.is_empty() {
83+
attribute_data.insert(EVENT_NAME, event_name.to_owned());
84+
}
7985

8086
relay_otel::otel_scope_into_attributes(&mut attribute_data, resource, scope);
8187

@@ -570,4 +576,61 @@ mod tests {
570576
}
571577
"#);
572578
}
579+
580+
#[test]
581+
fn parse_otel_log_with_event_name() {
582+
// 2024-01-01T10:00:00Z = 1704103200
583+
let json = r#"{
584+
"eventName": "user.login",
585+
"timeUnixNano": "1704103200000000000",
586+
"severityText": "INFO",
587+
"body": {
588+
"stringValue": "User login successful"
589+
},
590+
"attributes": [
591+
{
592+
"key": "user.id",
593+
"value": { "stringValue": "12345" }
594+
},
595+
{
596+
"key": "login.method",
597+
"value": { "stringValue": "oauth" }
598+
}
599+
],
600+
"traceId": "abcdef1234567890abcdef1234567890",
601+
"spanId": "7890123456789012"
602+
}"#;
603+
604+
let otel_log: OtelLogRecord = serde_json::from_str(json).unwrap();
605+
let our_log = otel_to_sentry_log(otel_log, None, None);
606+
let annotated_log: Annotated<OurLog> = Annotated::new(our_log);
607+
608+
insta::assert_json_snapshot!(SerializableAnnotated(&annotated_log), @r#"
609+
{
610+
"timestamp": 1704103200.0,
611+
"trace_id": "abcdef1234567890abcdef1234567890",
612+
"span_id": "7890123456789012",
613+
"level": "info",
614+
"body": "User login successful",
615+
"attributes": {
616+
"event.name": {
617+
"type": "string",
618+
"value": "user.login"
619+
},
620+
"login.method": {
621+
"type": "string",
622+
"value": "oauth"
623+
},
624+
"sentry.origin": {
625+
"type": "string",
626+
"value": "auto.otlp.logs"
627+
},
628+
"user.id": {
629+
"type": "string",
630+
"value": "12345"
631+
}
632+
}
633+
}
634+
"#);
635+
}
573636
}

0 commit comments

Comments
 (0)