-
Notifications
You must be signed in to change notification settings - Fork 935
add stdout log record exporter #6675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jack-berg
merged 47 commits into
open-telemetry:main
from
zeitlinger:stdout-exporter-logs-core
Sep 18, 2024
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
aa57fff
add stdout log record exporter
zeitlinger 3fb3c92
add stdout log record exporter
zeitlinger aeed8fc
simplify export
zeitlinger 48634ea
rename OtlpJsonLoggingLogRecordExporterBuilder
zeitlinger 75adbfa
no logger in InternalBuilder
zeitlinger 61bff70
add EXPORTER_ARTIFACT_ID_BY_NAME
zeitlinger 70087b8
remove InternalBuilder, OtlpStdoutLogRecordExporter delegates
zeitlinger daee6e6
we need two builders, because they produce different types
zeitlinger 28628ec
return interface
zeitlinger 77e6456
simplify
zeitlinger 284e879
split test class
zeitlinger 165e1fe
demo
jack-berg f56f794
allow to set logger
zeitlinger 61ea461
remove create method
zeitlinger cf194c6
fix test
zeitlinger 7dc1960
inline abstract class
zeitlinger 95fa97f
inline abstract class
zeitlinger 2ee23b9
get back old test
zeitlinger f2280c1
simplify tests
zeitlinger f2db40c
simplify tests
zeitlinger d52e8a9
simplify tests
zeitlinger 335b3fc
Update buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
zeitlinger 70eb011
add test for using file exporter
zeitlinger 01fa923
add test for using file exporter
zeitlinger 9eb0c45
test coverage
zeitlinger 0726ce6
call close unless it's System.out or System.err
zeitlinger ee3ceb6
call close unless it's System.out or System.err
zeitlinger 66b804d
rename setLogger to setOutput, don't set the logger for reporting errors
zeitlinger 04c1d61
move provider to sdk-extensions/incubator and rename to otlp/stdout a…
zeitlinger 0933b6e
move provider to sdk-extensions/incubator and rename to otlp/stdout a…
zeitlinger c3c6e86
move provider to sdk-extensions/incubator and rename to otlp/stdout a…
zeitlinger 8e049b5
add tests
zeitlinger 5e7af08
add tests
zeitlinger d1cfadf
Update buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
zeitlinger 69b0014
Revert "move provider to sdk-extensions/incubator and rename to otlp/…
zeitlinger e97b117
Revert "move provider to sdk-extensions/incubator and rename to otlp/…
zeitlinger d99a97f
Revert "move provider to sdk-extensions/incubator and rename to otlp/…
zeitlinger ca75f71
change name to "experimental-otlp/stdout"
zeitlinger c09c634
close input stream on shutdown
zeitlinger 77aec31
inline superclass
zeitlinger febd77c
add tests
zeitlinger 0f88cb2
add tests
zeitlinger 1baa575
add tests
zeitlinger 382d311
Update exporters/logging-otlp/src/main/java/io/opentelemetry/exporter…
zeitlinger e65af38
Update exporters/logging-otlp/src/main/java/io/opentelemetry/exporter…
zeitlinger 069db45
pr review
zeitlinger 44de5ea
pr review
zeitlinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ava/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.logging.otlp.internal.logs; | ||
|
|
||
| import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler; | ||
| import io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler; | ||
| import io.opentelemetry.exporter.logging.otlp.internal.writer.JsonWriter; | ||
| import io.opentelemetry.sdk.common.CompletableResultCode; | ||
| import io.opentelemetry.sdk.logs.data.LogRecordData; | ||
| import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
| import java.util.Collection; | ||
| import java.util.StringJoiner; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Exporter for sending OTLP log records to stdout. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public class OtlpStdoutLogRecordExporter implements LogRecordExporter { | ||
|
|
||
| private static final Logger LOGGER = | ||
| Logger.getLogger(OtlpStdoutLogRecordExporter.class.getName()); | ||
|
|
||
| private final AtomicBoolean isShutdown = new AtomicBoolean(); | ||
|
|
||
| private final Logger logger; | ||
| private final JsonWriter jsonWriter; | ||
| private final boolean wrapperJsonObject; | ||
|
|
||
| OtlpStdoutLogRecordExporter(Logger logger, JsonWriter jsonWriter, boolean wrapperJsonObject) { | ||
| this.logger = logger; | ||
| this.jsonWriter = jsonWriter; | ||
| this.wrapperJsonObject = wrapperJsonObject; | ||
| } | ||
|
|
||
| /** Returns a new {@link OtlpStdoutLogRecordExporterBuilder}. */ | ||
| @SuppressWarnings("SystemOut") | ||
| public static OtlpStdoutLogRecordExporterBuilder builder() { | ||
| return new OtlpStdoutLogRecordExporterBuilder(LOGGER).setOutput(System.out); | ||
| } | ||
zeitlinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public CompletableResultCode export(Collection<LogRecordData> logs) { | ||
| if (isShutdown.get()) { | ||
| return CompletableResultCode.ofFailure(); | ||
| } | ||
|
|
||
| if (wrapperJsonObject) { | ||
| LogsRequestMarshaler request = LogsRequestMarshaler.create(logs); | ||
| return jsonWriter.write(request); | ||
| } else { | ||
| for (ResourceLogsMarshaler resourceLogs : ResourceLogsMarshaler.create(logs)) { | ||
| CompletableResultCode resultCode = jsonWriter.write(resourceLogs); | ||
| if (!resultCode.isSuccess()) { | ||
| // already logged | ||
| return resultCode; | ||
| } | ||
| } | ||
| return CompletableResultCode.ofSuccess(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode flush() { | ||
| return jsonWriter.flush(); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode shutdown() { | ||
| if (!isShutdown.compareAndSet(false, true)) { | ||
| logger.log(Level.INFO, "Calling shutdown() multiple times."); | ||
| } else { | ||
| jsonWriter.close(); | ||
| } | ||
| return CompletableResultCode.ofSuccess(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringJoiner joiner = new StringJoiner(", ", "OtlpStdoutLogRecordExporter{", "}"); | ||
| joiner.add("jsonWriter=" + jsonWriter); | ||
| joiner.add("wrapperJsonObject=" + wrapperJsonObject); | ||
| return joiner.toString(); | ||
| } | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
...opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.logging.otlp.internal.logs; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; | ||
| import io.opentelemetry.exporter.logging.otlp.internal.writer.JsonWriter; | ||
| import io.opentelemetry.exporter.logging.otlp.internal.writer.LoggerJsonWriter; | ||
| import io.opentelemetry.exporter.logging.otlp.internal.writer.StreamJsonWriter; | ||
| import java.io.OutputStream; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Builder for {@link OtlpJsonLoggingLogRecordExporter}. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public final class OtlpStdoutLogRecordExporterBuilder { | ||
|
|
||
| private static final String TYPE = "log records"; | ||
|
|
||
| private final Logger logger; | ||
| private JsonWriter jsonWriter; | ||
| private boolean wrapperJsonObject = true; | ||
|
|
||
| public OtlpStdoutLogRecordExporterBuilder(Logger logger) { | ||
| this.logger = logger; | ||
| this.jsonWriter = new LoggerJsonWriter(logger, TYPE); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the exporter to use the specified JSON object wrapper. | ||
| * | ||
| * @param wrapperJsonObject whether to wrap the JSON object in an outer JSON "resourceLogs" | ||
| * object. | ||
| */ | ||
| public OtlpStdoutLogRecordExporterBuilder setWrapperJsonObject(boolean wrapperJsonObject) { | ||
| this.wrapperJsonObject = wrapperJsonObject; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the exporter to use the specified output stream. | ||
| * | ||
| * <p>The output stream will be closed when {@link OtlpStdoutLogRecordExporter#shutdown()} is | ||
| * called unless it's {@link System#out} or {@link System#err}. | ||
| * | ||
| * @param outputStream the output stream to use. | ||
| */ | ||
| public OtlpStdoutLogRecordExporterBuilder setOutput(OutputStream outputStream) { | ||
| requireNonNull(outputStream, "outputStream"); | ||
| this.jsonWriter = new StreamJsonWriter(outputStream, TYPE); | ||
| return this; | ||
| } | ||
|
|
||
| /** Sets the exporter to use the specified logger. */ | ||
| public OtlpStdoutLogRecordExporterBuilder setOutput(Logger logger) { | ||
| requireNonNull(logger, "logger"); | ||
| this.jsonWriter = new LoggerJsonWriter(logger, TYPE); | ||
jack-berg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a new instance of the exporter based on the builder's values. | ||
| * | ||
| * @return a new exporter's instance | ||
| */ | ||
| public OtlpStdoutLogRecordExporter build() { | ||
| return new OtlpStdoutLogRecordExporter(logger, jsonWriter, wrapperJsonObject); | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
...try/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.logging.otlp.internal.logs; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.StructuredConfigProperties; | ||
| import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
|
|
||
| /** | ||
| * File configuration SPI implementation for {@link OtlpStdoutLogRecordExporter}. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public class OtlpStdoutLogRecordExporterComponentProvider | ||
| implements ComponentProvider<LogRecordExporter> { | ||
|
|
||
| @Override | ||
| public Class<LogRecordExporter> getType() { | ||
| return LogRecordExporter.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "experimental-otlp/stdout"; | ||
| } | ||
|
|
||
| @Override | ||
| public LogRecordExporter create(StructuredConfigProperties config) { | ||
| OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder(); | ||
| return builder.build(); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...pentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.exporter.logging.otlp.internal.logs; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; | ||
| import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
|
|
||
| /** | ||
| * {@link LogRecordExporter} SPI implementation for {@link OtlpStdoutLogRecordExporter}. | ||
| * | ||
| * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
| * at any time. | ||
| */ | ||
| public class OtlpStdoutLogRecordExporterProvider implements ConfigurableLogRecordExporterProvider { | ||
| @Override | ||
| public LogRecordExporter createExporter(ConfigProperties config) { | ||
| OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder(); | ||
| return builder.build(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "experimental-otlp/stdout"; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.