Skip to content

Commit

Permalink
OTLP exporter: Set observed timestamp (#4444)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest authored Apr 26, 2023
1 parent 9d51cc3 commit 39314f8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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,
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

0 comments on commit 39314f8

Please sign in to comment.