Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Aug 8, 2023
1 parent f906851 commit 820809a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions exporter/collector/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,10 @@ func (l logMapper) logToSplitEntries(
}
entry.Severity = severityMapping[severityNumber]

// log.Body().AsString() can be expensive, and we use it several times below this, so
// do it once and save that as a variable.
logBodyString := logRecord.Body().AsString()

// Parse severityNumber > 17 (error) to a GCP Error Reporting entry if enabled
if severityNumber >= 17 && l.cfg.LogConfig.ErrorReportingType {
if logRecord.Body().Type() != pcommon.ValueTypeMap {
logBodyString := logRecord.Body().AsString()
logRecord.Body().SetEmptyMap()
logRecord.Body().Map().PutStr("message", logBodyString)
}
Expand All @@ -458,10 +455,6 @@ func (l logMapper) logToSplitEntries(
}
}

if len(logBodyString) == 0 {
return []*logpb.LogEntry{entry}, nil
}

// Handle map and bytes as JSON-structured logs if they are successfully converted.
switch logRecord.Body().Type() {
case pcommon.ValueTypeMap:
Expand All @@ -477,10 +470,17 @@ func (l logMapper) logToSplitEntries(
entry.Payload = &logpb.LogEntry_JsonPayload{JsonPayload: s}

Check warning on line 470 in exporter/collector/logs.go

View check run for this annotation

Codecov / codecov/patch

exporter/collector/logs.go#L470

Added line #L470 was not covered by tests
return []*logpb.LogEntry{entry}, nil
}
l.obs.log.Warn(fmt.Sprintf("bytes body cannot be converted to a json payload, exporting as raw string: %+v", err))
l.obs.log.Warn(fmt.Sprintf("bytes body cannot be converted to a json payload, exporting as base64 string: %+v", err))
}
// For all other ValueTypes, export as a string payload.

// log.Body().AsString() can be expensive, and we use it several times below this, so
// do it once and save that as a variable.
logBodyString := logRecord.Body().AsString()
if len(logBodyString) == 0 {
return []*logpb.LogEntry{entry}, nil
}

// Calculate the size of the internal log entry so this overhead can be accounted
// for when determining the need to split based on payload size
// TODO(damemi): Find an appropriate estimated buffer to account for the LogSplit struct as well
Expand Down

0 comments on commit 820809a

Please sign in to comment.