From 89a0f045932108b24c138a62db5b32dfe3b0c844 Mon Sep 17 00:00:00 2001 From: "Spindler, Justin" Date: Thu, 4 Jan 2024 08:53:52 -0500 Subject: [PATCH] Revert to simple boolean to include unsampled spans --- .../opentelemetry-exporter-otlp.txt | 25 ++++++++++++++++++- .../opentelemetry-sdk-trace.txt | 4 +-- .../sdk/trace/export/BatchSpanProcessor.java | 9 +++---- .../export/BatchSpanProcessorBuilder.java | 14 +++++------ .../sdk/trace/export/SimpleSpanProcessor.java | 9 +++---- .../export/SimpleSpanProcessorBuilder.java | 15 +++++------ .../trace/export/BatchSpanProcessorTest.java | 2 +- .../trace/export/SimpleSpanProcessorTest.java | 6 ++--- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-otlp.txt b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-otlp.txt index df26146497b..93de493b25a 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-otlp.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-otlp.txt @@ -1,2 +1,25 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +***! MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setConnectTimeout(long, java.util.concurrent.TimeUnit) + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setConnectTimeout(java.time.Duration) + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder setHeaders(java.util.function.Supplier>) +***! MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setConnectTimeout(long, java.util.concurrent.TimeUnit) + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setConnectTimeout(java.time.Duration) + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder setHeaders(java.util.function.Supplier>) +***! MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setConnectTimeout(long, java.util.concurrent.TimeUnit) + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setConnectTimeout(java.time.Duration) + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder setHeaders(java.util.function.Supplier>) +***! MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder setHeaders(java.util.function.Supplier>) +***! MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder setHeaders(java.util.function.Supplier>) +***! MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + ---! REMOVED METHOD: PUBLIC(-) io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder setHeaders(java.util.function.Supplier>) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt index 6acb2beedf4..f03b01723c1 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt @@ -1,7 +1,7 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder setExportFilter(java.util.function.Predicate) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.BatchSpanProcessorBuilder setExportUnsampledSpans(boolean) *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.export.SimpleSpanProcessor (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.export.SimpleSpanProcessorBuilder builder(io.opentelemetry.sdk.trace.export.SpanExporter) @@ -9,4 +9,4 @@ Comparing source compatibility of against +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.SimpleSpanProcessor build() - +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.SimpleSpanProcessorBuilder setExportFilter(java.util.function.Predicate) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.trace.export.SimpleSpanProcessorBuilder setExportUnsampledSpans(boolean) diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessor.java index 6ba49b0d952..27f5572b966 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessor.java @@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; @@ -54,7 +53,7 @@ public final class BatchSpanProcessor implements SpanProcessor { AttributeKey.booleanKey("dropped"); private static final String SPAN_PROCESSOR_TYPE_VALUE = BatchSpanProcessor.class.getSimpleName(); - private final Predicate exportPredicate; + private final boolean exportUnsampledSpans; private final Worker worker; private final AtomicBoolean isShutdown = new AtomicBoolean(false); @@ -71,13 +70,13 @@ public static BatchSpanProcessorBuilder builder(SpanExporter spanExporter) { BatchSpanProcessor( SpanExporter spanExporter, - Predicate exportPredicate, + boolean exportUnsampledSpans, MeterProvider meterProvider, long scheduleDelayNanos, int maxQueueSize, int maxExportBatchSize, long exporterTimeoutNanos) { - this.exportPredicate = exportPredicate; + this.exportUnsampledSpans = exportUnsampledSpans; this.worker = new Worker( spanExporter, @@ -100,7 +99,7 @@ public boolean isStartRequired() { @Override public void onEnd(ReadableSpan span) { - if (span != null && exportPredicate.test(span)) { + if (span != null && (exportUnsampledSpans || span.getSpanContext().isSampled())) { worker.addSpan(span); } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorBuilder.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorBuilder.java index 49f46e83752..3e155bdfc5d 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorBuilder.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorBuilder.java @@ -9,10 +9,8 @@ import static java.util.Objects.requireNonNull; import io.opentelemetry.api.metrics.MeterProvider; -import io.opentelemetry.sdk.trace.ReadableSpan; import java.time.Duration; import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; /** Builder class for {@link BatchSpanProcessor}. */ public final class BatchSpanProcessorBuilder { @@ -27,7 +25,7 @@ public final class BatchSpanProcessorBuilder { static final int DEFAULT_EXPORT_TIMEOUT_MILLIS = 30_000; private final SpanExporter spanExporter; - private Predicate exportPredicate = span -> span.getSpanContext().isSampled(); + private boolean exportUnsampledSpans; private long scheduleDelayNanos = TimeUnit.MILLISECONDS.toNanos(DEFAULT_SCHEDULE_DELAY_MILLIS); private int maxQueueSize = DEFAULT_MAX_QUEUE_SIZE; private int maxExportBatchSize = DEFAULT_MAX_EXPORT_BATCH_SIZE; @@ -39,11 +37,11 @@ public final class BatchSpanProcessorBuilder { } /** - * Sets a {@link Predicate Predicate<ReadableSpan>} that filters the {@link ReadableSpan}s - * that are to be exported. If unset, defaults to exporting sampled spans. + * Sets whether unsampled spans should be exported. If unset, defaults to exporting only sampled + * spans. */ - public BatchSpanProcessorBuilder setExportFilter(Predicate exportPredicate) { - this.exportPredicate = requireNonNull(exportPredicate, "exportPredicate"); + public BatchSpanProcessorBuilder setExportUnsampledSpans(boolean exportUnsampledSpans) { + this.exportUnsampledSpans = exportUnsampledSpans; return this; } @@ -158,7 +156,7 @@ int getMaxExportBatchSize() { public BatchSpanProcessor build() { return new BatchSpanProcessor( spanExporter, - exportPredicate, + exportUnsampledSpans, meterProvider, scheduleDelayNanos, maxQueueSize, diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessor.java index 2db8fb5235f..aab5818ea17 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessor.java @@ -18,7 +18,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; @@ -37,7 +36,7 @@ public final class SimpleSpanProcessor implements SpanProcessor { private static final Logger logger = Logger.getLogger(SimpleSpanProcessor.class.getName()); private final SpanExporter spanExporter; - private final Predicate exportPredicate; + private final boolean exportUnsampledSpans; private final Set pendingExports = Collections.newSetFromMap(new ConcurrentHashMap<>()); private final AtomicBoolean isShutdown = new AtomicBoolean(false); @@ -62,9 +61,9 @@ public static SimpleSpanProcessorBuilder builder(SpanExporter exporter) { return new SimpleSpanProcessorBuilder(exporter); } - SimpleSpanProcessor(SpanExporter spanExporter, Predicate exportPredicate) { + SimpleSpanProcessor(SpanExporter spanExporter, boolean exportUnsampledSpans) { this.spanExporter = requireNonNull(spanExporter, "spanExporter"); - this.exportPredicate = exportPredicate; + this.exportUnsampledSpans = exportUnsampledSpans; } @Override @@ -79,7 +78,7 @@ public boolean isStartRequired() { @Override public void onEnd(ReadableSpan span) { - if (span != null && exportPredicate.test(span)) { + if (span != null && (exportUnsampledSpans || span.getSpanContext().isSampled())) { try { List spans = Collections.singletonList(span.toSpanData()); CompletableResultCode result = spanExporter.export(spans); diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorBuilder.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorBuilder.java index 841b3fa3621..76e5482cd9d 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorBuilder.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorBuilder.java @@ -7,24 +7,21 @@ import static java.util.Objects.requireNonNull; -import io.opentelemetry.sdk.trace.ReadableSpan; -import java.util.function.Predicate; - /** Builder class for {@link SimpleSpanProcessor}. */ public final class SimpleSpanProcessorBuilder { private final SpanExporter spanExporter; - private Predicate exportPredicate = span -> span.getSpanContext().isSampled(); + private boolean exportUnsampledSpans; SimpleSpanProcessorBuilder(SpanExporter spanExporter) { this.spanExporter = requireNonNull(spanExporter, "spanExporter"); } /** - * Sets a {@link Predicate Predicate<ReadableSpan>} that filters the {@link ReadableSpan}s - * that are to be exported. If unset, defaults to exporting sampled spans. + * Sets whether unsampled spans should be exported. If unset, defaults to exporting only sampled + * spans. */ - public SimpleSpanProcessorBuilder setExportFilter(Predicate exportPredicate) { - this.exportPredicate = requireNonNull(exportPredicate, "exportPredicate"); + public SimpleSpanProcessorBuilder setExportUnsampledSpans(boolean exportUnsampledSpans) { + this.exportUnsampledSpans = exportUnsampledSpans; return this; } @@ -34,6 +31,6 @@ public SimpleSpanProcessorBuilder setExportFilter(Predicate export * @return a new {@link SimpleSpanProcessor}. */ public SimpleSpanProcessor build() { - return new SimpleSpanProcessor(spanExporter, exportPredicate); + return new SimpleSpanProcessor(spanExporter, exportUnsampledSpans); } } diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorTest.java b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorTest.java index 3f2f4d6e54d..bc9cd24a408 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorTest.java +++ b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/BatchSpanProcessorTest.java @@ -528,7 +528,7 @@ void exportUnsampledSpans_recordOnly() { SdkTracerProvider.builder() .addSpanProcessor( BatchSpanProcessor.builder(waitingSpanExporter) - .setExportFilter(span -> true) + .setExportUnsampledSpans(true) .setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS) .build()) .setSampler(mockSampler) diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorTest.java b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorTest.java index 55888acd83b..9bcd195bb11 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorTest.java +++ b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/export/SimpleSpanProcessorTest.java @@ -110,7 +110,7 @@ void onEndSync_ExportUnsampledSpans_NotSampledSpan() { when(readableSpan.getSpanContext()).thenReturn(NOT_SAMPLED_SPAN_CONTEXT); when(readableSpan.toSpanData()).thenReturn(spanData); SpanProcessor simpleSpanProcessor = - SimpleSpanProcessor.builder(spanExporter).setExportFilter(span -> true).build(); + SimpleSpanProcessor.builder(spanExporter).setExportUnsampledSpans(true).build(); simpleSpanProcessor.onEnd(readableSpan); verify(spanExporter).export(Collections.singletonList(spanData)); } @@ -121,7 +121,7 @@ void onEndSync_ExportUnsampledSpans_SampledSpan() { when(readableSpan.getSpanContext()).thenReturn(SAMPLED_SPAN_CONTEXT); when(readableSpan.toSpanData()).thenReturn(spanData); SpanProcessor simpleSpanProcessor = - SimpleSpanProcessor.builder(spanExporter).setExportFilter(span -> true).build(); + SimpleSpanProcessor.builder(spanExporter).setExportUnsampledSpans(true).build(); simpleSpanProcessor.onEnd(readableSpan); verify(spanExporter).export(Collections.singletonList(spanData)); } @@ -172,7 +172,7 @@ void tracerSdk_ExportUnsampledSpans_NotSampledSpan() { SdkTracerProvider.builder() .addSpanProcessor( SimpleSpanProcessor.builder(waitingSpanExporter) - .setExportFilter(span -> true) + .setExportUnsampledSpans(true) .build()) .setSampler(mockSampler) .build();