Merge sdk logs testing (#5431)

This commit is contained in:
jack-berg 2023-05-12 15:59:12 -05:00 committed by GitHub
parent d5e715aaa8
commit d67faf2aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 91 additions and 87 deletions

View File

@ -246,7 +246,6 @@ dependency as follows, replacing `{{artifact-id}}` with the value from the "Arti
| [Log SDK](./sdk/logs) | OpenTelemetry log SDK | `opentelemetry-sdk-logs` | <!--VERSION_UNSTABLE-->1.26.0-alpha<!--/VERSION_UNSTABLE--> | [![Javadocs](https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-sdk-logs.svg)](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-logs) |
| [SDK Common](./sdk/common) | Shared SDK components | `opentelemetry-sdk-common` | <!--VERSION_STABLE-->1.26.0<!--/VERSION_STABLE--> | [![Javadocs](https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-sdk-common.svg)](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-common) |
| [SDK Testing](./sdk/testing) | Components for testing OpenTelemetry instrumentation | `opentelemetry-sdk-testing` | <!--VERSION_STABLE-->1.26.0<!--/VERSION_STABLE--> | [![Javadocs](https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-sdk-testing.svg)](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-testing) |
| [SDK Logs Testing](./sdk/logs-testing) | Components for testing OpenTelemetry logs | `opentelemetry-sdk-logs-testing` | <!--VERSION_UNSTABLE-->1.26.0-alpha<!--/VERSION_UNSTABLE--> | [![Javadocs](https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-sdk-logs-testing.svg)](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-logs-testing) |
### SDK Exporters

View File

@ -1,2 +1,53 @@
Comparing source compatibility of against
No changes.
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributes(io.opentelemetry.api.common.Attributes)
+++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributes(java.util.Map$Entry[])
+++ NEW ANNOTATION: java.lang.SafeVarargs
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributesSatisfying(java.util.function.Consumer)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributesSatisfying(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributesSatisfying(java.lang.Iterable)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasAttributesSatisfyingExactly(java.lang.Iterable)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasBody(java.lang.String)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasInstrumentationScope(io.opentelemetry.sdk.common.InstrumentationScopeInfo)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasObservedTimestamp(long)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasResource(io.opentelemetry.sdk.resources.Resource)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasSeverity(io.opentelemetry.api.logs.Severity)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasSeverityText(java.lang.String)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasSpanContext(io.opentelemetry.api.trace.SpanContext)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasTimestamp(long)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert hasTotalAttributeCount(int)
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.testing.assertj.LogRecordDataAssert assertThat(io.opentelemetry.sdk.logs.data.LogRecordData)
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.exporter.InMemoryLogRecordExporter (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.testing.exporter.InMemoryLogRecordExporter create()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.CompletableResultCode export(java.util.Collection)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.CompletableResultCode flush()
+++ NEW METHOD: PUBLIC(+) java.util.List getFinishedLogRecordItems()
+++ NEW METHOD: PUBLIC(+) void reset()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.CompletableResultCode shutdown()
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder builder()
+++ NEW CLASS: PUBLIC(+) ABSTRACT(+) STATIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW CONSTRUCTOR: PUBLIC(+) TestLogRecordData$Builder()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData build()
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setAttributes(io.opentelemetry.api.common.Attributes)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setBody(java.lang.String)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setInstrumentationScopeInfo(io.opentelemetry.sdk.common.InstrumentationScopeInfo)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setObservedTimestamp(java.time.Instant)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setObservedTimestamp(long, java.util.concurrent.TimeUnit)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setResource(io.opentelemetry.sdk.resources.Resource)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setSeverity(io.opentelemetry.api.logs.Severity)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setSeverityText(java.lang.String)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setSpanContext(io.opentelemetry.api.trace.SpanContext)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setTimestamp(java.time.Instant)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setTimestamp(long, java.util.concurrent.TimeUnit)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.testing.logs.TestLogRecordData$Builder setTotalAttributeCount(int)

View File

@ -19,7 +19,6 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-core")
testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
testImplementation("org.skyscreamer:jsonassert")
}

View File

@ -5,7 +5,7 @@
package io.opentelemetry.exporter.logging.otlp.internal;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter;
import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter;

View File

@ -16,5 +16,4 @@ dependencies {
implementation(project(":sdk-extensions:autoconfigure-spi"))
testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
}

View File

@ -29,7 +29,6 @@ dependencies {
testImplementation(project(":sdk:trace"))
testImplementation(project(":sdk:logs"))
testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
testImplementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation("com.google.protobuf:protobuf-java-util")

View File

@ -19,7 +19,6 @@ dependencies {
testImplementation("io.grpc:grpc-stub")
testImplementation(project(":exporters:otlp:testing-internal"))
testImplementation(project(":sdk:logs-testing"))
testImplementation("com.linecorp.armeria:armeria-junit5")
testImplementation("com.google.api.grpc:proto-google-common-protos")
@ -31,7 +30,6 @@ testing {
val testGrpcNetty by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":exporters:otlp:testing-internal"))
implementation(project(":sdk:logs-testing"))
implementation("io.grpc:grpc-netty")
implementation("io.grpc:grpc-stub")
@ -40,7 +38,6 @@ testing {
val testGrpcNettyShaded by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":exporters:otlp:testing-internal"))
implementation(project(":sdk:logs-testing"))
implementation("io.grpc:grpc-netty-shaded")
implementation("io.grpc:grpc-stub")
@ -49,7 +46,6 @@ testing {
val testGrpcOkhttp by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":exporters:otlp:testing-internal"))
implementation(project(":sdk:logs-testing"))
implementation("io.grpc:grpc-okhttp")
implementation("io.grpc:grpc-stub")

View File

@ -11,7 +11,6 @@ dependencies {
api(project(":sdk:metrics"))
api(project(":sdk:trace"))
api(project(":sdk:testing"))
api(project(":sdk:logs-testing"))
api(project(":exporters:otlp:all"))
api(project(":exporters:otlp:logs"))

View File

@ -1,24 +0,0 @@
plugins {
id("otel.java-conventions")
id("otel.publish-conventions")
}
description = "OpenTelemetry Logs SDK Testing utilities"
otelJava.moduleName.set("io.opentelemetry.sdk.logs.testing")
dependencies {
api(project(":api:all"))
api(project(":sdk:all"))
api(project(":sdk:logs"))
api(project(":sdk:testing"))
compileOnly("org.assertj:assertj-core")
compileOnly("junit:junit")
compileOnly("org.junit.jupiter:junit-jupiter-api")
annotationProcessor("com.google.auto.value:auto-value")
testImplementation(project(":sdk:logs-testing"))
testImplementation("junit:junit")
}

View File

@ -1 +0,0 @@
otel.release=alpha

View File

@ -1,20 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.sdk.testing.assertj;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import org.assertj.core.api.Assertions;
/** Test assertions for data heading to exporters within the Metrics SDK. */
public final class LogAssertions extends Assertions {
/** Returns an assertion for {@link LogRecordData}. */
public static LogRecordDataAssert assertThat(LogRecordData log) {
return new LogRecordDataAssert(log);
}
private LogAssertions() {}
}

View File

@ -1,9 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
@ParametersAreNonnullByDefault
package io.opentelemetry.sdk.testing.assertj;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -15,7 +15,7 @@ dependencies {
implementation(project(":api:events"))
testImplementation(project(":sdk:logs-testing"))
testImplementation(project(":sdk:testing"))
testImplementation("org.awaitility:awaitility")

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.logs;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.mockito.Mockito.when;
import io.opentelemetry.api.common.AttributeKey;

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.logs;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;

View File

@ -9,7 +9,6 @@ import static io.opentelemetry.api.common.AttributeKey.booleanArrayKey;
import static io.opentelemetry.api.common.AttributeKey.doubleArrayKey;
import static io.opentelemetry.api.common.AttributeKey.longArrayKey;
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.logs.export;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.awaitility.Awaitility.await;
@ -20,7 +20,6 @@ import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.testing.assertj.LogAssertions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -346,8 +345,7 @@ class BatchLogRecordProcessorTest {
when(mockLogRecordExporter.export(
argThat(
logs -> {
assertThat(logs)
.anySatisfy(log -> LogAssertions.assertThat(log).hasBody(LOG_MESSAGE_1));
assertThat(logs).anySatisfy(log -> assertThat(log).hasBody(LOG_MESSAGE_1));
exported.countDown();
return true;
})))
@ -364,8 +362,7 @@ class BatchLogRecordProcessorTest {
when(mockLogRecordExporter.export(
argThat(
logs -> {
assertThat(logs)
.anySatisfy(log -> LogAssertions.assertThat(log).hasBody(LOG_MESSAGE_2));
assertThat(logs).anySatisfy(log -> assertThat(log).hasBody(LOG_MESSAGE_2));
exportedAgain.countDown();
return true;
})))

View File

@ -5,7 +5,7 @@
package io.opentelemetry.sdk.logs.internal;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View File

@ -18,11 +18,17 @@ import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.assertj.core.api.AbstractAssert;
/** Test assertions for {@link LogRecordData}. */
public class LogRecordDataAssert extends AbstractAssert<LogRecordDataAssert, LogRecordData> {
protected LogRecordDataAssert(LogRecordData actual) {
/**
* Test assertions for {@link LogRecordData}.
*
* @since 1.27.0
*/
public final class LogRecordDataAssert extends AbstractAssert<LogRecordDataAssert, LogRecordData> {
LogRecordDataAssert(@Nullable LogRecordData actual) {
super(actual, LogRecordDataAssert.class);
}

View File

@ -7,6 +7,7 @@ package io.opentelemetry.sdk.testing.assertj;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.trace.data.EventData;
import io.opentelemetry.sdk.trace.data.SpanData;
@ -55,6 +56,15 @@ public final class OpenTelemetryAssertions extends Assertions {
return new EventDataAssert(eventData);
}
/**
* Returns an assertion for {@link LogRecordData}.
*
* @since 1.27.0
*/
public static LogRecordDataAssert assertThat(@Nullable LogRecordData log) {
return new LogRecordDataAssert(log);
}
/**
* Returns an attribute entry with a String value for use with {@link
* AttributesAssert#containsOnly(java.util.Map.Entry[])}.

View File

@ -17,6 +17,8 @@ import java.util.concurrent.ConcurrentLinkedQueue;
/**
* A {@link LogRecordExporter} implementation that can be used to test OpenTelemetry integration.
*
* @since 1.27.0
*/
public final class InMemoryLogRecordExporter implements LogRecordExporter {
private final Queue<LogRecordData> finishedLogItems = new ConcurrentLinkedQueue<>();

View File

@ -17,7 +17,11 @@ import java.time.Instant;
import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.Immutable;
/** Immutable representation of {@link LogRecordData}. */
/**
* Immutable representation of {@link LogRecordData}.
*
* @since 1.27.0
*/
@Immutable
@AutoValue
public abstract class TestLogRecordData implements LogRecordData {

View File

@ -6,7 +6,7 @@
package io.opentelemetry.sdk.testing.assertj;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

View File

@ -6,13 +6,12 @@
package io.opentelemetry.sdk.testing.exporter;
import static io.opentelemetry.api.logs.Severity.DEBUG;
import static org.assertj.core.api.Assertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
import io.opentelemetry.sdk.testing.assertj.LogAssertions;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.util.Collections;
import java.util.List;
@ -50,9 +49,9 @@ class InMemoryLogRecordExporterTest {
List<LogRecordData> logItems = exporter.getFinishedLogRecordItems();
assertThat(logItems).isNotNull();
assertThat(logItems.size()).isEqualTo(3);
LogAssertions.assertThat(logItems.get(0)).hasBody("message 1");
LogAssertions.assertThat(logItems.get(1)).hasBody("message 2");
LogAssertions.assertThat(logItems.get(2)).hasBody("message 3");
assertThat(logItems.get(0)).hasBody("message 1");
assertThat(logItems.get(1)).hasBody("message 2");
assertThat(logItems.get(2)).hasBody("message 3");
}
@Test

View File

@ -53,7 +53,6 @@ include(":perf-harness")
include(":sdk:all")
include(":sdk:common")
include(":sdk:logs")
include(":sdk:logs-testing")
include(":sdk:metrics")
include(":sdk:testing")
include(":sdk:trace")