diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-logging-otlp.txt b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-logging-otlp.txt index 77422214df7..5937a3fe47a 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-logging-otlp.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-logging-otlp.txt @@ -1,2 +1,10 @@ Comparing source compatibility of opentelemetry-exporter-logging-otlp-1.55.0-SNAPSHOT.jar against opentelemetry-exporter-logging-otlp-1.54.0.jar -No changes. \ No newline at end of file +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.logs.export.LogRecordExporter create(boolean) +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.export.MetricExporter create(io.opentelemetry.sdk.metrics.data.AggregationTemporality, boolean) +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.export.SpanExporter create(boolean) diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporter.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporter.java index 0c00cca908e..b9641526e50 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporter.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporter.java @@ -8,6 +8,7 @@ import io.opentelemetry.exporter.logging.otlp.internal.logs.OtlpStdoutLogRecordExporter; import io.opentelemetry.exporter.logging.otlp.internal.logs.OtlpStdoutLogRecordExporterBuilder; import io.opentelemetry.sdk.common.CompletableResultCode; +import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import java.util.Collection; @@ -33,6 +34,24 @@ public static LogRecordExporter create() { return new OtlpJsonLoggingLogRecordExporter(delegate); } + /** + * Returns a new {@link OtlpJsonLoggingLogRecordExporter}. + * + * @param useLowAllocation whether to use low allocation OTLP marshalers with {@link + * MemoryMode#REUSABLE_DATA}. When {@code true}, uses low allocation mode and wraps the JSON + * object in an outer JSON "resourceLogs" object. When {@code false}, uses {@link + * MemoryMode#IMMUTABLE_DATA}. + */ + public static LogRecordExporter create(boolean useLowAllocation) { + MemoryMode memoryMode = useLowAllocation ? MemoryMode.REUSABLE_DATA : MemoryMode.IMMUTABLE_DATA; + OtlpStdoutLogRecordExporter delegate = + new OtlpStdoutLogRecordExporterBuilder(logger) + .setWrapperJsonObject(useLowAllocation) + .setMemoryMode(memoryMode) + .build(); + return new OtlpJsonLoggingLogRecordExporter(delegate); + } + OtlpJsonLoggingLogRecordExporter(OtlpStdoutLogRecordExporter delegate) { this.delegate = delegate; } diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporter.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporter.java index b42ef4acab7..45ae7ffdfc1 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporter.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporter.java @@ -8,6 +8,7 @@ import io.opentelemetry.exporter.logging.otlp.internal.metrics.OtlpStdoutMetricExporter; import io.opentelemetry.exporter.logging.otlp.internal.metrics.OtlpStdoutMetricExporterBuilder; import io.opentelemetry.sdk.common.CompletableResultCode; +import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.metrics.InstrumentType; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.MetricData; @@ -46,6 +47,27 @@ public static MetricExporter create(AggregationTemporality aggregationTemporalit return new OtlpJsonLoggingMetricExporter(delegate, aggregationTemporality); } + /** + * Returns a new {@link OtlpJsonLoggingMetricExporter} with the given {@code + * aggregationTemporality}. + * + * @param aggregationTemporality the aggregation temporality to use + * @param useLowAllocation whether to use low allocation OTLP marshalers with {@link + * MemoryMode#REUSABLE_DATA}. When {@code true}, uses low allocation mode and wraps the JSON + * object in an outer JSON "resourceMetrics" object. When {@code false}, uses {@link + * MemoryMode#IMMUTABLE_DATA}. + */ + public static MetricExporter create( + AggregationTemporality aggregationTemporality, boolean useLowAllocation) { + MemoryMode memoryMode = useLowAllocation ? MemoryMode.REUSABLE_DATA : MemoryMode.IMMUTABLE_DATA; + OtlpStdoutMetricExporter delegate = + new OtlpStdoutMetricExporterBuilder(logger) + .setWrapperJsonObject(useLowAllocation) + .setMemoryMode(memoryMode) + .build(); + return new OtlpJsonLoggingMetricExporter(delegate, aggregationTemporality); + } + OtlpJsonLoggingMetricExporter( OtlpStdoutMetricExporter delegate, AggregationTemporality aggregationTemporality) { this.delegate = delegate; diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporter.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporter.java index 63901351326..f25e193ffac 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporter.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporter.java @@ -8,6 +8,7 @@ import io.opentelemetry.exporter.logging.otlp.internal.traces.OtlpStdoutSpanExporter; import io.opentelemetry.exporter.logging.otlp.internal.traces.OtlpStdoutSpanExporterBuilder; import io.opentelemetry.sdk.common.CompletableResultCode; +import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; import java.util.Collection; @@ -31,6 +32,24 @@ public static SpanExporter create() { return new OtlpJsonLoggingSpanExporter(delegate); } + /** + * Returns a new {@link OtlpJsonLoggingSpanExporter}. + * + * @param useLowAllocation whether to use low allocation OTLP marshalers with {@link + * MemoryMode#REUSABLE_DATA}. When {@code true}, uses low allocation mode and wraps the JSON + * object in an outer JSON "resourceSpans" object. When {@code false}, uses {@link + * MemoryMode#IMMUTABLE_DATA}. + */ + public static SpanExporter create(boolean useLowAllocation) { + MemoryMode memoryMode = useLowAllocation ? MemoryMode.REUSABLE_DATA : MemoryMode.IMMUTABLE_DATA; + OtlpStdoutSpanExporter delegate = + new OtlpStdoutSpanExporterBuilder(logger) + .setWrapperJsonObject(useLowAllocation) + .setMemoryMode(memoryMode) + .build(); + return new OtlpJsonLoggingSpanExporter(delegate); + } + OtlpJsonLoggingSpanExporter(OtlpStdoutSpanExporter delegate) { this.delegate = delegate; } diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java index 11798e938f0..fabdb43f17b 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java @@ -34,17 +34,17 @@ public final class OtlpStdoutLogRecordExporter implements LogRecordExporter { private final Logger logger; private final JsonWriter jsonWriter; - private final boolean wrapperJsonObject; + private final boolean useLowAllocation; private final MemoryMode memoryMode; private final Function, CompletableResultCode> marshaler; OtlpStdoutLogRecordExporter( - Logger logger, JsonWriter jsonWriter, boolean wrapperJsonObject, MemoryMode memoryMode) { + Logger logger, JsonWriter jsonWriter, boolean useLowAllocation, MemoryMode memoryMode) { this.logger = logger; this.jsonWriter = jsonWriter; - this.wrapperJsonObject = wrapperJsonObject; + this.useLowAllocation = useLowAllocation; this.memoryMode = memoryMode; - marshaler = createMarshaler(jsonWriter, memoryMode, wrapperJsonObject); + marshaler = createMarshaler(jsonWriter, memoryMode, useLowAllocation); } /** Returns a new {@link OtlpStdoutLogRecordExporterBuilder}. */ @@ -54,8 +54,8 @@ public static OtlpStdoutLogRecordExporterBuilder builder() { } private static Function, CompletableResultCode> createMarshaler( - JsonWriter jsonWriter, MemoryMode memoryMode, boolean wrapperJsonObject) { - if (wrapperJsonObject) { + JsonWriter jsonWriter, MemoryMode memoryMode, boolean useLowAllocation) { + if (useLowAllocation) { LogReusableDataMarshaler reusableDataMarshaler = new LogReusableDataMarshaler( memoryMode, (marshaler, numItems) -> jsonWriter.write(marshaler)); @@ -103,7 +103,7 @@ public CompletableResultCode shutdown() { public String toString() { StringJoiner joiner = new StringJoiner(", ", "OtlpStdoutLogRecordExporter{", "}"); joiner.add("jsonWriter=" + jsonWriter); - joiner.add("wrapperJsonObject=" + wrapperJsonObject); + joiner.add("useLowAllocation=" + useLowAllocation); joiner.add("memoryMode=" + memoryMode); return joiner.toString(); } diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java index 76e6adb20ad..1e58d2edfe3 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java @@ -27,7 +27,7 @@ public final class OtlpStdoutLogRecordExporterBuilder { private final Logger logger; private JsonWriter jsonWriter; - private boolean wrapperJsonObject = true; + private boolean useLowAllocation = true; private MemoryMode memoryMode = MemoryMode.IMMUTABLE_DATA; public OtlpStdoutLogRecordExporterBuilder(Logger logger) { @@ -38,11 +38,10 @@ public OtlpStdoutLogRecordExporterBuilder(Logger logger) { /** * Sets the exporter to use the specified JSON object wrapper. * - * @param wrapperJsonObject whether to wrap the JSON object in an outer JSON "resourceLogs" - * object. + * @param useLowAllocation whether to wrap the JSON object in an outer JSON "resourceLogs" object. */ - public OtlpStdoutLogRecordExporterBuilder setWrapperJsonObject(boolean wrapperJsonObject) { - this.wrapperJsonObject = wrapperJsonObject; + public OtlpStdoutLogRecordExporterBuilder setWrapperJsonObject(boolean useLowAllocation) { + this.useLowAllocation = useLowAllocation; return this; } @@ -84,10 +83,10 @@ public OtlpStdoutLogRecordExporterBuilder setOutput(Logger logger) { * @return a new exporter's instance */ public OtlpStdoutLogRecordExporter build() { - if (memoryMode == MemoryMode.REUSABLE_DATA && !wrapperJsonObject) { + if (memoryMode == MemoryMode.REUSABLE_DATA && !useLowAllocation) { throw new IllegalArgumentException( - "Reusable data mode is not supported without wrapperJsonObject"); + "Reusable data mode is not supported without useLowAllocation"); } - return new OtlpStdoutLogRecordExporter(logger, jsonWriter, wrapperJsonObject, memoryMode); + return new OtlpStdoutLogRecordExporter(logger, jsonWriter, useLowAllocation, memoryMode); } } diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporter.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporter.java index 4294c1d2571..b839d643649 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporter.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporter.java @@ -38,7 +38,7 @@ public final class OtlpStdoutMetricExporter implements MetricExporter { private final Logger logger; private final JsonWriter jsonWriter; - private final boolean wrapperJsonObject; + private final boolean useLowAllocation; private final MemoryMode memoryMode; private final Function, CompletableResultCode> marshaler; private final AggregationTemporalitySelector aggregationTemporalitySelector; @@ -47,17 +47,17 @@ public final class OtlpStdoutMetricExporter implements MetricExporter { OtlpStdoutMetricExporter( Logger logger, JsonWriter jsonWriter, - boolean wrapperJsonObject, + boolean useLowAllocation, MemoryMode memoryMode, AggregationTemporalitySelector aggregationTemporalitySelector, DefaultAggregationSelector defaultAggregationSelector) { this.logger = logger; this.jsonWriter = jsonWriter; - this.wrapperJsonObject = wrapperJsonObject; + this.useLowAllocation = useLowAllocation; this.memoryMode = memoryMode; this.aggregationTemporalitySelector = aggregationTemporalitySelector; this.defaultAggregationSelector = defaultAggregationSelector; - marshaler = createMarshaler(jsonWriter, memoryMode, wrapperJsonObject); + marshaler = createMarshaler(jsonWriter, memoryMode, useLowAllocation); } /** Returns a new {@link OtlpStdoutMetricExporterBuilder}. */ @@ -67,8 +67,8 @@ public static OtlpStdoutMetricExporterBuilder builder() { } private static Function, CompletableResultCode> createMarshaler( - JsonWriter jsonWriter, MemoryMode memoryMode, boolean wrapperJsonObject) { - if (wrapperJsonObject) { + JsonWriter jsonWriter, MemoryMode memoryMode, boolean useLowAllocation) { + if (useLowAllocation) { MetricReusableDataMarshaler reusableDataMarshaler = new MetricReusableDataMarshaler( memoryMode, (marshaler, numItems) -> jsonWriter.write(marshaler)); @@ -131,7 +131,7 @@ public CompletableResultCode shutdown() { public String toString() { StringJoiner joiner = new StringJoiner(", ", "OtlpStdoutMetricExporter{", "}"); joiner.add("jsonWriter=" + jsonWriter); - joiner.add("wrapperJsonObject=" + wrapperJsonObject); + joiner.add("useLowAllocation=" + useLowAllocation); joiner.add("memoryMode=" + memoryMode); joiner.add( "aggregationTemporalitySelector=" diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterBuilder.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterBuilder.java index 945ffd778bd..8d41da4e46b 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterBuilder.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterBuilder.java @@ -40,7 +40,7 @@ public final class OtlpStdoutMetricExporterBuilder { private final Logger logger; private JsonWriter jsonWriter; - private boolean wrapperJsonObject = true; + private boolean useLowAllocation = true; private MemoryMode memoryMode = MemoryMode.IMMUTABLE_DATA; public OtlpStdoutMetricExporterBuilder(Logger logger) { @@ -51,11 +51,11 @@ public OtlpStdoutMetricExporterBuilder(Logger logger) { /** * Sets the exporter to use the specified JSON object wrapper. * - * @param wrapperJsonObject whether to wrap the JSON object in an outer JSON "resourceMetrics" + * @param useLowAllocation whether to wrap the JSON object in an outer JSON "resourceMetrics" * object. */ - public OtlpStdoutMetricExporterBuilder setWrapperJsonObject(boolean wrapperJsonObject) { - this.wrapperJsonObject = wrapperJsonObject; + public OtlpStdoutMetricExporterBuilder setWrapperJsonObject(boolean useLowAllocation) { + this.useLowAllocation = useLowAllocation; return this; } @@ -127,14 +127,14 @@ public OtlpStdoutMetricExporterBuilder setDefaultAggregationSelector( * @return a new exporter's instance */ public OtlpStdoutMetricExporter build() { - if (memoryMode == MemoryMode.REUSABLE_DATA && !wrapperJsonObject) { + if (memoryMode == MemoryMode.REUSABLE_DATA && !useLowAllocation) { throw new IllegalArgumentException( - "Reusable data mode is not supported without wrapperJsonObject"); + "Reusable data mode is not supported without useLowAllocation"); } return new OtlpStdoutMetricExporter( logger, jsonWriter, - wrapperJsonObject, + useLowAllocation, memoryMode, aggregationTemporalitySelector, defaultAggregationSelector); diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporter.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporter.java index 187cdacc245..f91a5be9604 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporter.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporter.java @@ -33,17 +33,17 @@ public final class OtlpStdoutSpanExporter implements SpanExporter { private final Logger logger; private final JsonWriter jsonWriter; - private final boolean wrapperJsonObject; + private final boolean useLowAllocation; private final MemoryMode memoryMode; private final Function, CompletableResultCode> marshaler; OtlpStdoutSpanExporter( - Logger logger, JsonWriter jsonWriter, boolean wrapperJsonObject, MemoryMode memoryMode) { + Logger logger, JsonWriter jsonWriter, boolean useLowAllocation, MemoryMode memoryMode) { this.logger = logger; this.jsonWriter = jsonWriter; - this.wrapperJsonObject = wrapperJsonObject; + this.useLowAllocation = useLowAllocation; this.memoryMode = memoryMode; - marshaler = createMarshaler(jsonWriter, memoryMode, wrapperJsonObject); + marshaler = createMarshaler(jsonWriter, memoryMode, useLowAllocation); } /** Returns a new {@link OtlpStdoutSpanExporterBuilder}. */ @@ -53,8 +53,8 @@ public static OtlpStdoutSpanExporterBuilder builder() { } private static Function, CompletableResultCode> createMarshaler( - JsonWriter jsonWriter, MemoryMode memoryMode, boolean wrapperJsonObject) { - if (wrapperJsonObject) { + JsonWriter jsonWriter, MemoryMode memoryMode, boolean useLowAllocation) { + if (useLowAllocation) { SpanReusableDataMarshaler reusableDataMarshaler = new SpanReusableDataMarshaler( memoryMode, (marshaler, numItems) -> jsonWriter.write(marshaler)); @@ -102,7 +102,7 @@ public CompletableResultCode shutdown() { public String toString() { StringJoiner joiner = new StringJoiner(", ", "OtlpStdoutSpanExporter{", "}"); joiner.add("jsonWriter=" + jsonWriter); - joiner.add("wrapperJsonObject=" + wrapperJsonObject); + joiner.add("useLowAllocation=" + useLowAllocation); joiner.add("memoryMode=" + memoryMode); return joiner.toString(); } diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterBuilder.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterBuilder.java index 341f63c6e49..71ec89642eb 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterBuilder.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterBuilder.java @@ -27,7 +27,7 @@ public final class OtlpStdoutSpanExporterBuilder { private final Logger logger; private JsonWriter jsonWriter; - private boolean wrapperJsonObject = true; + private boolean useLowAllocation = true; private MemoryMode memoryMode = MemoryMode.IMMUTABLE_DATA; public OtlpStdoutSpanExporterBuilder(Logger logger) { @@ -38,11 +38,11 @@ public OtlpStdoutSpanExporterBuilder(Logger logger) { /** * Sets the exporter to use the specified JSON object wrapper. * - * @param wrapperJsonObject whether to wrap the JSON object in an outer JSON "resourceSpans" + * @param useLowAllocation whether to wrap the JSON object in an outer JSON "resourceSpans" * object. */ - public OtlpStdoutSpanExporterBuilder setWrapperJsonObject(boolean wrapperJsonObject) { - this.wrapperJsonObject = wrapperJsonObject; + public OtlpStdoutSpanExporterBuilder setWrapperJsonObject(boolean useLowAllocation) { + this.useLowAllocation = useLowAllocation; return this; } @@ -84,10 +84,10 @@ public OtlpStdoutSpanExporterBuilder setOutput(Logger logger) { * @return a new exporter's instance */ public OtlpStdoutSpanExporter build() { - if (memoryMode == MemoryMode.REUSABLE_DATA && !wrapperJsonObject) { + if (memoryMode == MemoryMode.REUSABLE_DATA && !useLowAllocation) { throw new IllegalArgumentException( - "Reusable data mode is not supported without wrapperJsonObject"); + "Reusable data mode is not supported without useLowAllocation"); } - return new OtlpStdoutSpanExporter(logger, jsonWriter, wrapperJsonObject, memoryMode); + return new OtlpStdoutSpanExporter(logger, jsonWriter, useLowAllocation, memoryMode); } } diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java index 44b046aca42..63907e7cbb2 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java @@ -79,7 +79,7 @@ public AbstractOtlpStdoutExporterTest( } protected abstract T createExporter( - @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean wrapperJsonObject); + @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean useLowAllocation); protected abstract T createDefaultExporter(); @@ -134,13 +134,13 @@ enum OutputType { public static class TestCase { private final MemoryMode memoryMode; - private final boolean wrapperJsonObject; + private final boolean useLowAllocation; private final OutputType outputType; - public TestCase(OutputType outputType, MemoryMode memoryMode, boolean wrapperJsonObject) { + public TestCase(OutputType outputType, MemoryMode memoryMode, boolean useLowAllocation) { this.outputType = outputType; this.memoryMode = memoryMode; - this.wrapperJsonObject = wrapperJsonObject; + this.useLowAllocation = useLowAllocation; } public OutputType getOutputType() { @@ -148,7 +148,7 @@ public OutputType getOutputType() { } public boolean isWrapperJsonObject() { - return wrapperJsonObject; + return useLowAllocation; } public MemoryMode getMemoryMode() { @@ -158,47 +158,42 @@ public MemoryMode getMemoryMode() { static Stream exportTestCases() { return ImmutableList.of( - testCase(OutputType.SYSTEM_OUT, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ true), - testCase(OutputType.SYSTEM_OUT, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ false), - testCase(OutputType.FILE, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ true), - testCase(OutputType.FILE, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ false), + testCase(OutputType.SYSTEM_OUT, MemoryMode.IMMUTABLE_DATA, /* useLowAllocation= */ true), + testCase(OutputType.SYSTEM_OUT, MemoryMode.IMMUTABLE_DATA, /* useLowAllocation= */ false), + testCase(OutputType.FILE, MemoryMode.IMMUTABLE_DATA, /* useLowAllocation= */ true), + testCase(OutputType.FILE, MemoryMode.IMMUTABLE_DATA, /* useLowAllocation= */ false), testCase( OutputType.FILE_AND_BUFFERED_WRITER, MemoryMode.IMMUTABLE_DATA, - /* wrapperJsonObject= */ true), + /* useLowAllocation= */ true), testCase( OutputType.FILE_AND_BUFFERED_WRITER, MemoryMode.IMMUTABLE_DATA, - /* wrapperJsonObject= */ false), - testCase(OutputType.LOGGER, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ true), - testCase(OutputType.LOGGER, MemoryMode.IMMUTABLE_DATA, /* wrapperJsonObject= */ false), - testCase(OutputType.SYSTEM_OUT, MemoryMode.REUSABLE_DATA, /* wrapperJsonObject= */ true), - testCase(OutputType.SYSTEM_OUT, MemoryMode.REUSABLE_DATA, /* wrapperJsonObject= */ false), - testCase(OutputType.FILE, MemoryMode.REUSABLE_DATA, /* wrapperJsonObject= */ true), - testCase(OutputType.FILE, MemoryMode.REUSABLE_DATA, /* wrapperJsonObject= */ false), + /* useLowAllocation= */ false), + testCase(OutputType.LOGGER, MemoryMode.IMMUTABLE_DATA, /* useLowAllocation= */ true), + testCase(OutputType.LOGGER, MemoryMode.IMMUTABLE_DATA, /* useLowAllocation= */ false), + testCase(OutputType.SYSTEM_OUT, MemoryMode.REUSABLE_DATA, /* useLowAllocation= */ true), + testCase(OutputType.SYSTEM_OUT, MemoryMode.REUSABLE_DATA, /* useLowAllocation= */ false), + testCase(OutputType.FILE, MemoryMode.REUSABLE_DATA, /* useLowAllocation= */ true), + testCase(OutputType.FILE, MemoryMode.REUSABLE_DATA, /* useLowAllocation= */ false), testCase( OutputType.FILE_AND_BUFFERED_WRITER, MemoryMode.REUSABLE_DATA, - /* wrapperJsonObject= */ true), + /* useLowAllocation= */ true), testCase( OutputType.FILE_AND_BUFFERED_WRITER, MemoryMode.REUSABLE_DATA, - /* wrapperJsonObject= */ false), - testCase(OutputType.LOGGER, MemoryMode.REUSABLE_DATA, /* wrapperJsonObject= */ true), - testCase(OutputType.LOGGER, MemoryMode.REUSABLE_DATA, /* wrapperJsonObject= */ false)) + /* useLowAllocation= */ false), + testCase(OutputType.LOGGER, MemoryMode.REUSABLE_DATA, /* useLowAllocation= */ true), + testCase(OutputType.LOGGER, MemoryMode.REUSABLE_DATA, /* useLowAllocation= */ false)) .stream(); } private static Arguments testCase( - OutputType type, MemoryMode memoryMode, boolean wrapperJsonObject) { + OutputType type, MemoryMode memoryMode, boolean useLowAllocation) { return Arguments.of( - "output=" - + type - + ", wrapperJsonObject=" - + wrapperJsonObject - + ", memoryMode=" - + memoryMode, - new TestCase(type, memoryMode, wrapperJsonObject)); + "output=" + type + ", useLowAllocation=" + useLowAllocation + ", memoryMode=" + memoryMode, + new TestCase(type, memoryMode, useLowAllocation)); } @SuppressWarnings("SystemOut") @@ -233,7 +228,7 @@ void exportWithProgrammaticConfig(String name, TestCase testCase) throws Excepti if (testCase.getMemoryMode() == MemoryMode.REUSABLE_DATA && !testCase.isWrapperJsonObject()) { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(exporter::get) - .withMessage("Reusable data mode is not supported without wrapperJsonObject"); + .withMessage("Reusable data mode is not supported without useLowAllocation"); return; } @@ -308,7 +303,7 @@ void componentProviderConfig() { DeclarativeConfigProperties properties = spy(DeclarativeConfigProperties.empty()); T exporter = exporterFromComponentProvider(properties); - assertThat(exporter).extracting("wrapperJsonObject").isEqualTo(true); + assertThat(exporter).extracting("useLowAllocation").isEqualTo(true); assertThat(exporter).extracting("memoryMode").isEqualTo(MemoryMode.IMMUTABLE_DATA); assertThat(exporter) .extracting("jsonWriter") diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java index 75677620dbb..0372e3bb1bf 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java @@ -45,6 +45,36 @@ void log() throws Exception { assertThat(message).doesNotContain("\n"); } + @Test + void logWithWrapperJsonObjectFalse() throws Exception { + // Test that useLowAllocation=false produces the same output as the default create() + LogRecordExporter exporterWithoutWrapper = OtlpJsonLoggingLogRecordExporter.create(false); + testDataExporter.export(exporterWithoutWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(false); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + + @Test + void logWithWrapperJsonObjectTrue() throws Exception { + // Test that useLowAllocation=true produces wrapper format (enables low allocation) + LogRecordExporter exporterWithWrapper = OtlpJsonLoggingLogRecordExporter.create(true); + testDataExporter.export(exporterWithWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(true); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + @Test void shutdown() { assertThat(exporter.shutdown().isSuccess()).isTrue(); diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java index ccbfdb26dce..584e5aeb775 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingMetricExporterTest.java @@ -47,6 +47,30 @@ void getAggregationTemporality() { .isEqualTo(AggregationTemporality.DELTA); } + /** + * Test that the new create method with useLowAllocation parameter maintains correct aggregation + * temporality. + */ + @Test + void getAggregationTemporalityWithUseLowAllocation() { + assertThat( + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, false) + .getAggregationTemporality(InstrumentType.COUNTER)) + .isEqualTo(AggregationTemporality.CUMULATIVE); + assertThat( + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.DELTA, false) + .getAggregationTemporality(InstrumentType.COUNTER)) + .isEqualTo(AggregationTemporality.DELTA); + assertThat( + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, true) + .getAggregationTemporality(InstrumentType.COUNTER)) + .isEqualTo(AggregationTemporality.CUMULATIVE); + assertThat( + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.DELTA, true) + .getAggregationTemporality(InstrumentType.COUNTER)) + .isEqualTo(AggregationTemporality.DELTA); + } + @Test void log() throws Exception { testDataExporter.export(exporter); @@ -60,6 +84,54 @@ void log() throws Exception { assertThat(message).doesNotContain("\n"); } + @Test + void logWithWrapperJsonObjectFalse() throws Exception { + // Test that useLowAllocation=false produces the same output as the default create() + MetricExporter exporterWithoutWrapper = + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, false); + testDataExporter.export(exporterWithoutWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(false); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + + @Test + void logWithWrapperJsonObjectTrue() throws Exception { + // Test that useLowAllocation=true produces wrapper format (enables low allocation) + MetricExporter exporterWithWrapper = + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.CUMULATIVE, true); + testDataExporter.export(exporterWithWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(true); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + + @Test + void logWithWrapperJsonObjectTrueAndDeltaTemporality() throws Exception { + // Test that useLowAllocation=true works with DELTA temporality too + MetricExporter exporterWithWrapper = + OtlpJsonLoggingMetricExporter.create(AggregationTemporality.DELTA, true); + testDataExporter.export(exporterWithWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(true); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + @Test void flush() { assertThat(exporter.flush().isSuccess()).isTrue(); diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java index ac3129f4a1c..fdd8c33bd71 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingSpanExporterTest.java @@ -46,6 +46,36 @@ void log() throws Exception { assertThat(message).doesNotContain("\n"); } + @Test + void logWithWrapperJsonObjectFalse() throws Exception { + // Test that useLowAllocation=false produces the same output as the default create() + SpanExporter exporterWithoutWrapper = OtlpJsonLoggingSpanExporter.create(false); + testDataExporter.export(exporterWithoutWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(false); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + + @Test + void logWithWrapperJsonObjectTrue() throws Exception { + // Test that useLowAllocation=true produces wrapper format (enables low allocation) + SpanExporter exporterWithWrapper = OtlpJsonLoggingSpanExporter.create(true); + testDataExporter.export(exporterWithWrapper); + + assertThat(logs.getEvents()) + .hasSize(1) + .allSatisfy(log -> assertThat(log.getLevel()).isEqualTo(Level.INFO)); + String message = logs.getEvents().get(0).getMessage(); + String expectedJson = testDataExporter.getExpectedJson(true); + JSONAssert.assertEquals("Got \n" + message, expectedJson, message, /* strict= */ false); + assertThat(message).doesNotContain("\n"); + } + @Test void flush() { assertThat(exporter.flush().isSuccess()).isTrue(); diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java index c19fba0fe3e..f88628a8a39 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java @@ -23,7 +23,7 @@ public OtlpStdoutLogRecordExporterTest() { OtlpStdoutLogRecordExporter.class, ConfigurableLogRecordExporterProvider.class, LogRecordExporter.class, - "OtlpStdoutLogRecordExporter{jsonWriter=StreamJsonWriter{outputStream=stdout}, wrapperJsonObject=true, memoryMode=IMMUTABLE_DATA}"); + "OtlpStdoutLogRecordExporter{jsonWriter=StreamJsonWriter{outputStream=stdout}, useLowAllocation=true, memoryMode=IMMUTABLE_DATA}"); } @Override @@ -33,11 +33,11 @@ protected OtlpStdoutLogRecordExporter createDefaultExporter() { @Override protected OtlpStdoutLogRecordExporter createExporter( - @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean wrapperJsonObject) { + @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean useLowAllocation) { OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder() .setMemoryMode(memoryMode) - .setWrapperJsonObject(wrapperJsonObject); + .setWrapperJsonObject(useLowAllocation); if (outputStream != null) { builder.setOutput(outputStream); } else { diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutMetricExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutMetricExporterTest.java index 28b0b2e3587..09036fb9bc7 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutMetricExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutMetricExporterTest.java @@ -37,7 +37,7 @@ public OtlpStdoutMetricExporterTest() { OtlpStdoutMetricExporter.class, ConfigurableMetricExporterProvider.class, MetricExporter.class, - "OtlpStdoutMetricExporter{jsonWriter=StreamJsonWriter{outputStream=stdout}, wrapperJsonObject=true, memoryMode=IMMUTABLE_DATA, aggregationTemporalitySelector=AggregationTemporalitySelector{COUNTER=CUMULATIVE, UP_DOWN_COUNTER=CUMULATIVE, HISTOGRAM=CUMULATIVE, OBSERVABLE_COUNTER=CUMULATIVE, OBSERVABLE_UP_DOWN_COUNTER=CUMULATIVE, OBSERVABLE_GAUGE=CUMULATIVE, GAUGE=CUMULATIVE}, defaultAggregationSelector=DefaultAggregationSelector{COUNTER=default, UP_DOWN_COUNTER=default, HISTOGRAM=default, OBSERVABLE_COUNTER=default, OBSERVABLE_UP_DOWN_COUNTER=default, OBSERVABLE_GAUGE=default, GAUGE=default}}"); + "OtlpStdoutMetricExporter{jsonWriter=StreamJsonWriter{outputStream=stdout}, useLowAllocation=true, memoryMode=IMMUTABLE_DATA, aggregationTemporalitySelector=AggregationTemporalitySelector{COUNTER=CUMULATIVE, UP_DOWN_COUNTER=CUMULATIVE, HISTOGRAM=CUMULATIVE, OBSERVABLE_COUNTER=CUMULATIVE, OBSERVABLE_UP_DOWN_COUNTER=CUMULATIVE, OBSERVABLE_GAUGE=CUMULATIVE, GAUGE=CUMULATIVE}, defaultAggregationSelector=DefaultAggregationSelector{COUNTER=default, UP_DOWN_COUNTER=default, HISTOGRAM=default, OBSERVABLE_COUNTER=default, OBSERVABLE_UP_DOWN_COUNTER=default, OBSERVABLE_GAUGE=default, GAUGE=default}}"); } @Override @@ -47,11 +47,11 @@ protected OtlpStdoutMetricExporter createDefaultExporter() { @Override protected OtlpStdoutMetricExporter createExporter( - @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean wrapperJsonObject) { + @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean useLowAllocation) { OtlpStdoutMetricExporterBuilder builder = OtlpStdoutMetricExporter.builder() .setMemoryMode(memoryMode) - .setWrapperJsonObject(wrapperJsonObject); + .setWrapperJsonObject(useLowAllocation); if (outputStream != null) { builder.setOutput(outputStream); } else { diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutSpanExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutSpanExporterTest.java index 01d3a96ccd2..95e9a52cbf0 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutSpanExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutSpanExporterTest.java @@ -22,7 +22,7 @@ public OtlpStdoutSpanExporterTest() { OtlpStdoutSpanExporter.class, ConfigurableSpanExporterProvider.class, SpanExporter.class, - "OtlpStdoutSpanExporter{jsonWriter=StreamJsonWriter{outputStream=stdout}, wrapperJsonObject=true, memoryMode=IMMUTABLE_DATA}"); + "OtlpStdoutSpanExporter{jsonWriter=StreamJsonWriter{outputStream=stdout}, useLowAllocation=true, memoryMode=IMMUTABLE_DATA}"); } @Override @@ -32,11 +32,11 @@ protected OtlpStdoutSpanExporter createDefaultExporter() { @Override protected OtlpStdoutSpanExporter createExporter( - @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean wrapperJsonObject) { + @Nullable OutputStream outputStream, MemoryMode memoryMode, boolean useLowAllocation) { OtlpStdoutSpanExporterBuilder builder = OtlpStdoutSpanExporter.builder() .setMemoryMode(memoryMode) - .setWrapperJsonObject(wrapperJsonObject); + .setWrapperJsonObject(useLowAllocation); if (outputStream != null) { builder.setOutput(outputStream); } else {