From 46a5d017ce6a37006e965bdc10a478b97715827f Mon Sep 17 00:00:00 2001 From: jeet7122 Date: Tue, 24 Feb 2026 17:21:12 -0500 Subject: [PATCH 1/4] sdk-logs: default event timestamp on emit --- .../io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java | 9 ++++++++- .../opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java index a99165d33e5..a3eaa9869a4 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java @@ -144,11 +144,18 @@ public void emit() { if (!logger.isEnabled(severity, context)) { return; } + + long now = loggerSharedState.getClock().now(); + long observedTimestampEpochNanos = this.observedTimestampEpochNanos == 0 - ? this.loggerSharedState.getClock().now() + ? now : this.observedTimestampEpochNanos; + long timeStampEpochNanos = this.timestampEpochNanos == 0 ? now : this.timestampEpochNanos; + + this.timestampEpochNanos = timeStampEpochNanos; + loggerSharedState.getLoggerInstrumentation().emitLog(); loggerSharedState .getLogRecordProcessor() diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java index 54f2d15199f..ff92f94f3ce 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java @@ -125,7 +125,7 @@ void emit_NoFields() { .hasResource(RESOURCE) .hasInstrumentationScope(SCOPE_INFO) .hasBody((Value) null) - .hasTimestamp(0L) + .hasTimestamp(10L) .hasObservedTimestamp(10L) .hasAttributes(Attributes.empty()) .hasSpanContext(SpanContext.getInvalid()) From 7fdc85997ecafe51f1416b4222b7b016f98d18b5 Mon Sep 17 00:00:00 2001 From: jeet7122 Date: Tue, 24 Feb 2026 18:07:43 -0500 Subject: [PATCH 2/4] Revert "sdk-logs: default event timestamp on emit" This reverts commit 46a5d017ce6a37006e965bdc10a478b97715827f. --- .../io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java | 9 +-------- .../opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java index a3eaa9869a4..a99165d33e5 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java @@ -144,18 +144,11 @@ public void emit() { if (!logger.isEnabled(severity, context)) { return; } - - long now = loggerSharedState.getClock().now(); - long observedTimestampEpochNanos = this.observedTimestampEpochNanos == 0 - ? now + ? this.loggerSharedState.getClock().now() : this.observedTimestampEpochNanos; - long timeStampEpochNanos = this.timestampEpochNanos == 0 ? now : this.timestampEpochNanos; - - this.timestampEpochNanos = timeStampEpochNanos; - loggerSharedState.getLoggerInstrumentation().emitLog(); loggerSharedState .getLogRecordProcessor() diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java index ff92f94f3ce..54f2d15199f 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java @@ -125,7 +125,7 @@ void emit_NoFields() { .hasResource(RESOURCE) .hasInstrumentationScope(SCOPE_INFO) .hasBody((Value) null) - .hasTimestamp(10L) + .hasTimestamp(0L) .hasObservedTimestamp(10L) .hasAttributes(Attributes.empty()) .hasSpanContext(SpanContext.getInvalid()) From cb7fa054bfaeb79d5f0b779e4e06838be802b0d5 Mon Sep 17 00:00:00 2001 From: jeet7122 Date: Tue, 24 Feb 2026 18:13:37 -0500 Subject: [PATCH 3/4] api-logs: fix LogRecordBuilder#setTimestamp javadoc --- .../opentelemetry/api/logs/LogRecordBuilder.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java b/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java index c0239724b36..0c1c3a49a92 100644 --- a/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java +++ b/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java @@ -31,16 +31,22 @@ public interface LogRecordBuilder { /** * Set the epoch {@code timestamp}, using the timestamp and unit. * - *

The {@code timestamp} is the time at which the log record occurred. If unset, it will be set - * to the current time when {@link #emit()} is called. + *

The {@code timestamp} is the time at which the log record occurred. + * If unset, the timestamp will remain unset. + * + *

The observed timestamp will be set to the current time when {@link #emit()} + * is called if it is not explicitly set. */ LogRecordBuilder setTimestamp(long timestamp, TimeUnit unit); /** - * Set the epoch {@code timestamp}, using the instant. + * Set the epoch {@code timestamp}, using the timestamp and unit. + * + *

The {@code timestamp} is the time at which the log record occurred. + * If unset, the timestamp will remain unset. * - *

The {@code timestamp} is the time at which the log record occurred. If unset, it will be set - * to the current time when {@link #emit()} is called. + *

The observed timestamp will be set to the current time when {@link #emit()} + * is called if it is not explicitly set. */ LogRecordBuilder setTimestamp(Instant instant); From 0e6f81522efcc41d55f6e102f9f5d428478bbd02 Mon Sep 17 00:00:00 2001 From: jeet7122 Date: Tue, 24 Feb 2026 18:19:25 -0500 Subject: [PATCH 4/4] api-logs: format LogRecordBuilder javadoc --- .../opentelemetry/api/logs/LogRecordBuilder.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java b/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java index 0c1c3a49a92..2c264fd18df 100644 --- a/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java +++ b/api/all/src/main/java/io/opentelemetry/api/logs/LogRecordBuilder.java @@ -31,22 +31,22 @@ public interface LogRecordBuilder { /** * Set the epoch {@code timestamp}, using the timestamp and unit. * - *

The {@code timestamp} is the time at which the log record occurred. - * If unset, the timestamp will remain unset. + *

The {@code timestamp} is the time at which the log record occurred. If unset, the timestamp + * will remain unset. * - *

The observed timestamp will be set to the current time when {@link #emit()} - * is called if it is not explicitly set. + *

The observed timestamp will be set to the current time when {@link #emit()} is called if it + * is not explicitly set. */ LogRecordBuilder setTimestamp(long timestamp, TimeUnit unit); /** * Set the epoch {@code timestamp}, using the timestamp and unit. * - *

The {@code timestamp} is the time at which the log record occurred. - * If unset, the timestamp will remain unset. + *

The {@code timestamp} is the time at which the log record occurred. If unset, the timestamp + * will remain unset. * - *

The observed timestamp will be set to the current time when {@link #emit()} - * is called if it is not explicitly set. + *

The observed timestamp will be set to the current time when {@link #emit()} is called if it + * is not explicitly set. */ LogRecordBuilder setTimestamp(Instant instant);