Skip to content

Commit

Permalink
Update OTLP protobufs to v0.13.0-alpha (#4170)
Browse files Browse the repository at this point in the history
and add documentation on how to update that dependency.
  • Loading branch information
John Watson committed Feb 12, 2022
1 parent 34d75aa commit f7c52e1
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 137 deletions.
195 changes: 111 additions & 84 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ val DEPENDENCIES = listOf(
"eu.rekawek.toxiproxy:toxiproxy-java:2.1.5",
"io.github.netmikey.logunit:logunit-jul:1.1.3",
"io.jaegertracing:jaeger-client:1.8.0",
"io.opentelemetry.proto:opentelemetry-proto:0.11.0-alpha",
"io.opentelemetry.proto:opentelemetry-proto:0.13.0-alpha",
"io.opentracing:opentracing-api:0.33.0",
"junit:junit:4.13.2",
"nl.jqno.equalsverifier:equalsverifier:3.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void log() throws Exception {
assertThat(logs.getEvents())
.hasSize(1)
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
String message = logs.getEvents().get(0).getMessage();
JSONAssert.assertEquals(
"{\n"
+ " \"resource\":{\n"
Expand All @@ -105,7 +106,7 @@ void log() throws Exception {
+ " \"name\":\"instrumentation2\",\n"
+ " \"version\":\"2\"\n"
+ " },\n"
+ " \"logs\":[\n"
+ " \"logRecords\":[\n"
+ " {\n"
+ " \"timeUnixNano\":\"1631533710000000\",\n"
+ " \"severityNumber\":\"SEVERITY_NUMBER_INFO\",\n"
Expand All @@ -132,7 +133,7 @@ void log() throws Exception {
+ " \"name\":\"instrumentation\",\n"
+ " \"version\":\"1\"\n"
+ " },\n"
+ " \"logs\":[\n"
+ " \"logRecords\":[\n"
+ " {\n"
+ " \"timeUnixNano\":\"1631533710000000\",\n"
+ " \"severityNumber\":\"SEVERITY_NUMBER_INFO\",\n"
Expand Down Expand Up @@ -162,9 +163,9 @@ void log() throws Exception {
+ " }\n"
+ " ]\n"
+ "}",
logs.getEvents().get(0).getMessage(),
message,
/* strict= */ false);
assertThat(logs.getEvents().get(0).getMessage()).doesNotContain("\n");
assertThat(message).doesNotContain("\n");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void log() throws Exception {
assertThat(logs.getEvents())
.hasSize(1)
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
String message = logs.getEvents().get(0).getMessage();
JSONAssert.assertEquals(
"{"
+ " \"resource\": {"
Expand All @@ -124,7 +125,6 @@ void log() throws Exception {
+ " \"startTimeUnixNano\": \"500\","
+ " \"endTimeUnixNano\": \"1501\","
+ " \"status\": {"
+ " \"deprecatedCode\": \"DEPRECATED_STATUS_CODE_UNKNOWN_ERROR\","
+ " \"code\": \"STATUS_CODE_ERROR\""
+ " }"
+ " }]"
Expand Down Expand Up @@ -167,9 +167,9 @@ void log() throws Exception {
+ " }]"
+ " }]"
+ "}",
logs.getEvents().get(0).getMessage(),
message,
/* strict= */ false);
assertThat(logs.getEvents().get(0).getMessage()).doesNotContain("\n");
assertThat(message).doesNotContain("\n");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class InstrumentationLibraryLogsMarshaler extends MarshalerWithSize {
public void writeTo(Serializer output) throws IOException {
output.serializeMessage(
InstrumentationLibraryLogs.INSTRUMENTATION_LIBRARY, instrumentationLibrary);
output.serializeRepeatedMessage(InstrumentationLibraryLogs.LOGS, logMarshalers);
output.serializeRepeatedMessage(InstrumentationLibraryLogs.LOG_RECORDS, logMarshalers);
output.serializeString(InstrumentationLibraryLogs.SCHEMA_URL, schemaUrlUtf8);
}

Expand All @@ -46,7 +46,8 @@ private static int calculateSize(
MarshalerUtil.sizeMessage(
InstrumentationLibraryLogs.INSTRUMENTATION_LIBRARY, instrumentationLibrary);
size += MarshalerUtil.sizeBytes(InstrumentationLibraryLogs.SCHEMA_URL, schemaUrlUtf8);
size += MarshalerUtil.sizeRepeatedMessage(InstrumentationLibraryLogs.LOGS, logMarshalers);
size +=
MarshalerUtil.sizeRepeatedMessage(InstrumentationLibraryLogs.LOG_RECORDS, logMarshalers);
return size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,33 @@

final class SpanStatusMarshaler extends MarshalerWithSize {
private final ProtoEnumInfo protoStatusCode;
private final ProtoEnumInfo deprecatedStatusCode;
private final byte[] descriptionUtf8;

static SpanStatusMarshaler create(StatusData status) {
ProtoEnumInfo protoStatusCode = Status.StatusCode.STATUS_CODE_UNSET;
ProtoEnumInfo deprecatedStatusCode = Status.DeprecatedStatusCode.DEPRECATED_STATUS_CODE_OK;
if (status.getStatusCode() == StatusCode.OK) {
protoStatusCode = Status.StatusCode.STATUS_CODE_OK;
} else if (status.getStatusCode() == StatusCode.ERROR) {
protoStatusCode = Status.StatusCode.STATUS_CODE_ERROR;
deprecatedStatusCode = Status.DeprecatedStatusCode.DEPRECATED_STATUS_CODE_UNKNOWN_ERROR;
}
byte[] description = MarshalerUtil.toBytes(status.getDescription());
return new SpanStatusMarshaler(protoStatusCode, deprecatedStatusCode, description);
return new SpanStatusMarshaler(protoStatusCode, description);
}

private SpanStatusMarshaler(
ProtoEnumInfo protoStatusCode, ProtoEnumInfo deprecatedStatusCode, byte[] descriptionUtf8) {
super(computeSize(protoStatusCode, deprecatedStatusCode, descriptionUtf8));
private SpanStatusMarshaler(ProtoEnumInfo protoStatusCode, byte[] descriptionUtf8) {
super(computeSize(protoStatusCode, descriptionUtf8));
this.protoStatusCode = protoStatusCode;
this.deprecatedStatusCode = deprecatedStatusCode;
this.descriptionUtf8 = descriptionUtf8;
}

@Override
public void writeTo(Serializer output) throws IOException {
output.serializeEnum(Status.DEPRECATED_CODE, deprecatedStatusCode);
output.serializeString(Status.MESSAGE, descriptionUtf8);
output.serializeEnum(Status.CODE, protoStatusCode);
}

private static int computeSize(
ProtoEnumInfo protoStatusCode, ProtoEnumInfo deprecatedStatusCode, byte[] descriptionUtf8) {
private static int computeSize(ProtoEnumInfo protoStatusCode, byte[] descriptionUtf8) {
int size = 0;
size += MarshalerUtil.sizeEnum(Status.DEPRECATED_CODE, deprecatedStatusCode);
size += MarshalerUtil.sizeBytes(Status.MESSAGE, descriptionUtf8);
size += MarshalerUtil.sizeEnum(Status.CODE, protoStatusCode);
return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static <T extends Message> T parse(T prototype, Marshaler marshaler) {
ResourceLogs.Builder fixed = (ResourceLogs.Builder) builder;
for (InstrumentationLibraryLogs.Builder ill :
fixed.getInstrumentationLibraryLogsBuilderList()) {
for (LogRecord.Builder span : ill.getLogsBuilderList()) {
for (LogRecord.Builder span : ill.getLogRecordsBuilderList()) {
fixSpanJsonIds(span);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.proto.trace.v1.Span.SpanKind.SPAN_KIND_SERVER;
import static io.opentelemetry.proto.trace.v1.Status.DeprecatedStatusCode.DEPRECATED_STATUS_CODE_OK;
import static io.opentelemetry.proto.trace.v1.Status.DeprecatedStatusCode.DEPRECATED_STATUS_CODE_UNKNOWN_ERROR;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_ERROR;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_OK;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_UNSET;
Expand Down Expand Up @@ -229,45 +227,24 @@ void toProtoSpanKind() {
}

@Test
@SuppressWarnings("deprecation")
// setDeprecatedCode is deprecated.
void toProtoStatus() {
assertThat(parse(Status.getDefaultInstance(), SpanStatusMarshaler.create(StatusData.unset())))
.isEqualTo(
Status.newBuilder()
.setCode(STATUS_CODE_UNSET)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_OK)
.build());
.isEqualTo(Status.newBuilder().setCode(STATUS_CODE_UNSET).build());
assertThat(
parse(
Status.getDefaultInstance(),
SpanStatusMarshaler.create(StatusData.create(StatusCode.ERROR, "ERROR"))))
.isEqualTo(
Status.newBuilder()
.setCode(STATUS_CODE_ERROR)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_UNKNOWN_ERROR)
.setMessage("ERROR")
.build());
.isEqualTo(Status.newBuilder().setCode(STATUS_CODE_ERROR).setMessage("ERROR").build());
assertThat(
parse(
Status.getDefaultInstance(),
SpanStatusMarshaler.create(StatusData.create(StatusCode.ERROR, "UNKNOWN"))))
.isEqualTo(
Status.newBuilder()
.setCode(STATUS_CODE_ERROR)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_UNKNOWN_ERROR)
.setMessage("UNKNOWN")
.build());
.isEqualTo(Status.newBuilder().setCode(STATUS_CODE_ERROR).setMessage("UNKNOWN").build());
assertThat(
parse(
Status.getDefaultInstance(),
SpanStatusMarshaler.create(StatusData.create(StatusCode.OK, "OK_OVERRIDE"))))
.isEqualTo(
Status.newBuilder()
.setCode(STATUS_CODE_OK)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_OK)
.setMessage("OK_OVERRIDE")
.build());
.isEqualTo(Status.newBuilder().setCode(STATUS_CODE_OK).setMessage("OK_OVERRIDE").build());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ private static void testLogExporter(LogExporter logExporter) {
InstrumentationLibraryLogs ilLogs = resourceLogs.getInstrumentationLibraryLogs(0);
assertThat(ilLogs.getInstrumentationLibrary().getName())
.isEqualTo(OtlpExporterIntegrationTest.class.getName());
assertThat(ilLogs.getLogsCount()).isEqualTo(1);
assertThat(ilLogs.getLogRecordsCount()).isEqualTo(1);

io.opentelemetry.proto.logs.v1.LogRecord protoLog = ilLogs.getLogs(0);
io.opentelemetry.proto.logs.v1.LogRecord protoLog = ilLogs.getLogRecords(0);
assertThat(protoLog.getName()).isEqualTo("log-name");
assertThat(protoLog.getBody().getStringValue()).isEqualTo("log body");
assertThat(protoLog.getAttributesList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void configures() throws Exception {
.setValue(AnyValue.newBuilder().setStringValue("meow").build())
.build());
// MetricExporterCustomizer filters logs not whose level is less than Severity.INFO
LogRecord log = logRequest.getResourceLogs(0).getInstrumentationLibraryLogs(0).getLogs(0);
LogRecord log = logRequest.getResourceLogs(0).getInstrumentationLibraryLogs(0).getLogRecords(0);
assertThat(log.getBody().getStringValue()).isEqualTo("info log message");
assertThat(log.getSeverityNumberValue()).isEqualTo(Severity.INFO.getSeverityNumber());
}
Expand Down

0 comments on commit f7c52e1

Please sign in to comment.