Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import io.opentelemetry.exporter.logging.otlp.internal.writer.StreamJsonWriter;
import io.opentelemetry.sdk.common.export.MemoryMode;
import java.io.OutputStream;
import java.util.function.Function;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* Builder for {@link OtlpJsonLoggingLogRecordExporter}.
Expand All @@ -26,13 +28,15 @@ public final class OtlpStdoutLogRecordExporterBuilder {
private static final String TYPE = "log records";

private final Logger logger;
private JsonWriter jsonWriter;
@Nullable private OutputStream outputStream;
@Nullable private Logger outputLogger;
private Function<OutputStream, OutputStream> outputStreamMapper = Function.identity();
private boolean wrapperJsonObject = true;
private MemoryMode memoryMode = MemoryMode.IMMUTABLE_DATA;

public OtlpStdoutLogRecordExporterBuilder(Logger logger) {
this.logger = logger;
this.jsonWriter = new LoggerJsonWriter(logger, TYPE);
this.outputLogger = logger;
}

/**
Expand Down Expand Up @@ -67,14 +71,35 @@ public OtlpStdoutLogRecordExporterBuilder setMemoryMode(MemoryMode memoryMode) {
*/
public OtlpStdoutLogRecordExporterBuilder setOutput(OutputStream outputStream) {
requireNonNull(outputStream, "outputStream");
this.jsonWriter = new StreamJsonWriter(outputStream, TYPE);
this.outputStream = outputStream;
this.outputLogger = null;
return this;
}

/** Sets the exporter to use the specified logger. */
public OtlpStdoutLogRecordExporterBuilder setOutput(Logger logger) {
requireNonNull(logger, "logger");
this.jsonWriter = new LoggerJsonWriter(logger, TYPE);
this.outputLogger = logger;
this.outputStream = null;
return this;
}

/**
* Sets the {@link Function} to map the output stream before writing.
*
* <p>This can be used to customize the stream, for example to apply compression:
*
* <pre>{@code
* builder.setOutputStreamMapper(GZIPOutputStream::new)
* }</pre>
*
* @param outputStreamMapper the function to map the output stream
* @return this
*/
public OtlpStdoutLogRecordExporterBuilder setOutputStreamMapper(
Function<OutputStream, OutputStream> outputStreamMapper) {
requireNonNull(outputStreamMapper, "outputStreamMapper");
this.outputStreamMapper = outputStreamMapper;
return this;
}

Expand All @@ -88,6 +113,16 @@ public OtlpStdoutLogRecordExporter build() {
throw new IllegalArgumentException(
"Reusable data mode is not supported without wrapperJsonObject");
}
JsonWriter jsonWriter;
if (outputStream != null) {
jsonWriter =
new StreamJsonWriter(
requireNonNull(
outputStreamMapper.apply(outputStream), "outputStreamMapper returned null"),
TYPE);
} else {
jsonWriter = new LoggerJsonWriter(requireNonNull(outputLogger), TYPE);
}
return new OtlpStdoutLogRecordExporter(logger, jsonWriter, wrapperJsonObject, memoryMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.io.OutputStream;
import java.util.function.Function;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* Builder for {@link OtlpJsonLoggingMetricExporter}.
Expand All @@ -39,13 +41,15 @@ public final class OtlpStdoutMetricExporterBuilder {
DefaultAggregationSelector.getDefault();

private final Logger logger;
private JsonWriter jsonWriter;
@Nullable private OutputStream outputStream;
@Nullable private Logger outputLogger;
private Function<OutputStream, OutputStream> outputStreamMapper = Function.identity();
private boolean wrapperJsonObject = true;
private MemoryMode memoryMode = MemoryMode.IMMUTABLE_DATA;

public OtlpStdoutMetricExporterBuilder(Logger logger) {
this.logger = logger;
this.jsonWriter = new LoggerJsonWriter(logger, TYPE);
this.outputLogger = logger;
}

/**
Expand Down Expand Up @@ -80,14 +84,35 @@ public OtlpStdoutMetricExporterBuilder setMemoryMode(MemoryMode memoryMode) {
*/
public OtlpStdoutMetricExporterBuilder setOutput(OutputStream outputStream) {
requireNonNull(outputStream, "outputStream");
this.jsonWriter = new StreamJsonWriter(outputStream, TYPE);
this.outputStream = outputStream;
this.outputLogger = null;
return this;
}

/** Sets the exporter to use the specified logger. */
public OtlpStdoutMetricExporterBuilder setOutput(Logger logger) {
requireNonNull(logger, "logger");
this.jsonWriter = new LoggerJsonWriter(logger, TYPE);
this.outputLogger = logger;
this.outputStream = null;
return this;
}

/**
* Sets the {@link Function} to map the output stream before writing.
*
* <p>This can be used to customize the stream, for example to apply compression:
*
* <pre>{@code
* builder.setOutputStreamMapper(GZIPOutputStream::new)
* }</pre>
*
* @param outputStreamMapper the function to map the output stream
* @return this
*/
public OtlpStdoutMetricExporterBuilder setOutputStreamMapper(
Function<OutputStream, OutputStream> outputStreamMapper) {
requireNonNull(outputStreamMapper, "outputStreamMapper");
this.outputStreamMapper = outputStreamMapper;
return this;
}

Expand Down Expand Up @@ -131,6 +156,16 @@ public OtlpStdoutMetricExporter build() {
throw new IllegalArgumentException(
"Reusable data mode is not supported without wrapperJsonObject");
}
JsonWriter jsonWriter;
if (outputStream != null) {
jsonWriter =
new StreamJsonWriter(
requireNonNull(
outputStreamMapper.apply(outputStream), "outputStreamMapper returned null"),
TYPE);
} else {
jsonWriter = new LoggerJsonWriter(requireNonNull(outputLogger), TYPE);
}
return new OtlpStdoutMetricExporter(
logger,
jsonWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import io.opentelemetry.exporter.logging.otlp.internal.writer.StreamJsonWriter;
import io.opentelemetry.sdk.common.export.MemoryMode;
import java.io.OutputStream;
import java.util.function.Function;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* Builder for {@link OtlpJsonLoggingSpanExporter}.
Expand All @@ -26,13 +28,15 @@ public final class OtlpStdoutSpanExporterBuilder {
private static final String TYPE = "spans";

private final Logger logger;
private JsonWriter jsonWriter;
@Nullable private OutputStream outputStream;
@Nullable private Logger outputLogger;
private Function<OutputStream, OutputStream> outputStreamMapper = Function.identity();
private boolean wrapperJsonObject = true;
private MemoryMode memoryMode = MemoryMode.IMMUTABLE_DATA;

public OtlpStdoutSpanExporterBuilder(Logger logger) {
this.logger = logger;
this.jsonWriter = new LoggerJsonWriter(logger, TYPE);
this.outputLogger = logger;
}

/**
Expand Down Expand Up @@ -67,14 +71,35 @@ public OtlpStdoutSpanExporterBuilder setMemoryMode(MemoryMode memoryMode) {
*/
public OtlpStdoutSpanExporterBuilder setOutput(OutputStream outputStream) {
requireNonNull(outputStream, "outputStream");
this.jsonWriter = new StreamJsonWriter(outputStream, TYPE);
this.outputStream = outputStream;
this.outputLogger = null;
return this;
}

/** Sets the exporter to use the specified logger. */
public OtlpStdoutSpanExporterBuilder setOutput(Logger logger) {
requireNonNull(logger, "logger");
this.jsonWriter = new LoggerJsonWriter(logger, TYPE);
this.outputLogger = logger;
this.outputStream = null;
return this;
}

/**
* Sets the {@link Function} to map the output stream before writing.
*
* <p>This can be used to customize the stream, for example to apply compression:
*
* <pre>{@code
* builder.setOutputStreamMapper(GZIPOutputStream::new)
* }</pre>
*
* @param outputStreamMapper the function to map the output stream
* @return this
*/
public OtlpStdoutSpanExporterBuilder setOutputStreamMapper(
Function<OutputStream, OutputStream> outputStreamMapper) {
requireNonNull(outputStreamMapper, "outputStreamMapper");
this.outputStreamMapper = outputStreamMapper;
return this;
}

Expand All @@ -88,6 +113,16 @@ public OtlpStdoutSpanExporter build() {
throw new IllegalArgumentException(
"Reusable data mode is not supported without wrapperJsonObject");
}
JsonWriter jsonWriter;
if (outputStream != null) {
jsonWriter =
new StreamJsonWriter(
requireNonNull(
outputStreamMapper.apply(outputStream), "outputStreamMapper returned null"),
TYPE);
} else {
jsonWriter = new LoggerJsonWriter(requireNonNull(outputLogger), TYPE);
}
return new OtlpStdoutSpanExporter(logger, jsonWriter, wrapperJsonObject, memoryMode);
}
}
Loading
Loading