Deprecate log name field (#4160)

* Deprecate log name field

* Add deprecation description to javadoc
This commit is contained in:
jack-berg 2022-02-10 21:15:48 -06:00 committed by GitHub
parent 34273f43ca
commit 19b0fec813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 31 additions and 4 deletions

View File

@ -36,6 +36,7 @@ class OtlpJsonLoggingLogExporterTest {
private static final Resource RESOURCE = private static final Resource RESOURCE =
Resource.create(Attributes.builder().put("key", "value").build()); Resource.create(Attributes.builder().put("key", "value").build());
@SuppressWarnings("deprecation") // test deprecated setName method
private static final LogData LOG1 = private static final LogData LOG1 =
LogDataBuilder.create(RESOURCE, InstrumentationLibraryInfo.create("instrumentation", "1")) LogDataBuilder.create(RESOURCE, InstrumentationLibraryInfo.create("instrumentation", "1"))
.setName("testLog1") .setName("testLog1")
@ -52,6 +53,7 @@ class OtlpJsonLoggingLogExporterTest {
TraceState.getDefault())) TraceState.getDefault()))
.build(); .build();
@SuppressWarnings("deprecation") // test deprecated setName method
private static final LogData LOG2 = private static final LogData LOG2 =
LogDataBuilder.create(RESOURCE, InstrumentationLibraryInfo.create("instrumentation2", "2")) LogDataBuilder.create(RESOURCE, InstrumentationLibraryInfo.create("instrumentation2", "2"))
.setName("testLog2") .setName("testLog2")

View File

