Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ static void formatLog(StringBuilder stringBuilder, LogRecordData log) {
InstrumentationScopeInfo instrumentationScopeInfo = log.getInstrumentationScopeInfo();
Value<?> body = log.getBodyValue();
String eventName = log.getEventName();
long timestampEpochNanos = log.getTimestampEpochNanos();
if (timestampEpochNanos == 0) {
timestampEpochNanos = log.getObservedTimestampEpochNanos();
}
stringBuilder
.append(
ISO_FORMAT.format(
Instant.ofEpochMilli(NANOSECONDS.toMillis(log.getTimestampEpochNanos()))
Instant.ofEpochMilli(NANOSECONDS.toMillis(timestampEpochNanos))
.atZone(ZoneOffset.UTC)))
.append(" ")
.append(log.getSeverity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ void formatWithEventName() {
+ "00000000000000010000000000000002 0000000000000003 [scopeInfo: logTest:1.0] {}");
}

@Test
void formatWithoutTimestampUsesObservedTimestamp() {
long observedTimestamp =
LocalDateTime.of(1970, Month.AUGUST, 7, 10, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
LogRecordData log =
TestLogRecordData.builder()
.setResource(Resource.empty())
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("logTest").setVersion("1.0").build())
.setBody("message")
.setSeverity(Severity.ERROR3)
.setObservedTimestamp(observedTimestamp, TimeUnit.MILLISECONDS)
.setSpanContext(
SpanContext.create(
"00000000000000010000000000000002",
"0000000000000003",
TraceFlags.getDefault(),
TraceState.getDefault()))
.build();
StringBuilder output = new StringBuilder();
SystemOutLogRecordExporter.formatLog(output, log);
assertThat(output.toString())
.isEqualTo(
"1970-08-07T10:00:00Z ERROR3 'message' : 00000000000000010000000000000002 "
+ "0000000000000003 [scopeInfo: logTest:1.0] {}");
}

@Test
void shutdown() {
SystemOutLogRecordExporter exporter = SystemOutLogRecordExporter.create();
Expand Down
Loading