Skip to content

Add ObservedTimestamp to LogRecordData#6979

Open
juliuskoval wants to merge 6 commits intoopen-telemetry:mainfrom
juliuskoval:ObservedTimeStamp
Open

Add ObservedTimestamp to LogRecordData#6979
juliuskoval wants to merge 6 commits intoopen-telemetry:mainfrom
juliuskoval:ObservedTimeStamp

Conversation

@juliuskoval
Copy link
Copy Markdown
Contributor

@juliuskoval juliuskoval commented Mar 18, 2026

Towards #4433

Changes

Adds ObservedTimestamp to LogRecordData and LogRecord.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions bot added pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package labels Mar 18, 2026
@juliuskoval
Copy link
Copy Markdown
Contributor Author

juliuskoval commented Mar 18, 2026

On a somewhat related note, it seems to me that the spec suggests that LogRecordData.Timestamp should be nullable. LogRecord.Timestamp is always set in OpenTelemetryLogger so it shouldn't be a breaking change, but it would be changing the stable public API.

@juliuskoval juliuskoval marked this pull request as ready for review March 18, 2026 17:53
@juliuskoval juliuskoval requested a review from a team as a code owner March 18, 2026 17:53
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.81%. Comparing base (0f74489) to head (7f596a8).
⚠️ Report is 66 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/OpenTelemetry/Logs/LogRecord.cs 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6979      +/-   ##
==========================================
- Coverage   88.87%   88.81%   -0.07%     
==========================================
  Files         263      263              
  Lines       12424    12434      +10     
==========================================
+ Hits        11042    11043       +1     
- Misses       1382     1391       +9     
Flag Coverage Δ
unittests-Project-Experimental 88.62% <90.90%> (-0.14%) ⬇️
unittests-Project-Stable 88.53% <90.90%> (-0.31%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry.Api/Logs/LogRecordData.cs 100.00% <100.00%> (ø)
...metry.Exporter.Console/ConsoleLogRecordExporter.cs 97.10% <100.00%> (+0.04%) ⬆️
...ementation/Serializer/ProtobufOtlpLogSerializer.cs 99.24% <100.00%> (+0.01%) ⬆️
.../OpenTelemetry/Logs/ILogger/OpenTelemetryLogger.cs 87.00% <100.00%> (+0.13%) ⬆️
src/OpenTelemetry/Logs/LogRecord.cs 70.58% <66.66%> (-0.08%) ⬇️

... and 2 files with indirect coverage changes

Comment thread src/OpenTelemetry.Api/.publicApi/Experimental/PublicAPI.Unshipped.txt Outdated
Comment thread src/OpenTelemetry.Api/CHANGELOG.md Outdated
Copy link
Copy Markdown
Member

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a suggestion to update OTLP Exporter changelog.

@Kielek
Copy link
Copy Markdown
Member

Kielek commented Mar 20, 2026

On a somewhat related note, it seems to me that the spec suggests that LogRecordData.Timestamp and LogRecord.Timestamp should be nullable. LogRecord.Timestamp is always set in OpenTelemetryLogger so it shouldn't be a breaking change, but it would be changing the stable public API.

I think that we should document this spec deviation in the document (can be separate PR). What is more it will be great to create some issue to fix it. There is label required major bump.

@juliuskoval
Copy link
Copy Markdown
Contributor Author

On a somewhat related note, it seems to me that the spec suggests that LogRecordData.Timestamp and LogRecord.Timestamp should be nullable. LogRecord.Timestamp is always set in OpenTelemetryLogger so it shouldn't be a breaking change, but it would be changing the stable public API.

I think that we should document this spec deviation in the document (can be separate PR). What is more it will be great to create some issue to fix it. There is label required major bump.

I created this issue to track all the deviations from the spec. #6992

Copy link
Copy Markdown
Member

@Kielek Kielek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delays with reviews. Finally, I was able to finish other OTel Auto task.

If we go with non-nullable approach, it should be fine with some small adjustments.

I have checked also other possibilities (the code is still dirty and probably needs to be split into at least 2 PRs, but it shows potential solution without breaking changes.
Description https://github.com/Kielek/opentelemetry-dotnet/blob/3ee221fe48f17ca399b3dd4d59d7cca9cf8b96de/docs/design/make-timestamp-nullable.md

and the PR itself: Kielek@3ee221f

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar change should be done for ConsoleExporter.
Together with Timestamp, we should log also Observed timestamp.

Please add also CHANGELOG entry.

{
internal DateTime TimestampBacking = DateTime.UtcNow;

internal DateTime ObservedTimestampBacking = DateTime.UtcNow;
Copy link
Copy Markdown
Member

@Kielek Kielek Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider, I think that we should avoid any drifts between these values by default.

Suggested change
internal DateTime ObservedTimestampBacking = DateTime.UtcNow;
internal DateTime ObservedTimestampBacking = TimestampBacking;

@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.Console Issues related to OpenTelemetry.Exporter.Console NuGet package label Mar 29, 2026
@juliuskoval
Copy link
Copy Markdown
Contributor Author

juliuskoval commented Mar 29, 2026

@Kielek Sorry about taking so long as well. Regarding your proposed solutions, couldn't we just leave LogRecord.Timestamp as it is right now given that all options would lead to deviations from the spec and document the difference somewhere?

@juliuskoval
Copy link
Copy Markdown
Contributor Author

Hi @Kielek, do you have any thoughts on my previous comment?

@Kielek
Copy link
Copy Markdown
Member

Kielek commented Apr 2, 2026

Yes, I have one more discussion about this last days. We could change a bit behavior in non-public class and treat DateTime.MinValue/default as not set (for both values) + check it during exporting.

As I know Go-lang is implemented in this way. Hidden null, to avoid extra memory footprint by Nullable version.

I will play a bit with thin Tuesday+ next week.

@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Apr 10, 2026
@Kielek Kielek removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Apr 18, 2026
@martincostello martincostello added keep-open Prevents issues and pull requests being closed as stale and removed Stale Issues and pull requests which have been flagged for closing due to inactivity labels Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep-open Prevents issues and pull requests being closed as stale pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry.Exporter.Console Issues related to OpenTelemetry.Exporter.Console NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants