Update OTLP protobufs to v0.13.0-alpha (#4170)

and add documentation on how to update that dependency.
This commit is contained in:
John Watson 2022-02-12 10:33:38 -08:00 committed by GitHub
parent 34d75aa260
commit f7c52e181e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 134 additions and 136 deletions

View File

@ -21,24 +21,23 @@ used on Java 8 or higher.
## Building opentelemetry-java ## Building opentelemetry-java
Continuous integration builds the project, runs the tests, and runs multiple Continuous integration builds the project, runs the tests, and runs multiple types of static
types of static analysis. analysis.
1. Note: Currently, to run the full suite of tests, you'll need to be running a docker daemon. 1. Note: Currently, to run the full suite of tests, you'll need to be running a docker daemon. The
The tests that require docker are disabled if docker is not present. If you wish to run them, tests that require docker are disabled if docker is not present. If you wish to run them, you
you must run a local docker daemon. must run a local docker daemon.
2. Clone the repository 2. Clone the repository
`git clone https://github.com/open-telemetry/opentelemetry-java.git` `git clone https://github.com/open-telemetry/opentelemetry-java.git`
3. Run the following commands to build, run tests and most static analysis, and 3. Run the following commands to build, run tests and most static analysis, and check formatting:
check formatting:
`./gradlew build` `./gradlew build`
4. If you are a Windows user, use the alternate command mentioned below to run tests and 4. If you are a Windows user, use the alternate command mentioned below to run tests and check
check formatting: formatting:
`gradlew.bat` `gradlew.bat`
@ -51,37 +50,44 @@ with the `check` task.
$ ./gradlew check $ ./gradlew check
``` ```
Note: this gradle task will potentially generate changes to files in the `docs/apidiffs/current_vs_latest` Note: this gradle task will potentially generate changes to files in
the `docs/apidiffs/current_vs_latest`
directory. Please make sure to include any changes to these files in your pull request. directory. Please make sure to include any changes to these files in your pull request.
## PR Review ## PR Review
After you submit a PR, it will be reviewed by the project maintainers and approvers. Not all maintainers need to review a
particular PR, but merging to the base branch is authorized to restricted members (administrators). After you submit a PR, it will be reviewed by the project maintainers and approvers. Not all
maintainers need to review a particular PR, but merging to the base branch is authorized to
restricted members (administrators).
## Style guideline ## Style guideline
We follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). We follow the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html). Our
Our build will fail if source code is not formatted according to that style. To fix any build will fail if source code is not formatted according to that style. To fix any style failures
style failures the above [checks](#checks) show, automatically apply the formatting with: the above [checks](#checks) show, automatically apply the formatting with:
```bash ```bash
$ ./gradlew spotlessApply $ ./gradlew spotlessApply
``` ```
To verify code style manually run the following command, To verify code style manually run the following command, which
which uses [google-java-format](https://github.com/google/google-java-format) library: uses [google-java-format](https://github.com/google/google-java-format) library:
`./gradlew spotlessCheck` `./gradlew spotlessCheck`
### Best practices that we follow ### Best practices that we follow
* This project uses [semantic versioning](https://semver.org/). Except for major versions, a user should be able to update * This project uses [semantic versioning](https://semver.org/). Except for major versions, a user
their dependency version on this project and have nothing break. This means we do not make breaking should be able to update their dependency version on this project and have nothing break. This
changes to the API (e.g., remove a public method) or to the ABI (e.g., change return type from void to non-void). means we do not make breaking changes to the API (e.g., remove a public method) or to the ABI (
e.g., change return type from void to non-void).
* Avoid exposing publicly any class/method/variable that don't need to be public. * Avoid exposing publicly any class/method/variable that don't need to be public.
* By default, all arguments/members are treated as non-null. Every argument/member that can be `null` must be annotated with `@Nullable`. * By default, all arguments/members are treated as non-null. Every argument/member that can
* The project aims to provide a consistent experience across all the public APIs. It is important to ensure consistency (same look and feel) across different public packages. be `null` must be annotated with `@Nullable`.
* Use `final` for public classes everywhere it is possible, this ensures that these classes cannot be extended when the API does not intend to offer that functionality. * The project aims to provide a consistent experience across all the public APIs. It is important to
ensure consistency (same look and feel) across different public packages.
* Use `final` for public classes everywhere it is possible, this ensures that these classes cannot
be extended when the API does not intend to offer that functionality.
* In general, we use the following ordering of class members: * In general, we use the following ordering of class members:
* Static fields (final before non-final) * Static fields (final before non-final)
* Instance fields (final before non-final) * Instance fields (final before non-final)
@ -89,53 +95,56 @@ changes to the API (e.g., remove a public method) or to the ABI (e.g., change re
* In static utility classes (where all members are static), the private constructor * In static utility classes (where all members are static), the private constructor
(used to prevent construction) should be ordered after methods instead of before methods. (used to prevent construction) should be ordered after methods instead of before methods.
* Methods * Methods
* If methods call each other, it's nice if the calling method is ordered (somewhere) above * If methods call each other, it's nice if the calling method is ordered (somewhere) above the
the method that it calls. So, for one example, a private method would be ordered (somewhere) below method that it calls. So, for one example, a private method would be ordered (somewhere) below
the non-private methods that use it. the non-private methods that use it.
* Nested classes * Nested classes
* Adding `toString()` overrides on classes is encouraged, but we only use `toString()` to provide debugging assistance. The implementations * Adding `toString()` overrides on classes is encouraged, but we only use `toString()` to provide
of all `toString()` methods should be considered to be unstable unless explicitly documented otherwise. debugging assistance. The implementations of all `toString()` methods should be considered to be
unstable unless explicitly documented otherwise.
If you notice any practice being applied in the project consistently that isn't listed here, please consider a pull request to add it. If you notice any practice being applied in the project consistently that isn't listed here, please
consider a pull request to add it.
### Pre-commit hook ### Pre-commit hook
To completely delegate code style formatting to the machine,
you can add [git pre-commit hook](https://git-scm.com/docs/githooks). To completely delegate code style formatting to the machine, you can
We provide an example script in `buildscripts/pre-commit` file. add [git pre-commit hook](https://git-scm.com/docs/githooks). We provide an example script
Just copy or symlink it into `.git/hooks` folder. in `buildscripts/pre-commit` file. Just copy or symlink it into `.git/hooks` folder.
### Editorconfig ### Editorconfig
As additional convenience for IntelliJ Idea users, we provide `.editorconfig` file.
Idea will automatically use it to adjust its code formatting settings. As additional convenience for IntelliJ Idea users, we provide `.editorconfig` file. Idea will
It does not support all required rules, so you still have to run `spotlessApply` from time to time. automatically use it to adjust its code formatting settings. It does not support all required rules,
so you still have to run `spotlessApply` from time to time.
### Javadoc ### Javadoc
* All public classes and their public and protected methods MUST have javadoc. * All public classes and their public and protected methods MUST have javadoc. It MUST be complete (
It MUST be complete (all params documented etc.) Everything else all params documented etc.) Everything else
(package-protected classes, private) MAY have javadoc, at the code writer's (package-protected classes, private) MAY have javadoc, at the code writer's whim. It does not have
whim. It does not have to be complete, and reviewers are not allowed to to be complete, and reviewers are not allowed to require or disallow it.
require or disallow it. * Each API element should have a `@since` tag specifying the minor version when it was released (or
* Each API element should have a `@since` tag specifying the minor version when the next minor version).
it was released (or the next minor version).
* There MUST be NO javadoc errors. * There MUST be NO javadoc errors.
* See [section *
7.3.1](https://google.github.io/styleguide/javaguide.html#s7.3.1-javadoc-exception-self-explanatory)
in the guide for exceptions to the Javadoc requirement. See [section 7.3.1](https://google.github.io/styleguide/javaguide.html#s7.3.1-javadoc-exception-self-explanatory)
* Reviewers may request documentation for any element that doesn't require in the guide for exceptions to the Javadoc requirement.
Javadoc, though the style of documentation is up to the author.
* Try to do the least amount of change when modifying existing documentation. * Reviewers may request documentation for any element that doesn't require Javadoc, though the style
Don't change the style unless you have a good reason. of documentation is up to the author.
* Try to do the least amount of change when modifying existing documentation. Don't change the style
unless you have a good reason.
* We do not use `@author` tags in our javadoc. * We do not use `@author` tags in our javadoc.
* Our javadoc is available via [javadoc.io}(https://javadoc.io/doc/io.opentelemetry/opentelemetry-api) * Our javadoc is available via [
javadoc.io}(https://javadoc.io/doc/io.opentelemetry/opentelemetry-api)
### AutoValue ### AutoValue
* Use [AutoValue](https://github.com/google/auto/tree/master/value), when * Use [AutoValue](https://github.com/google/auto/tree/master/value), when possible, for any new
possible, for any new value classes. Remember to add package-private value classes. Remember to add package-private constructors to all AutoValue classes to prevent
constructors to all AutoValue classes to prevent classes in other packages classes in other packages from extending them.
from extending them.
### Unit Tests ### Unit Tests
@ -145,35 +154,41 @@ It does not support all required rules, so you still have to run `spotlessApply`
### Updating the Snapshot build number ### Updating the Snapshot build number
The overall version number for opentelemetry-java is determined from git tags, and not fixed in any file. The overall version number for opentelemetry-java is determined from git tags, and not fixed in any
file.
This means it will not update, even if you `git pull` from the repo tip. It will still produce a set of libraries with the old version number. This means it will not update, even if you `git pull` from the repo tip. It will still produce a set
of libraries with the old version number.
To update it, you must fetch the tags, via `git fetch --all --tags` - which should work, even if you have forked the repo, as long as the trunk repo is set as an upstream remote. To update it, you must fetch the tags, via `git fetch --all --tags` - which should work, even if you
have forked the repo, as long as the trunk repo is set as an upstream remote.
### Updating OTLP proto dependency version ### Updating OTLP proto dependency version
The OTLP proto dependency version is defined [here](proto/build.gradle). To bump the version, The OTLP proto dependency version is defined [here](proto/build.gradle). To bump the version,
1. Find the latest release version [here](https://github.com/open-telemetry/opentelemetry-proto/releases/latest) 1. Find the latest release
version [here](https://github.com/open-telemetry/opentelemetry-proto/releases/latest)
2. Download the zip source code archive 2. Download the zip source code archive
3. Run `shasum -a 256 ~/path/to/downloaded.zip` to compute its checksum 3. Run `shasum -a 256 ~/path/to/downloaded.zip` to compute its checksum
4. Update `protoVersion` and `protoChecksum` in the build file with the new version and checksum 4. Update `protoVersion` and `protoChecksum` in the build file with the new version and checksum
### Composing builds ### Composing builds
Beware that this section is only meant for developers of opentelemetry-java, or closely related projects. Beware that this section is only meant for developers of opentelemetry-java, or closely related
The steps described here could change at any time and what you do for one version (commit) may break projects. The steps described here could change at any time and what you do for one version (commit)
with the next one already. may break with the next one already.
Gradle provides a feature called ["composite builds"](https://docs.gradle.org/current/userguide/composite_builds.html) Gradle provides a feature
called ["composite builds"](https://docs.gradle.org/current/userguide/composite_builds.html)
that allows to replace some normally externally provided dependencies with a project that is built that allows to replace some normally externally provided dependencies with a project that is built
(included) in the same Gradle invocation. This can be useful to quickly test a new feature or bug fix you are (included) in the same Gradle invocation. This can be useful to quickly test a new feature or bug
developing in opentelemetry-java with the examples or the app or instrumentation library where you fix you are developing in opentelemetry-java with the examples or the app or instrumentation library
need the feature or run into the bug. Unfortunately, opentelemetry-java does not work out of the box where you need the feature or run into the bug. Unfortunately, opentelemetry-java does not work out
with this feature because Gradle is unable to map the project names to the customized artifact of the box with this feature because Gradle is unable to map the project names to the customized
coordinates (see e.g. [gradle/gradle#18291](https://github.com/gradle/gradle/issues/18291) artifact coordinates (see e.g. [gradle/gradle#18291](https://github.com/gradle/gradle/issues/18291)
and related issues. However, gradle supports manually declaring the mapping between ("substitution of") and related issues. However, gradle supports manually declaring the mapping between ("substitution
of")
artifact coordinates and project names. To ease this tedious task, opentelemetry-java provides a artifact coordinates and project names. To ease this tedious task, opentelemetry-java provides a
gradle task `:generateBuildSubstitutions` that generates a code snippet with these substitutions in gradle task `:generateBuildSubstitutions` that generates a code snippet with these substitutions in
kts (Kotlin Script) format. kts (Kotlin Script) format.
@ -200,6 +215,18 @@ Example usage could be as follows:
See [the Gradle documentation](https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions) See [the Gradle documentation](https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions)
for more information. for more information.
4. If you now build your project, it will use the included build to supply the opentelemetry-java artifacts, 4. If you now build your project, it will use the included build to supply the opentelemetry-java
ignoring any version declarations. Use the prefix `:DIRECTORY:` to refer to tasks/projects within artifacts, ignoring any version declarations. Use the prefix `:DIRECTORY:` to refer to
the included build, where DIRECTORY is the name of the directory in the included build (only the part after the last `/`). tasks/projects within the included build, where DIRECTORY is the name of the directory in the
included build (only the part after the last `/`).
### Updating the OTLP protobufs
OTLP protobuf Java bindings are published via
the [opentelemetry-proto-java](https://github.com/open-telemetry/opentelemetry-proto-java)
repository. This project does not use the java bindings, but does use the `.proto` files that are
published in the binding jar by that project.
To update the OTLP protobuf version,
first [release a new version of the java bindings](https://github.com/open-telemetry/opentelemetry-proto-java/blob/main/RELEASING.md)
then simply update the dependency version that this project has on that jar.

View File

@ -87,7 +87,7 @@ val DEPENDENCIES = listOf(
"eu.rekawek.toxiproxy:toxiproxy-java:2.1.5", "eu.rekawek.toxiproxy:toxiproxy-java:2.1.5",
"io.github.netmikey.logunit:logunit-jul:1.1.3", "io.github.netmikey.logunit:logunit-jul:1.1.3",
"io.jaegertracing:jaeger-client:1.8.0", "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", "io.opentracing:opentracing-api:0.33.0",
"junit:junit:4.13.2", "junit:junit:4.13.2",
"nl.jqno.equalsverifier:equalsverifier:3.9", "nl.jqno.equalsverifier:equalsverifier:3.9",

View File

@ -87,6 +87,7 @@ class OtlpJsonLoggingLogExporterTest {
assertThat(logs.getEvents()) assertThat(logs.getEvents())
.hasSize(1) .hasSize(1)
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
String message = logs.getEvents().get(0).getMessage();
JSONAssert.assertEquals( JSONAssert.assertEquals(
"{\n" "{\n"
+ " \"resource\":{\n" + " \"resource\":{\n"
@ -105,7 +106,7 @@ class OtlpJsonLoggingLogExporterTest {
+ " \"name\":\"instrumentation2\",\n" + " \"name\":\"instrumentation2\",\n"
+ " \"version\":\"2\"\n" + " \"version\":\"2\"\n"
+ " },\n" + " },\n"
+ " \"logs\":[\n" + " \"logRecords\":[\n"
+ " {\n" + " {\n"
+ " \"timeUnixNano\":\"1631533710000000\",\n" + " \"timeUnixNano\":\"1631533710000000\",\n"
+ " \"severityNumber\":\"SEVERITY_NUMBER_INFO\",\n" + " \"severityNumber\":\"SEVERITY_NUMBER_INFO\",\n"
@ -132,7 +133,7 @@ class OtlpJsonLoggingLogExporterTest {
+ " \"name\":\"instrumentation\",\n" + " \"name\":\"instrumentation\",\n"
+ " \"version\":\"1\"\n" + " \"version\":\"1\"\n"
+ " },\n" + " },\n"
+ " \"logs\":[\n" + " \"logRecords\":[\n"
+ " {\n" + " {\n"
+ " \"timeUnixNano\":\"1631533710000000\",\n" + " \"timeUnixNano\":\"1631533710000000\",\n"
+ " \"severityNumber\":\"SEVERITY_NUMBER_INFO\",\n" + " \"severityNumber\":\"SEVERITY_NUMBER_INFO\",\n"
@ -162,9 +163,9 @@ class OtlpJsonLoggingLogExporterTest {
+ " }\n" + " }\n"
+ " ]\n" + " ]\n"
+ "}", + "}",
logs.getEvents().get(0).getMessage(), message,
/* strict= */ false); /* strict= */ false);
assertThat(logs.getEvents().get(0).getMessage()).doesNotContain("\n"); assertThat(message).doesNotContain("\n");
} }
@Test @Test

View File

@ -101,6 +101,7 @@ class OtlpJsonLoggingSpanExporterTest {
assertThat(logs.getEvents()) assertThat(logs.getEvents())
.hasSize(1) .hasSize(1)
.allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO));
String message = logs.getEvents().get(0).getMessage();
JSONAssert.assertEquals( JSONAssert.assertEquals(
"{" "{"
+ " \"resource\": {" + " \"resource\": {"
@ -124,7 +125,6 @@ class OtlpJsonLoggingSpanExporterTest {
+ " \"startTimeUnixNano\": \"500\"," + " \"startTimeUnixNano\": \"500\","
+ " \"endTimeUnixNano\": \"1501\"," + " \"endTimeUnixNano\": \"1501\","
+ " \"status\": {" + " \"status\": {"
+ " \"deprecatedCode\": \"DEPRECATED_STATUS_CODE_UNKNOWN_ERROR\","
+ " \"code\": \"STATUS_CODE_ERROR\"" + " \"code\": \"STATUS_CODE_ERROR\""
+ " }" + " }"
+ " }]" + " }]"
@ -167,9 +167,9 @@ class OtlpJsonLoggingSpanExporterTest {
+ " }]" + " }]"
+ " }]" + " }]"
+ "}", + "}",
logs.getEvents().get(0).getMessage(), message,
/* strict= */ false); /* strict= */ false);
assertThat(logs.getEvents().get(0).getMessage()).doesNotContain("\n"); assertThat(message).doesNotContain("\n");
} }
@Test @Test

View File

@ -33,7 +33,7 @@ final class InstrumentationLibraryLogsMarshaler extends MarshalerWithSize {
public void writeTo(Serializer output) throws IOException { public void writeTo(Serializer output) throws IOException {
output.serializeMessage( output.serializeMessage(
InstrumentationLibraryLogs.INSTRUMENTATION_LIBRARY, instrumentationLibrary); InstrumentationLibraryLogs.INSTRUMENTATION_LIBRARY, instrumentationLibrary);
output.serializeRepeatedMessage(InstrumentationLibraryLogs.LOGS, logMarshalers); output.serializeRepeatedMessage(InstrumentationLibraryLogs.LOG_RECORDS, logMarshalers);
output.serializeString(InstrumentationLibraryLogs.SCHEMA_URL, schemaUrlUtf8); output.serializeString(InstrumentationLibraryLogs.SCHEMA_URL, schemaUrlUtf8);
} }
@ -46,7 +46,8 @@ final class InstrumentationLibraryLogsMarshaler extends MarshalerWithSize {
MarshalerUtil.sizeMessage( MarshalerUtil.sizeMessage(
InstrumentationLibraryLogs.INSTRUMENTATION_LIBRARY, instrumentationLibrary); InstrumentationLibraryLogs.INSTRUMENTATION_LIBRARY, instrumentationLibrary);
size += MarshalerUtil.sizeBytes(InstrumentationLibraryLogs.SCHEMA_URL, schemaUrlUtf8); size += MarshalerUtil.sizeBytes(InstrumentationLibraryLogs.SCHEMA_URL, schemaUrlUtf8);
size += MarshalerUtil.sizeRepeatedMessage(InstrumentationLibraryLogs.LOGS, logMarshalers); size +=
MarshalerUtil.sizeRepeatedMessage(InstrumentationLibraryLogs.LOG_RECORDS, logMarshalers);
return size; return size;
} }
} }

View File

@ -16,41 +16,33 @@ import java.io.IOException;
final class SpanStatusMarshaler extends MarshalerWithSize { final class SpanStatusMarshaler extends MarshalerWithSize {
private final ProtoEnumInfo protoStatusCode; private final ProtoEnumInfo protoStatusCode;
private final ProtoEnumInfo deprecatedStatusCode;
private final byte[] descriptionUtf8; private final byte[] descriptionUtf8;
static SpanStatusMarshaler create(StatusData status) { static SpanStatusMarshaler create(StatusData status) {
ProtoEnumInfo protoStatusCode = Status.StatusCode.STATUS_CODE_UNSET; ProtoEnumInfo protoStatusCode = Status.StatusCode.STATUS_CODE_UNSET;
ProtoEnumInfo deprecatedStatusCode = Status.DeprecatedStatusCode.DEPRECATED_STATUS_CODE_OK;
if (status.getStatusCode() == StatusCode.OK) { if (status.getStatusCode() == StatusCode.OK) {
protoStatusCode = Status.StatusCode.STATUS_CODE_OK; protoStatusCode = Status.StatusCode.STATUS_CODE_OK;
} else if (status.getStatusCode() == StatusCode.ERROR) { } else if (status.getStatusCode() == StatusCode.ERROR) {
protoStatusCode = Status.StatusCode.STATUS_CODE_ERROR; protoStatusCode = Status.StatusCode.STATUS_CODE_ERROR;
deprecatedStatusCode = Status.DeprecatedStatusCode.DEPRECATED_STATUS_CODE_UNKNOWN_ERROR;
} }
byte[] description = MarshalerUtil.toBytes(status.getDescription()); byte[] description = MarshalerUtil.toBytes(status.getDescription());
return new SpanStatusMarshaler(protoStatusCode, deprecatedStatusCode, description); return new SpanStatusMarshaler(protoStatusCode, description);
} }
private SpanStatusMarshaler( private SpanStatusMarshaler(ProtoEnumInfo protoStatusCode, byte[] descriptionUtf8) {
ProtoEnumInfo protoStatusCode, ProtoEnumInfo deprecatedStatusCode, byte[] descriptionUtf8) { super(computeSize(protoStatusCode, descriptionUtf8));
super(computeSize(protoStatusCode, deprecatedStatusCode, descriptionUtf8));
this.protoStatusCode = protoStatusCode; this.protoStatusCode = protoStatusCode;
this.deprecatedStatusCode = deprecatedStatusCode;
this.descriptionUtf8 = descriptionUtf8; this.descriptionUtf8 = descriptionUtf8;
} }
@Override @Override
public void writeTo(Serializer output) throws IOException { public void writeTo(Serializer output) throws IOException {
output.serializeEnum(Status.DEPRECATED_CODE, deprecatedStatusCode);
output.serializeString(Status.MESSAGE, descriptionUtf8); output.serializeString(Status.MESSAGE, descriptionUtf8);
output.serializeEnum(Status.CODE, protoStatusCode); output.serializeEnum(Status.CODE, protoStatusCode);
} }
private static int computeSize( private static int computeSize(ProtoEnumInfo protoStatusCode, byte[] descriptionUtf8) {
ProtoEnumInfo protoStatusCode, ProtoEnumInfo deprecatedStatusCode, byte[] descriptionUtf8) {
int size = 0; int size = 0;
size += MarshalerUtil.sizeEnum(Status.DEPRECATED_CODE, deprecatedStatusCode);
size += MarshalerUtil.sizeBytes(Status.MESSAGE, descriptionUtf8); size += MarshalerUtil.sizeBytes(Status.MESSAGE, descriptionUtf8);
size += MarshalerUtil.sizeEnum(Status.CODE, protoStatusCode); size += MarshalerUtil.sizeEnum(Status.CODE, protoStatusCode);
return size; return size;

View File

@ -178,7 +178,7 @@ class LogsRequestMarshalerTest {
ResourceLogs.Builder fixed = (ResourceLogs.Builder) builder; ResourceLogs.Builder fixed = (ResourceLogs.Builder) builder;
for (InstrumentationLibraryLogs.Builder ill : for (InstrumentationLibraryLogs.Builder ill :
fixed.getInstrumentationLibraryLogsBuilderList()) { fixed.getInstrumentationLibraryLogsBuilderList()) {
for (LogRecord.Builder span : ill.getLogsBuilderList()) { for (LogRecord.Builder span : ill.getLogRecordsBuilderList()) {
fixSpanJsonIds(span); fixSpanJsonIds(span);
} }
} }

View File

@ -7,8 +7,6 @@ package io.opentelemetry.exporter.internal.otlp.traces;
import static io.opentelemetry.api.common.AttributeKey.stringKey; 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.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_ERROR;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_OK; import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_OK;
import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_UNSET; import static io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_UNSET;
@ -229,45 +227,24 @@ class TraceRequestMarshalerTest {
} }
@Test @Test
@SuppressWarnings("deprecation")
// setDeprecatedCode is deprecated.
void toProtoStatus() { void toProtoStatus() {
assertThat(parse(Status.getDefaultInstance(), SpanStatusMarshaler.create(StatusData.unset()))) assertThat(parse(Status.getDefaultInstance(), SpanStatusMarshaler.create(StatusData.unset())))
.isEqualTo( .isEqualTo(Status.newBuilder().setCode(STATUS_CODE_UNSET).build());
Status.newBuilder()
.setCode(STATUS_CODE_UNSET)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_OK)
.build());
assertThat( assertThat(
parse( parse(
Status.getDefaultInstance(), Status.getDefaultInstance(),
SpanStatusMarshaler.create(StatusData.create(StatusCode.ERROR, "ERROR")))) SpanStatusMarshaler.create(StatusData.create(StatusCode.ERROR, "ERROR"))))
.isEqualTo( .isEqualTo(Status.newBuilder().setCode(STATUS_CODE_ERROR).setMessage("ERROR").build());
Status.newBuilder()
.setCode(STATUS_CODE_ERROR)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_UNKNOWN_ERROR)
.setMessage("ERROR")
.build());
assertThat( assertThat(
parse( parse(
Status.getDefaultInstance(), Status.getDefaultInstance(),
SpanStatusMarshaler.create(StatusData.create(StatusCode.ERROR, "UNKNOWN")))) SpanStatusMarshaler.create(StatusData.create(StatusCode.ERROR, "UNKNOWN"))))
.isEqualTo( .isEqualTo(Status.newBuilder().setCode(STATUS_CODE_ERROR).setMessage("UNKNOWN").build());
Status.newBuilder()
.setCode(STATUS_CODE_ERROR)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_UNKNOWN_ERROR)
.setMessage("UNKNOWN")
.build());
assertThat( assertThat(
parse( parse(
Status.getDefaultInstance(), Status.getDefaultInstance(),
SpanStatusMarshaler.create(StatusData.create(StatusCode.OK, "OK_OVERRIDE")))) SpanStatusMarshaler.create(StatusData.create(StatusCode.OK, "OK_OVERRIDE"))))
.isEqualTo( .isEqualTo(Status.newBuilder().setCode(STATUS_CODE_OK).setMessage("OK_OVERRIDE").build());
Status.newBuilder()
.setCode(STATUS_CODE_OK)
.setDeprecatedCode(DEPRECATED_STATUS_CODE_OK)
.setMessage("OK_OVERRIDE")
.build());
} }
@Test @Test

View File

@ -415,9 +415,9 @@ abstract class OtlpExporterIntegrationTest {
InstrumentationLibraryLogs ilLogs = resourceLogs.getInstrumentationLibraryLogs(0); InstrumentationLibraryLogs ilLogs = resourceLogs.getInstrumentationLibraryLogs(0);
assertThat(ilLogs.getInstrumentationLibrary().getName()) assertThat(ilLogs.getInstrumentationLibrary().getName())
.isEqualTo(OtlpExporterIntegrationTest.class.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.getName()).isEqualTo("log-name");
assertThat(protoLog.getBody().getStringValue()).isEqualTo("log body"); assertThat(protoLog.getBody().getStringValue()).isEqualTo("log body");
assertThat(protoLog.getAttributesList()) assertThat(protoLog.getAttributesList())

View File

@ -281,7 +281,7 @@ class FullConfigTest {
.setValue(AnyValue.newBuilder().setStringValue("meow").build()) .setValue(AnyValue.newBuilder().setStringValue("meow").build())
.build()); .build());
// MetricExporterCustomizer filters logs not whose level is less than Severity.INFO // 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.getBody().getStringValue()).isEqualTo("info log message");
assertThat(log.getSeverityNumberValue()).isEqualTo(Severity.INFO.getSeverityNumber()); assertThat(log.getSeverityNumberValue()).isEqualTo(Severity.INFO.getSeverityNumber());
} }