Skip to content
Draft
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

### SDK

#### Logs

* Fix `ReadWriteLogRecord.getObservedTimestampEpochNanos()` default method returning the record timestamp instead of the observed timestamp
([#8504](https://github.com/open-telemetry/opentelemetry-java/pull/8504))

## Version 1.63.0 (2026-06-05)

### API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ default long getTimestampEpochNanos() {
* @since 1.46.0
*/
default long getObservedTimestampEpochNanos() {
return toLogRecordData().getTimestampEpochNanos();
return toLogRecordData().getObservedTimestampEpochNanos();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.Value;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.common.internal.AttributesMap;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class ReadWriteLogRecordTest {
Expand Down Expand Up @@ -48,6 +52,33 @@ void allHandlesEmpty() {
assertThat(result.getAttributes()).isEqualTo(originalAttributes);
}

@Test
void defaultGetObservedTimestampEpochNanos_returnsObservedTimestamp() {
LogRecordData data =
TestLogRecordData.builder()
.setTimestamp(100, TimeUnit.NANOSECONDS)
.setObservedTimestamp(200, TimeUnit.NANOSECONDS)
.build();
// A ReadWriteLogRecord that relies on the interface default methods, implementing only the
// abstract methods. The SDK's SdkReadWriteLogRecord overrides the getters, so the default
// method behavior must be exercised through a custom implementation.
ReadWriteLogRecord logRecord =
new ReadWriteLogRecord() {
@Override
public <T> ReadWriteLogRecord setAttribute(AttributeKey<T> key, T value) {
return this;
}

@Override
public LogRecordData toLogRecordData() {
return data;
}
};

assertThat(logRecord.getObservedTimestampEpochNanos()).isEqualTo(200);
assertThat(logRecord.getTimestampEpochNanos()).isEqualTo(100);
}

SdkReadWriteLogRecord buildLogRecord() {
Value<?> body = Value.of("bod");
AttributesMap initialAttributes = AttributesMap.create(100, 200);
Expand Down
Loading