@ -330,6 +330,7 @@ class OtlpHttpLogExporterTest {
return HttpResponse.of(httpStatus, APPLICATION_PROTOBUF, message.toByteArray()); return HttpResponse.of(httpStatus, APPLICATION_PROTOBUF, message.toByteArray());
} }
@SuppressWarnings("deprecation") // test deprecated setName method
private static LogData generateFakeLog() { private static LogData generateFakeLog() {
return LogDataBuilder.create( return LogDataBuilder.create(
Resource.getDefault(), Resource.getDefault(),

View File

@ -36,6 +36,7 @@ final class LogMarshaler extends MarshalerWithSize {
@Nullable private final String traceId; @Nullable private final String traceId;
@Nullable private final String spanId; @Nullable private final String spanId;
@SuppressWarnings("deprecation") // name field to be removed
static LogMarshaler create(io.opentelemetry.sdk.logs.data.LogData logData) { static LogMarshaler create(io.opentelemetry.sdk.logs.data.LogData logData) {
KeyValueMarshaler[] attributeMarshalers = KeyValueMarshaler[] attributeMarshalers =
KeyValueMarshaler.createRepeated(logData.getAttributes()); KeyValueMarshaler.createRepeated(logData.getAttributes());

View File

@ -50,6 +50,7 @@ class LogsRequestMarshalerTest {
private static final String BODY = "Hello world from this log..."; private static final String BODY = "Hello world from this log...";
@Test @Test
@SuppressWarnings("deprecation") // test deprecated setName method
void toProtoResourceLogs() { void toProtoResourceLogs() {
ResourceLogsMarshaler[] resourceLogsMarshalers = ResourceLogsMarshaler[] resourceLogsMarshalers =
ResourceLogsMarshaler.create( ResourceLogsMarshaler.create(
@ -83,6 +84,7 @@ class LogsRequestMarshalerTest {
} }
@Test @Test
@SuppressWarnings("deprecation") // test deprecated setName method
void toProtoLogRecord() { void toProtoLogRecord() {
LogRecord logRecord = LogRecord logRecord =
parse( parse(

View File

@ -104,6 +104,7 @@ class OtlpGrpcLogExporterTest extends AbstractGrpcTelemetryExporterTest<LogData,
} }
@Override @Override
@SuppressWarnings("deprecation") // test deprecated setName method
protected LogData generateFakeTelemetry() { protected LogData generateFakeTelemetry() {
return LogDataBuilder.create( return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()), Resource.create(Attributes.builder().put("testKey", "testValue").build()),

View File

@ -105,6 +105,7 @@ class OtlpGrpcNettyLogExporterTest
} }
@Override @Override
@SuppressWarnings("deprecation") // test deprecated setName method
protected LogData generateFakeTelemetry() { protected LogData generateFakeTelemetry() {
return LogDataBuilder.create( return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()), Resource.create(Attributes.builder().put("testKey", "testValue").build()),

View File

@ -94,6 +94,7 @@ class OtlpGrpcNettyShadedLogExporterTest
} }
@Override @Override
@SuppressWarnings("deprecation") // test deprecated setName method
protected LogData generateFakeTelemetry() { protected LogData generateFakeTelemetry() {
return LogDataBuilder.create( return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()), Resource.create(Attributes.builder().put("testKey", "testValue").build()),

View File

@ -94,6 +94,7 @@ class OtlpGrpcNettyOkHttpLogExporterTest
} }
@Override @Override
@SuppressWarnings("deprecation") // test deprecated setName method
protected LogData generateFakeTelemetry() { protected LogData generateFakeTelemetry() {
return LogDataBuilder.create( return LogDataBuilder.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()), Resource.create(Attributes.builder().put("testKey", "testValue").build()),

View File

@ -373,6 +373,7 @@ abstract class OtlpExporterIntegrationTest {
testLogExporter(otlpHttpLogExporter); testLogExporter(otlpHttpLogExporter);
} }
@SuppressWarnings("deprecation") // test deprecated setName method
private static void testLogExporter(LogExporter logExporter) { private static void testLogExporter(LogExporter logExporter) {
LogData logData = LogData logData =
LogDataBuilder.create( LogDataBuilder.create(

View File

@ -114,6 +114,7 @@ public class LogDataAssert extends AbstractAssert<LogDataAssert, LogData> {
} }
/** Asserts the log has the given name. */ /** Asserts the log has the given name. */
@Deprecated
public LogDataAssert hasName(String name) { public LogDataAssert hasName(String name) {
isNotNull(); isNotNull();
if (!name.equals(actual.getName())) { if (!name.equals(actual.getName())) {
@ -149,7 +150,6 @@ public class LogDataAssert extends AbstractAssert<LogDataAssert, LogData> {
actual.getAttributes(), actual.getAttributes(),
attributes, attributes,
"Expected log to have attributes <%s> but was <%s>", "Expected log to have attributes <%s> but was <%s>",
actual.getName(),
attributes, attributes,
actual.getAttributes()); actual.getAttributes());
} }

View File

@ -43,6 +43,7 @@ public class LogAssertionsTest {
.put("coins", 0.01, 0.05, 0.1) .put("coins", 0.01, 0.05, 0.1)
.build(); .build();
@SuppressWarnings("deprecation") // test deprecated setName method
private static final LogData LOG_DATA = private static final LogData LOG_DATA =
LogDataBuilder.create(RESOURCE, INSTRUMENTATION_LIBRARY_INFO) LogDataBuilder.create(RESOURCE, INSTRUMENTATION_LIBRARY_INFO)
.setEpoch(100, TimeUnit.NANOSECONDS) .setEpoch(100, TimeUnit.NANOSECONDS)
@ -57,6 +58,7 @@ public class LogAssertionsTest {
.build(); .build();
@Test @Test
@SuppressWarnings("deprecation") // test deprecated hasName method
void passing() { void passing() {
assertThat(LOG_DATA) assertThat(LOG_DATA)
.hasResource(RESOURCE) .hasResource(RESOURCE)
@ -113,6 +115,7 @@ public class LogAssertionsTest {
} }
@Test @Test
@SuppressWarnings("deprecation") // test deprecated hasName method
void failure() { void failure() {
assertThatThrownBy(() -> assertThat(LOG_DATA).hasResource(Resource.empty())); assertThatThrownBy(() -> assertThat(LOG_DATA).hasResource(Resource.empty()));
assertThatThrownBy( assertThatThrownBy(

View File

@ -57,6 +57,7 @@ final class SdkLogBuilder implements LogBuilder {
} }
@Override @Override
@Deprecated
public LogBuilder setName(String name) { public LogBuilder setName(String name) {
logDataBuilder.setName(name); logDataBuilder.setName(name);
return this; return this;

View File

@ -39,7 +39,12 @@ public interface LogData {
@Nullable @Nullable
String getSeverityText(); String getSeverityText();
/** Returns the name for this log, or null if unset. */ /**
* Returns the name for this log, or null if unset.
*
* @deprecated will be removed without replacement.
*/
@Deprecated
@Nullable @Nullable
String getName(); String getName();

View File

@ -85,7 +85,12 @@ public final class LogDataBuilder {
return this; return this;
} }
/** Set the name. */ /**
* Set the name.
*
* @deprecated will be removed without replacement.
*/
@Deprecated
public LogDataBuilder setName(String name) { public LogDataBuilder setName(String name) {
this.name = name; this.name = name;
return this; return this;

View File

@ -14,7 +14,9 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
@AutoValue @AutoValue
@AutoValue.CopyAnnotations
@Immutable @Immutable
@SuppressWarnings("deprecation") // name field to be removed
abstract class LogDataImpl implements LogData { abstract class LogDataImpl implements LogData {
LogDataImpl() {} LogDataImpl() {}

View File

@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
class SdkLogBuilderTest { class SdkLogBuilderTest {
@Test @Test
@SuppressWarnings("deprecation") // test deprecated setName method
void buildAndEmit() { void buildAndEmit() {
Instant now = Instant.now(); Instant now = Instant.now();
String name = "skippy"; String name = "skippy";

View File

@ -22,7 +22,6 @@ public final class TestUtil {
.setEpoch(System.currentTimeMillis(), TimeUnit.MILLISECONDS) .setEpoch(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.setSeverity(severity) .setSeverity(severity)
.setSeverityText("really severe") .setSeverityText("really severe")
.setName("log1")
.setBody(message) .setBody(message)
.setAttributes(Attributes.builder().put("animal", "cat").build()) .setAttributes(Attributes.builder().put("animal", "cat").build())
.build(); .build();