Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTLP exporter: Set observed timestamp #4444

Merged
merged 3 commits into from
Apr 26, 2023
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 @@ -16,6 +16,14 @@
and `Attributes` are equivalent).
([#4334](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4334))

* Fixed issue where the
[observed time](https://github.com/open-telemetry/opentelemetry-proto/blob/395c8422fe90080314c7d9b4114d701a0c049e1f/opentelemetry/proto/logs/v1/logs.proto#L138)
field of the OTLP log record was not set. It is now correctly set to equal
the
[time](https://github.com/open-telemetry/opentelemetry-proto/blob/395c8422fe90080314c7d9b4114d701a0c049e1f/opentelemetry/proto/logs/v1/logs.proto#L121)
field.
([#4444](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4444))

## 1.5.0-alpha.2

Released 2023-Mar-31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO

try
{
var timestamp = (ulong)logRecord.Timestamp.ToUnixTimeNanoseconds();
otlpLogRecord = new OtlpLogs.LogRecord
{
TimeUnixNano = (ulong)logRecord.Timestamp.ToUnixTimeNanoseconds(),
TimeUnixNano = timestamp,
ObservedTimeUnixNano = timestamp,
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
SeverityNumber = GetSeverityNumber(logRecord.LogLevel),
SeverityText = LogLevels[(int)logRecord.LogLevel],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,27 @@ public void CheckToOtlpLogRecordEventId()
Assert.Contains("MyEvent10", otlpLogRecordAttributes);
}

[Fact]
public void CheckToOtlpLogRecordTimestamps()
{
var logRecords = new List<LogRecord>();
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.AddInMemoryExporter(logRecords);
});
});

var logger = loggerFactory.CreateLogger("OtlpLogExporterTests");
logger.LogInformation("Log message");
var logRecord = logRecords[0];
var otlpLogRecord = logRecord.ToOtlpLog(DefaultSdkLimitOptions);

Assert.True(otlpLogRecord.TimeUnixNano > 0);
Assert.True(otlpLogRecord.ObservedTimeUnixNano > 0);
}

[Fact]
public void CheckToOtlpLogRecordTraceIdSpanIdFlagWithNoActivity()
{
Expand Down