Skip to content

Commit 91eb04a

Browse files
authored
Fix/upstream update disk buffering (#2694)
1 parent ec1966e commit 91eb04a

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
`java-platform`
33
}
44

5-
val otelInstrumentationVersion = "2.25.0-alpha"
5+
val otelInstrumentationVersion = "2.26.0-alpha"
66
val semconvVersion = "1.40.0"
77

88
javaPlatform {

disk-buffering/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ val protos by configurations.creating
1616

1717
dependencies {
1818
api("io.opentelemetry:opentelemetry-sdk")
19-
implementation("io.opentelemetry:opentelemetry-api-incubator")
2019
implementation("io.opentelemetry:opentelemetry-exporter-otlp-common")
2120
compileOnly("com.google.auto.value:auto-value-annotations")
2221
annotationProcessor("com.google.auto.value:auto-value")

disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/models/LogRecordDataImpl.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
import com.google.auto.value.AutoValue;
99
import io.opentelemetry.api.common.Attributes;
1010
import io.opentelemetry.api.common.Value;
11-
import io.opentelemetry.api.incubator.common.ExtendedAttributes;
1211
import io.opentelemetry.api.logs.Severity;
1312
import io.opentelemetry.api.trace.SpanContext;
1413
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
1514
import io.opentelemetry.sdk.logs.data.Body;
16-
import io.opentelemetry.sdk.logs.data.internal.ExtendedLogRecordData;
15+
import io.opentelemetry.sdk.logs.data.LogRecordData;
1716
import io.opentelemetry.sdk.resources.Resource;
1817
import javax.annotation.Nullable;
1918

2019
@AutoValue
21-
public abstract class LogRecordDataImpl implements ExtendedLogRecordData {
20+
public abstract class LogRecordDataImpl implements LogRecordData {
2221

2322
public static Builder builder() {
2423
return new AutoValue_LogRecordDataImpl.Builder();
@@ -30,14 +29,6 @@ public Body getBody() {
3029
return valueBody == null ? Body.empty() : Body.string(valueBody.asString());
3130
}
3231

33-
@Override
34-
public ExtendedAttributes getExtendedAttributes() {
35-
return ExtendedAttributes.builder().putAll(getAttributes()).build();
36-
}
37-
38-
// It's only deprecated in the incubating interface for extended attributes, which are not yet
39-
// supported in this module.
40-
@SuppressWarnings("deprecation")
4132
@Override
4233
public abstract Attributes getAttributes();
4334

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/IntegrationTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Collection;
4444
import java.util.Iterator;
4545
import java.util.List;
46+
import java.util.stream.Collectors;
4647
import org.junit.jupiter.api.AfterEach;
4748
import org.junit.jupiter.api.BeforeEach;
4849
import org.junit.jupiter.api.Test;
@@ -155,7 +156,7 @@ void verifyIntegration_defaultAutoDelete() throws InterruptedException {
155156

156157
assertThat(storedSpans).hasSize(2);
157158
assertThat(storedLogs).hasSize(2);
158-
assertThat(storedMetrics).hasSize(2);
159+
assertThat(filterTestMetrics(storedMetrics)).hasSize(2);
159160

160161
// Data is auto-deleted from disk
161162
assertDirectoryFileCount(spansDir, 0);
@@ -198,7 +199,7 @@ void verifyIntegration_withoutAutoDelete() throws InterruptedException {
198199

199200
assertThat(storedSpans).hasSize(2);
200201
assertThat(storedLogs).hasSize(2);
201-
assertThat(storedMetrics).hasSize(2);
202+
assertThat(filterTestMetrics(storedMetrics)).hasSize(2);
202203

203204
// Data stays on disk
204205
assertDirectoryFileCount(spansDir, 2);
@@ -253,7 +254,7 @@ void verifyIntegration_withoutAutoDelete_explicitRemove() throws InterruptedExce
253254

254255
assertThat(storedSpans).hasSize(2);
255256
assertThat(storedLogs).hasSize(2);
256-
assertThat(storedMetrics).hasSize(2);
257+
assertThat(filterTestMetrics(storedMetrics)).hasSize(2);
257258

258259
// Data explicitly cleared
259260
assertDirectoryFileCount(spansDir, 0);
@@ -284,6 +285,23 @@ private void createMetric() {
284285
clearInvocations(metricCallback);
285286
}
286287

288+
private static final String TEST_METRIC_INSTRUMENTATION_SCOPE_NAME = "MetricInstrumentationScope";
289+
290+
/**
291+
* Filters out upstream's self-instrumentation metrics (e.g. {@code
292+
* otel.sdk.metric_reader.collection.duration}) that {@link PeriodicMetricReader} automatically
293+
* records, returning only metrics from the test's instrumentation scope.
294+
*/
295+
private static List<MetricData> filterTestMetrics(List<MetricData> metrics) {
296+
return metrics.stream()
297+
.filter(
298+
m ->
299+
m.getInstrumentationScopeInfo()
300+
.getName()
301+
.equals(TEST_METRIC_INSTRUMENTATION_SCOPE_NAME))
302+
.collect(Collectors.toList());
303+
}
304+
287305
private static void assertDirectoryFileCount(File directory, int fileCount) {
288306
assertThat(directory).isDirectory();
289307
assertThat(directory.listFiles()).hasSize(fileCount);

noop-api/src/main/java/io/opentelemetry/contrib/noopapi/NoopTracerProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.opentelemetry.api.trace.TracerProvider;
1616
import io.opentelemetry.context.Context;
1717
import java.util.concurrent.TimeUnit;
18+
import javax.annotation.Nullable;
1819

1920
enum NoopTracerProvider implements TracerProvider {
2021
INSTANCE;
@@ -62,7 +63,7 @@ public SpanBuilder addLink(SpanContext spanContext, Attributes attributes) {
6263
}
6364

6465
@Override
65-
public SpanBuilder setAttribute(String key, String value) {
66+
public SpanBuilder setAttribute(String key, @Nullable String value) {
6667
return this;
6768
}
6869

@@ -82,7 +83,7 @@ public SpanBuilder setAttribute(String key, boolean value) {
8283
}
8384

8485
@Override
85-
public <T> SpanBuilder setAttribute(AttributeKey<T> key, T value) {
86+
public <T> SpanBuilder setAttribute(AttributeKey<T> key, @Nullable T value) {
8687
return this;
8788
}
8889

0 commit comments

Comments
 (0)