Skip to content

Commit

Permalink
Propagate isEvent flag to writeLogBody function
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny committed Jan 10, 2025
1 parent 539fa9d commit 7ba2575
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions exporter/elasticsearchexporter/pdata_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,17 @@ func serializeLog(resource pcommon.Resource, resourceSchemaURL string, scope pco
writeSpanIDField(v, "span_id", record.SpanID())
writeAttributes(v, record.Attributes(), false)
writeIntFieldSkipDefault(v, "dropped_attributes_count", int64(record.DroppedAttributesCount()))
isEvent := false
if record.EventName() != "" {
isEvent = true
writeStringFieldSkipDefault(v, "event_name", record.EventName())
} else if eventNameAttr, ok := record.Attributes().Get("event.name"); ok && eventNameAttr.Str() != "" {
isEvent = true
writeStringFieldSkipDefault(v, "event_name", eventNameAttr.Str())
}
writeResource(v, resource, resourceSchemaURL, false)
writeScope(v, scope, scopeSchemaURL, false)
writeLogBody(v, record)
writeLogBody(v, record, isEvent)
_ = v.OnObjectFinished()
return buf.Bytes(), nil
}
Expand All @@ -206,7 +209,7 @@ func writeDataStream(v *json.Visitor, attributes pcommon.Map) {
_ = v.OnObjectFinished()
}

func writeLogBody(v *json.Visitor, record plog.LogRecord) {
func writeLogBody(v *json.Visitor, record plog.LogRecord, isEvent bool) {
if record.Body().Type() == pcommon.ValueTypeEmpty {
return
}
Expand All @@ -216,7 +219,7 @@ func writeLogBody(v *json.Visitor, record plog.LogRecord) {
// Determine if this log record is an event, as they are mapped differently
// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/events.md
var bodyType string
if _, hasEventNameAttribute := record.Attributes().Get("event.name"); hasEventNameAttribute || record.EventName() != "" {
if isEvent {
bodyType = "structured"
} else {
bodyType = "flattened"
Expand Down

0 comments on commit 7ba2575

Please sign in to comment.