Skip to content

Commit

Permalink
Add missing timestamp for jboss logmanager instrumentation (#9159)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Aug 8, 2023
1 parent 4854a60 commit 14b063d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.jbosslogmanager.appender.v1_1;

import static java.util.Collections.emptyList;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
Expand Down Expand Up @@ -99,6 +100,7 @@ public void capture(Logger logger, ExtLogRecord record) {

builder.setContext(Context.current());

builder.setTimestamp(record.getMillis(), MILLISECONDS);
builder.emit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -17,6 +18,7 @@
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.time.Instant;
import java.util.stream.Stream;
import org.jboss.logmanager.Level;
import org.jboss.logmanager.LogContext;
Expand Down Expand Up @@ -108,6 +110,8 @@ private static void test(
String expectedSeverityText)
throws InterruptedException {

Instant start = Instant.now();

// when
if (withParent) {
testing.runWithSpan(
Expand All @@ -128,6 +132,11 @@ private static void test(
.hasInstrumentationScope(InstrumentationScopeInfo.builder(expectedLoggerName).build())
.hasSeverity(expectedSeverity)
.hasSeverityText(expectedSeverityText);

assertThat(log.getTimestampEpochNanos())
.isGreaterThanOrEqualTo(MILLISECONDS.toNanos(start.toEpochMilli()))
.isLessThanOrEqualTo(MILLISECONDS.toNanos(Instant.now().toEpochMilli()));

if (logException) {
assertThat(log)
.hasAttributesSatisfyingExactly(
Expand Down

0 comments on commit 14b063d

Please sign in to comment.