Rename setEpoch to setTimestamp (#5368)
This commit is contained in:
parent
ecc41c7f5a
commit
0a34867a57
|
|
@ -31,12 +31,12 @@ class DefaultLogger implements Logger {
|
|||
private NoopLogRecordBuilder() {}
|
||||
|
||||
@Override
|
||||
public LogRecordBuilder setEpoch(long timestamp, TimeUnit unit) {
|
||||
public LogRecordBuilder setTimestamp(long timestamp, TimeUnit unit) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogRecordBuilder setEpoch(Instant instant) {
|
||||
public LogRecordBuilder setTimestamp(Instant instant) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,21 @@ import java.util.concurrent.TimeUnit;
|
|||
*/
|
||||
public interface LogRecordBuilder {
|
||||
|
||||
/** Set the epoch timestamp using the timestamp and unit. */
|
||||
LogRecordBuilder setEpoch(long timestamp, TimeUnit unit);
|
||||
/**
|
||||
* Set the epoch {@code timestamp}, using the timestamp and unit.
|
||||
*
|
||||
* <p>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.
|
||||
*/
|
||||
LogRecordBuilder setTimestamp(long timestamp, TimeUnit unit);
|
||||
|
||||
/** Set the epoch timestamp using the instant. */
|
||||
LogRecordBuilder setEpoch(Instant instant);
|
||||
/**
|
||||
* Set the epoch {@code timestamp}, using the instant.
|
||||
*
|
||||
* <p>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.
|
||||
*/
|
||||
LogRecordBuilder setTimestamp(Instant instant);
|
||||
|
||||
/** Set the context. */
|
||||
LogRecordBuilder setContext(Context context);
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ class DefaultLoggerTest {
|
|||
() ->
|
||||
DefaultLogger.getInstance()
|
||||
.logRecordBuilder()
|
||||
.setEpoch(100, TimeUnit.SECONDS)
|
||||
.setEpoch(Instant.now())
|
||||
.setTimestamp(100, TimeUnit.SECONDS)
|
||||
.setTimestamp(Instant.now())
|
||||
.setContext(Context.root())
|
||||
.setSeverity(Severity.DEBUG)
|
||||
.setSeverityText("debug")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class OtlpJsonLoggingLogRecordExporterTest {
|
|||
.setBody("body1")
|
||||
.setSeverity(Severity.INFO)
|
||||
.setSeverityText("INFO")
|
||||
.setEpoch(1631533710L, TimeUnit.MILLISECONDS)
|
||||
.setTimestamp(1631533710L, TimeUnit.MILLISECONDS)
|
||||
.setAttributes(Attributes.of(stringKey("animal"), "cat", longKey("lives"), 9L))
|
||||
.setSpanContext(
|
||||
SpanContext.create(
|
||||
|
|
@ -66,7 +66,7 @@ class OtlpJsonLoggingLogRecordExporterTest {
|
|||
.setBody("body2")
|
||||
.setSeverity(Severity.INFO)
|
||||
.setSeverityText("INFO")
|
||||
.setEpoch(1631533710L, TimeUnit.MILLISECONDS)
|
||||
.setTimestamp(1631533710L, TimeUnit.MILLISECONDS)
|
||||
.setAttributes(Attributes.of(booleanKey("important"), true))
|
||||
.setSpanContext(
|
||||
SpanContext.create(
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class SystemOutLogRecordExporter implements LogRecordExporter {
|
|||
stringBuilder
|
||||
.append(
|
||||
ISO_FORMAT.format(
|
||||
Instant.ofEpochMilli(NANOSECONDS.toMillis(log.getEpochNanos()))
|
||||
Instant.ofEpochMilli(NANOSECONDS.toMillis(log.getTimestampEpochNanos()))
|
||||
.atZone(ZoneOffset.UTC)))
|
||||
.append(" ")
|
||||
.append(log.getSeverity())
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class SystemOutLogRecordExporterTest {
|
|||
.setAttributes(Attributes.of(stringKey("cheese"), "cheddar", longKey("amount"), 1L))
|
||||
.setBody("message")
|
||||
.setSeverity(Severity.ERROR3)
|
||||
.setEpoch(timestamp, TimeUnit.MILLISECONDS)
|
||||
.setTimestamp(timestamp, TimeUnit.MILLISECONDS)
|
||||
.setSpanContext(
|
||||
SpanContext.create(
|
||||
"00000000000000010000000000000002",
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ final class LogMarshaler extends MarshalerWithSize {
|
|||
|
||||
SpanContext spanContext = logRecordData.getSpanContext();
|
||||
return new LogMarshaler(
|
||||
logRecordData.getEpochNanos(),
|
||||
logRecordData.getTimestampEpochNanos(),
|
||||
toProtoSeverityNumber(logRecordData.getSeverity()),
|
||||
MarshalerUtil.toBytes(logRecordData.getSeverityText()),
|
||||
anyValueMarshaler,
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class LogsRequestMarshalerTest {
|
|||
TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()))
|
||||
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
|
||||
.setTotalAttributeCount(2)
|
||||
.setEpoch(12345, TimeUnit.NANOSECONDS)
|
||||
.setTimestamp(12345, TimeUnit.NANOSECONDS)
|
||||
.build()));
|
||||
|
||||
assertThat(resourceLogsMarshalers).hasSize(1);
|
||||
|
|
@ -113,7 +113,7 @@ class LogsRequestMarshalerTest {
|
|||
TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()))
|
||||
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
|
||||
.setTotalAttributeCount(2)
|
||||
.setEpoch(12345, TimeUnit.NANOSECONDS)
|
||||
.setTimestamp(12345, TimeUnit.NANOSECONDS)
|
||||
.build()));
|
||||
|
||||
assertThat(logRecord.getTraceId().toByteArray()).isEqualTo(TRACE_ID_BYTES);
|
||||
|
|
@ -141,7 +141,7 @@ class LogsRequestMarshalerTest {
|
|||
Resource.create(Attributes.builder().put("testKey", "testValue").build()))
|
||||
.setInstrumentationScopeInfo(
|
||||
InstrumentationScopeInfo.builder("instrumentation").setVersion("1").build())
|
||||
.setEpoch(12345, TimeUnit.NANOSECONDS)
|
||||
.setTimestamp(12345, TimeUnit.NANOSECONDS)
|
||||
.build()));
|
||||
|
||||
assertThat(logRecord.getTraceId()).isEmpty();
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class FakeTelemetryUtil {
|
|||
.setAttributes(Attributes.builder().put("key", "value").build())
|
||||
.setSeverity(Severity.INFO)
|
||||
.setSeverityText(Severity.INFO.name())
|
||||
.setEpoch(Instant.now())
|
||||
.setTimestamp(Instant.now())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -534,7 +534,7 @@ abstract class OtlpExporterIntegrationTest {
|
|||
.setAllAttributes(Attributes.builder().put("key", "value").build())
|
||||
.setSeverity(Severity.DEBUG)
|
||||
.setSeverityText("DEBUG")
|
||||
.setEpoch(Instant.now())
|
||||
.setTimestamp(Instant.now())
|
||||
.setContext(Context.current())
|
||||
.emit();
|
||||
eventEmitter.emit("event-name", Attributes.builder().put("key", "value").build());
|
||||
|
|
|
|||
|
|
@ -57,16 +57,16 @@ public class LogRecordDataAssert extends AbstractAssert<LogRecordDataAssert, Log
|
|||
return this;
|
||||
}
|
||||
|
||||
/** Asserts the log has the given epoch timestamp. */
|
||||
public LogRecordDataAssert hasEpochNanos(long epochNanos) {
|
||||
/** Asserts the log has the given epoch {@code timestamp}. */
|
||||
public LogRecordDataAssert hasTimestamp(long timestampEpochNanos) {
|
||||
isNotNull();
|
||||
if (actual.getEpochNanos() != epochNanos) {
|
||||
if (actual.getTimestampEpochNanos() != timestampEpochNanos) {
|
||||
failWithActualExpectedAndMessage(
|
||||
actual.getEpochNanos(),
|
||||
epochNanos,
|
||||
"Expected log to have epoch <%s> nanos but was <%s>",
|
||||
epochNanos,
|
||||
actual.getEpochNanos());
|
||||
actual.getTimestampEpochNanos(),
|
||||
timestampEpochNanos,
|
||||
"Expected log to have timestamp <%s> nanos but was <%s>",
|
||||
timestampEpochNanos,
|
||||
actual.getTimestampEpochNanos());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public abstract class TestLogRecordData implements LogRecordData {
|
|||
return new AutoValue_TestLogRecordData.Builder()
|
||||
.setResource(Resource.empty())
|
||||
.setInstrumentationScopeInfo(InstrumentationScopeInfo.empty())
|
||||
.setEpoch(0, TimeUnit.NANOSECONDS)
|
||||
.setTimestamp(0, TimeUnit.NANOSECONDS)
|
||||
.setSpanContext(SpanContext.getInvalid())
|
||||
.setSeverity(Severity.UNDEFINED_SEVERITY_NUMBER)
|
||||
.setBody("")
|
||||
|
|
@ -55,18 +55,31 @@ public abstract class TestLogRecordData implements LogRecordData {
|
|||
public abstract Builder setInstrumentationScopeInfo(
|
||||
InstrumentationScopeInfo instrumentationScopeInfo);
|
||||
|
||||
/** Set the epoch timestamp to the {@code instant}. */
|
||||
public Builder setEpoch(Instant instant) {
|
||||
return setEpochNanos(TimeUnit.SECONDS.toNanos(instant.getEpochSecond()) + instant.getNano());
|
||||
/**
|
||||
* Set the epoch {@code timestamp}, using the instant.
|
||||
*
|
||||
* <p>The {@code timestamp} is the time at which the log record occurred.
|
||||
*/
|
||||
public Builder setTimestamp(Instant instant) {
|
||||
return setTimestampEpochNanos(
|
||||
TimeUnit.SECONDS.toNanos(instant.getEpochSecond()) + instant.getNano());
|
||||
}
|
||||
|
||||
/** Set the epoch timestamp. */
|
||||
public Builder setEpoch(long timestamp, TimeUnit unit) {
|
||||
return setEpochNanos(unit.toNanos(timestamp));
|
||||
/**
|
||||
* Set the epoch {@code timestamp}, using the timestamp and unit.
|
||||
*
|
||||
* <p>The {@code timestamp} is the time at which the log record occurred.
|
||||
*/
|
||||
public Builder setTimestamp(long timestamp, TimeUnit unit) {
|
||||
return setTimestampEpochNanos(unit.toNanos(timestamp));
|
||||
}
|
||||
|
||||
/** Set the epoch timestamp in nanos. */
|
||||
abstract Builder setEpochNanos(long epochNanos);
|
||||
/**
|
||||
* Set the epoch {@code timestamp}.
|
||||
*
|
||||
* <p>The {@code timestamp} is the time at which the log record occurred.
|
||||
*/
|
||||
abstract Builder setTimestampEpochNanos(long epochNanos);
|
||||
|
||||
/** Set the span context. */
|
||||
public abstract Builder setSpanContext(SpanContext spanContext);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class LogAssertionsTest {
|
|||
TestLogRecordData.builder()
|
||||
.setResource(RESOURCE)
|
||||
.setInstrumentationScopeInfo(INSTRUMENTATION_SCOPE_INFO)
|
||||
.setEpoch(100, TimeUnit.NANOSECONDS)
|
||||
.setTimestamp(100, TimeUnit.NANOSECONDS)
|
||||
.setSpanContext(
|
||||
SpanContext.create(
|
||||
TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()))
|
||||
|
|
@ -64,7 +64,7 @@ public class LogAssertionsTest {
|
|||
assertThat(LOG_DATA)
|
||||
.hasResource(RESOURCE)
|
||||
.hasInstrumentationScope(INSTRUMENTATION_SCOPE_INFO)
|
||||
.hasEpochNanos(100)
|
||||
.hasTimestamp(100)
|
||||
.hasSpanContext(
|
||||
SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()))
|
||||
.hasSeverity(Severity.INFO)
|
||||
|
|
@ -132,7 +132,7 @@ public class LogAssertionsTest {
|
|||
assertThatThrownBy(() -> assertThat(LOG_DATA).hasResource(Resource.empty()));
|
||||
assertThatThrownBy(
|
||||
() -> assertThat(LOG_DATA).hasInstrumentationScope(InstrumentationScopeInfo.empty()));
|
||||
assertThatThrownBy(() -> assertThat(LOG_DATA).hasEpochNanos(200));
|
||||
assertThatThrownBy(() -> assertThat(LOG_DATA).hasTimestamp(200));
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
assertThat(LOG_DATA)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ final class SdkLogRecordBuilder implements LogRecordBuilder {
|
|||
private final LogLimits logLimits;
|
||||
|
||||
private final InstrumentationScopeInfo instrumentationScopeInfo;
|
||||
private long epochNanos;
|
||||
private long timestampEpochNanos;
|
||||
@Nullable private Context context;
|
||||
private Severity severity = Severity.UNDEFINED_SEVERITY_NUMBER;
|
||||
@Nullable private String severityText;
|
||||
|
|
@ -39,14 +39,15 @@ final class SdkLogRecordBuilder implements LogRecordBuilder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SdkLogRecordBuilder setEpoch(long timestamp, TimeUnit unit) {
|
||||
this.epochNanos = unit.toNanos(timestamp);
|
||||
public SdkLogRecordBuilder setTimestamp(long timestamp, TimeUnit unit) {
|
||||
this.timestampEpochNanos = unit.toNanos(timestamp);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdkLogRecordBuilder setEpoch(Instant instant) {
|
||||
this.epochNanos = TimeUnit.SECONDS.toNanos(instant.getEpochSecond()) + instant.getNano();
|
||||
public SdkLogRecordBuilder setTimestamp(Instant instant) {
|
||||
this.timestampEpochNanos =
|
||||
TimeUnit.SECONDS.toNanos(instant.getEpochSecond()) + instant.getNano();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +103,9 @@ final class SdkLogRecordBuilder implements LogRecordBuilder {
|
|||
loggerSharedState.getLogLimits(),
|
||||
loggerSharedState.getResource(),
|
||||
instrumentationScopeInfo,
|
||||
this.epochNanos == 0 ? this.loggerSharedState.getClock().now() : this.epochNanos,
|
||||
this.timestampEpochNanos == 0
|
||||
? this.loggerSharedState.getClock().now()
|
||||
: this.timestampEpochNanos,
|
||||
Span.fromContext(context).getSpanContext(),
|
||||
severity,
|
||||
severityText,
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public interface LogRecordData {
|
|||
/** Returns the instrumentation scope that generated this log. */
|
||||
InstrumentationScopeInfo getInstrumentationScopeInfo();
|
||||
|
||||
/** Returns the epoch timestamp in nanos when the log was recorded. */
|
||||
long getEpochNanos();
|
||||
/** Returns the timestamp at which the log record occurred, in epoch nanos. */
|
||||
long getTimestampEpochNanos();
|
||||
|
||||
/** Return the span context for this log, or {@link SpanContext#getInvalid()} if unset. */
|
||||
SpanContext getSpanContext();
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ class SdkLogRecordBuilderTest {
|
|||
|
||||
@Test
|
||||
void emit_AllFields() {
|
||||
Instant now = Instant.now();
|
||||
Instant timestamp = Instant.now();
|
||||
|
||||
String bodyStr = "body";
|
||||
String sevText = "sevText";
|
||||
Severity severity = Severity.DEBUG3;
|
||||
|
|
@ -69,8 +70,8 @@ class SdkLogRecordBuilderTest {
|
|||
TraceState.getDefault());
|
||||
|
||||
builder.setBody(bodyStr);
|
||||
builder.setEpoch(123, TimeUnit.SECONDS);
|
||||
builder.setEpoch(now);
|
||||
builder.setTimestamp(123, TimeUnit.SECONDS);
|
||||
builder.setTimestamp(timestamp);
|
||||
builder.setAttribute(null, null);
|
||||
builder.setAttribute(AttributeKey.stringKey("k1"), "v1");
|
||||
builder.setAllAttributes(Attributes.builder().put("k2", "v2").put("k3", "v3").build());
|
||||
|
|
@ -82,7 +83,7 @@ class SdkLogRecordBuilderTest {
|
|||
.hasResource(RESOURCE)
|
||||
.hasInstrumentationScope(SCOPE_INFO)
|
||||
.hasBody(bodyStr)
|
||||
.hasEpochNanos(TimeUnit.SECONDS.toNanos(now.getEpochSecond()) + now.getNano())
|
||||
.hasTimestamp(TimeUnit.SECONDS.toNanos(timestamp.getEpochSecond()) + timestamp.getNano())
|
||||
.hasAttributes(Attributes.builder().put("k1", "v1").put("k2", "v2").put("k3", "v3").build())
|
||||
.hasSpanContext(spanContext)
|
||||
.hasSeverity(severity)
|
||||
|
|
@ -101,7 +102,7 @@ class SdkLogRecordBuilderTest {
|
|||
.hasResource(RESOURCE)
|
||||
.hasInstrumentationScope(SCOPE_INFO)
|
||||
.hasBody(Body.empty().asString())
|
||||
.hasEpochNanos(10L)
|
||||
.hasTimestamp(10L)
|
||||
.hasAttributes(Attributes.empty())
|
||||
.hasSpanContext(SpanContext.getInvalid())
|
||||
.hasSeverity(Severity.UNDEFINED_SEVERITY_NUMBER);
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ class SdkLoggerProviderTest {
|
|||
sdkLoggerProvider
|
||||
.get("test")
|
||||
.logRecordBuilder()
|
||||
.setEpoch(100, TimeUnit.NANOSECONDS)
|
||||
.setTimestamp(100, TimeUnit.NANOSECONDS)
|
||||
.setContext(Span.wrap(spanContext).storeInContext(Context.root()))
|
||||
.setSeverity(Severity.DEBUG)
|
||||
.setSeverityText("debug")
|
||||
|
|
@ -260,7 +260,7 @@ class SdkLoggerProviderTest {
|
|||
assertThat(logRecordData.get())
|
||||
.hasResource(resource)
|
||||
.hasInstrumentationScope(InstrumentationScopeInfo.create("test"))
|
||||
.hasEpochNanos(100)
|
||||
.hasTimestamp(100)
|
||||
.hasSpanContext(spanContext)
|
||||
.hasSeverity(Severity.DEBUG)
|
||||
.hasSeverityText("debug")
|
||||
|
|
@ -347,7 +347,7 @@ class SdkLoggerProviderTest {
|
|||
.build();
|
||||
sdkLoggerProvider.loggerBuilder(null).build().logRecordBuilder().emit();
|
||||
assertThat(seenLogs.size()).isEqualTo(1);
|
||||
assertThat(seenLogs.get(0).toLogRecordData().getEpochNanos()).isEqualTo(now);
|
||||
assertThat(seenLogs.get(0).toLogRecordData().getTimestampEpochNanos()).isEqualTo(now);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class SdkLoggerTest {
|
|||
|
||||
// Have to test through the builder
|
||||
logRecordBuilder.emit();
|
||||
assertThat(seenLog.get().toLogRecordData()).hasBody("foo").hasEpochNanos(5);
|
||||
assertThat(seenLog.get().toLogRecordData()).hasBody("foo").hasTimestamp(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue