-
Notifications
You must be signed in to change notification settings - Fork 840
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
add stdout log record exporter #6675
add stdout log record exporter #6675
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6675 +/- ##
=========================================
Coverage 90.09% 90.09%
- Complexity 6390 6423 +33
=========================================
Files 711 717 +6
Lines 19333 19422 +89
Branches 1891 1894 +3
=========================================
+ Hits 17418 17499 +81
- Misses 1335 1341 +6
- Partials 580 582 +2 ☔ View full report in Codecov by Sentry. |
@jack-berg can you take a look? |
...entelemetry/exporter/logging/otlp/internal/logs/OtlpJsonLoggingLogRecordExporterBuilder.java
Outdated
Show resolved
Hide resolved
...entelemetry/exporter/logging/otlp/internal/logs/OtlpJsonLoggingLogRecordExporterBuilder.java
Outdated
Show resolved
Hide resolved
...p/src/main/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporter.java
Show resolved
Hide resolved
...ging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/InternalBuilder.java
Outdated
Show resolved
Hide resolved
...n/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java
Outdated
Show resolved
Hide resolved
...n/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java
Outdated
Show resolved
Hide resolved
...n/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java
Outdated
Show resolved
Hide resolved
...o/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterProvider.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpJsonLoggingExporterTest.java
Outdated
Show resolved
Hide resolved
...logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/LogRecordExporterTest.java
Outdated
Show resolved
Hide resolved
Thanks for breaking out - this was more manageable to review. |
cee0142
to
4088520
Compare
@jack-berg thanks for the thorough review - I hope I've addressed everything (build fails because of link checker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've got to get the delegation model right. We have a new OtlpStdoutLogRecordExporter
/ OtlpStdOutLogRecordExporterBuilder
which we think is going to be the standard going forward, but is internal and experimental for this. This supports a variety of configuration options, include the ability to specify your own output stream and wether you want the "wrapper json object". The old OtlpJsonLoggingLogRecordExporter
is just a OtlpStdoutLogRecordExporter
with a very specific configuration which is non-configurable. This means that OtlpJsonLoggingLogRecordExporter
should delegate to OtlpStdoutLogRecordExporter
, since OtlpStdoutLogRecordExporter
is a superset of the capabilities of OtlpJsonLoggingLogRecordExporter
.
Its flipped right now and I think its requiring some wonky stuff with reflection which makes this more complicated that it needs to be. This is hard to communicate via comments, so I sketched it out quickly in a commit. Note the tests don't pass yet, but I think those have an unnecessary abstract class, as I've mentioned in comments.
...c/test/java/io/opentelemetry/exporter/logging/otlp/OtlpJsonLoggingLogRecordExporterTest.java
Outdated
Show resolved
Hide resolved
...o/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterProvider.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java
Outdated
Show resolved
Hide resolved
...n/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java
Show resolved
Hide resolved
...entelemetry/exporter/logging/otlp/internal/logs/OtlpJsonLoggingLogRecordExporterBuilder.java
Outdated
Show resolved
Hide resolved
...tlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java
Outdated
Show resolved
Hide resolved
I really like the solution you found! I'll use it. 💯
You can't set the builder to use a logger. |
@jack-berg all suggestions incorporated now 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! Smaller number of lingering questions. I made it all the way through the code this time so I think this is likely the last set of comments to resolve.
...io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java
Show resolved
Hide resolved
|
||
public StreamJsonWriter(OutputStream originalStream, String type) { | ||
this.originalStream = originalStream; | ||
this.outputStream = new IgnoreCloseOutputStream(originalStream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on here? What close are we trying to ignore?
Also, what do you think in general about the resource management of the output stream? Should OtlpStdoutLogRecordExporter
be responsible for calling OutputStream.close()
? I think probably yes, since otherwise it would be complicated for a user to detect shutdown and close the output stream themselves. On the otherhand, closing System.out
is not correct. I wonder if we need a boolean configuration option to indicate whether the OutputStream
should be closed on LogRecordExporter#shutdown()
:
setOutputStream(os, true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good point - there's not even a test for using a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turned out that we can skip the boolean flag if we just call flush
in close
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flushing on close will ensure that any unwritten bytes are flushed to the outputstream, but doesn't allow any outputstream resources to be released on shutdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could call close on shutdown instead - but maybe that's too surprising
another option is that we specifically check for System.out
and System.err
- and only then not call close (I like that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could call close on shutdown instead - but maybe that's too surprising
That was my point with adding a boolean on setOutputStream
where the user could specify whether they want to be responsible for closing the stream or if they want the exporter to be responsible.
another option is that we specifically check for System.out and System.err
True.. That would probably cover most of the cases. But I wonder if there are other cases where you would want to skip closing the OutputStream
. We could always start with this suggestion and later add a boolean overload to setOutputStream
if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option is that we specifically check for System.out and System.err
I implemented this now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see code in IgnoreCloseOutputStream#close()
which checks if the stream is System.out
or System.err
, but I don't see where close()
is being called anywhere in OtlpStdoutLogRecordExporter#shutdown()
.
Also, we should add javadoc to OtlpStdoutLogRecordExporterBuilder#setOutput(OutputStream)
which indicates that the stream will be closed if its not System.out
or System.err
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch - I also found a better way to implement this I hope.
I couldn't find where flush
is being called - and if I need to flush the stream manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flush is called by jackson (https://fasterxml.github.io/jackson-core/javadoc/2.7/com/fasterxml/jackson/core/JsonGenerator.Feature.html#FLUSH_PASSED_TO_STREAM) - but it seems that
opentelemetry-java/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/LogRecordExporter.java
Line 72 in 8a917e0
CompletableResultCode flush(); |
...o/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterProvider.java
Outdated
Show resolved
Hide resolved
@jack-berg please have another look if you're ok with a separate experimental module, let me know which module would be appropriate |
1a900ff
to
4141ad3
Compare
@jack-berg please have another look 😄 |
...ain/java/io/opentelemetry/exporter/logging/otlp/internal/writer/IgnoreCloseOutputStream.java
Outdated
Show resolved
Hide resolved
...tor/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking on this comment: #6675 (comment)
Otherwise, just a few nits.
46b7624
to
ab33054
Compare
Co-authored-by: jack-berg <[email protected]>
…stdout as per spec" This reverts commit 4141ad3.
…stdout as per spec" This reverts commit 2b0160d.
…stdout as per spec" This reverts commit 3694af2.
c84f47b
to
1baa575
Compare
blocker is resolved @jack-berg 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits, but 👍
...n/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java
Outdated
Show resolved
Hide resolved
...io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java
Outdated
Show resolved
Hide resolved
...lp/src/test/java/io/opentelemetry/exporter/logging/otlp/OtlpStdoutLogRecordExporterTest.java
Outdated
Show resolved
Hide resolved
…/logging/otlp/internal/logs/OtlpStdoutLogRecordExporter.java Co-authored-by: jack-berg <[email protected]>
…/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterBuilder.java Co-authored-by: jack-berg <[email protected]>
be066b4
to
44de5ea
Compare
thanks @jack-berg - should I add the other signals next, or the memory mode for logs? |
No preference from me |
split off from #6632 - only for logs, and no memory mode