Skip to content

Commit

Permalink
Merge sdk logs testing (#5431)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored May 12, 2023
1 parent d5e715a commit d67faf2
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 87 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 52 additions & 1 deletion docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion exporters/logging-otlp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion exporters/logging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ dependencies {
implementation(project(":sdk-extensions:autoconfigure-spi"))

testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk:logs-testing"))
}
1 change: 0 additions & 1 deletion exporters/otlp/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 0 additions & 4 deletions exporters/otlp/logs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
1 change: 0 additions & 1 deletion exporters/otlp/testing-internal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
24 changes: 0 additions & 24 deletions sdk/logs-testing/build.gradle.kts

This file was deleted.

1 change: 0 additions & 1 deletion sdk/logs-testing/gradle.properties

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/logs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {

implementation(project(":api:events"))

testImplementation(project(":sdk:logs-testing"))
testImplementation(project(":sdk:testing"))

testImplementation("org.awaitility:awaitility")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,6 @@
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;
Expand Down Expand Up @@ -346,8 +345,7 @@ public void continuesIfExporterTimesOut() throws InterruptedException {
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;
})))
Expand All @@ -364,8 +362,7 @@ public void continuesIfExporterTimesOut() throws InterruptedException {
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;
})))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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;
Expand Down Expand Up @@ -55,6 +56,15 @@ public static EventDataAssert assertThat(@Nullable EventData eventData) {
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[])}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* 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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,9 +49,9 @@ void getFinishedLogItems() {
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
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d67faf2

Please sign in to comment.