Skip to content
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 a OTLP JSON span exporter to logs. #2295

Merged
merged 7 commits into from
Dec 23, 2020

Conversation

anuraaga
Copy link
Contributor

This uses a protobuf-json library I wrote a while ago, and we use it in Armeria for production. It's based on Jackson vs gson, which I think has a higher chance of being on an app's classpath which is nice. The use of Jackson also made it quite easy to switch the binary marshalling to hex from base64. But it's designed for speed (for use in production) so uses bytebuddy for runtime code generation as opposed to runtime reflection like the official json-format does. That does unfortunately make it more heavyweight than it could be, but at least it's fast 😅.

Wondering where to put this, probably not in -otlp, new -otlp-logging, or replace the current -logging? Leaning towards -otlp-logging.

@anuraaga
Copy link
Contributor Author

For reference, in official, the base64 encoding is hard coded inside this private method, so no go

https://github.com/protocolbuffers/protobuf/blob/master/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java#L1235

@jkwatson
Copy link
Contributor

how "heavyweight" does it end up being? My only concern with replacing the existing logging exporter is how much users would be taking on to get it. -otlp-logging seems good to me, otherwise. We can always decide to replace later, if there's appetite for it.

@anuraaga
Copy link
Contributor Author

@jkwatson I think ~4MB for byte-buddy + jackson. That's after I do some pruning since it's currently getting ~3MB of guava too due to a dependency on protobuf-java-util for a very small amount of logic, as it stands it's about 7MB. Let me go ahead and make a new module for it at least for now.

@trask
Copy link
Member

trask commented Dec 15, 2020

are we going to break out otlp-metrics and otlp-spans modules due to versioning? maybe this should be logging-otlp, it seems more a variant of logging to me than a variant of otlp (not sure if I'm making sense)

@anuraaga
Copy link
Contributor Author

Ah forgot to mention one more caveat - we'll need an otlp-common to contain the proto translation code. How's that sound?

are we going to break out otlp-metrics and otlp-spans modules due to versioning?

Ah yeah this was the plan

maybe this should be logging-otlp, it seems more a variant of logging to me than a variant of otlp (not sure if I'm making sense)

Makes sense to me

@anuraaga
Copy link
Contributor Author

anuraaga commented Dec 15, 2020

Hmm - well I guess the README is saying it's ok for me to move the code into this extension?

https://github.com/open-telemetry/opentelemetry-java/tree/master/sdk-extensions/otproto

@bogdandrutu
Copy link
Member

@anuraaga haven’t read the code, but why did you mention JSON encoding in the other PR? Can you add JSON format? We should prioritize proto

@anuraaga
Copy link
Contributor Author

anuraaga commented Dec 15, 2020

@bogdandrutu This does use JSON serialization of the proto. Meaning it relies on e.g., SpanAdapter to set up the proto, classes that technically aren't needed if adding #2304

@bogdandrutu
Copy link
Member

I read the PR and I think the tittle is confusing, this is not an exporter for OTLP logs, but an exporter that writes to the logs. Do we need this?

@anuraaga anuraaga changed the title Add a OTLP logging span exporter. Add a OTLP JSON span exporter to logs. Dec 16, 2020
@anuraaga
Copy link
Contributor Author

@bogdandrutu There was interest in a fully spec'd, stable format for spans when writing to logs in #2293. It seems nice, but could be overkill. @jkwatson @trask any thoughts? I've heard Splunk wanting to use logs for exporting spans in AWS Lambda, maybe @bogdandrutu @iNikem you know if this could help with that?

@trask
Copy link
Member

trask commented Dec 16, 2020

We've seen interest in using the logging exporter beyond getting started / toy apps (e.g. open-telemetry/opentelemetry-java-instrumentation#1600).

So it would be great if the output of the logging exporter can have some sort of stability guarantee, similar to the other stability guarantees we have been discussing.

OTLP/JSON[*] seems ideal, only because we get it for "free" and wouldn't have to invent something new.

[*]without the weird traceid/spanid format

@anuraaga anuraaga marked this pull request as ready for review December 21, 2020 04:35
ext.moduleName = "io.opentelemetry.exporter.otlpjson"

dependencies {
compileOnly project(':sdk:trace')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkwatson So I tried a different approach to splitting all exporters for trace vs metrics here since it seemed like it could be a bit too much. If going with this, I'd revert the change to split out the otlp exporters in favor of compileOnly dependencies.

One of the reasons it felt like much is we would need to split otproto up as well - they all end up having a common, trace, metrics split. Lots of artifacts.

But it means that previously, a user could only depend on exporter-otlp to have the SDK as well, but with such a scheme, they'd have to additionally add the SDK as a dependency. I wonder if this is too annoying or reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, since the trace SDK is supposed to be stable, I think it would ok to declare this as an api dependency and get that for free, like people would probably expect. Keeping the metrics dependency as provided might be ok, though, since someone has to explicitly opt-in to depending on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think so long term? e.g., what if someone replaces the trace SDK with a custom one, would we want the exporter artifacts to still bring in the trace SDK? I guess it could be ok, as custom SDKs still seem rare enough to me. Just want to confirm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a completely custom SDK, it might have a completely different exporter interface, yeah? This does make me think we should have a separate artifact with the "SDK Extension Points" in it, including exporter, span processor, sampler interfaces, so at least custom SDKs can use the same extension points.

@@ -0,0 +1,9 @@
# OpenTelemetry - OTLP JSON Exporters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is purely a logging exporter, this module should be named logging-otlp I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - there's some tension with the logging signal. But went with that name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh...yeah, I had forgotten about that bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no, I hadn't thought about that either, that's going to be very confusing, should we rename our existing logging exporter to "file" exporter, or "console" exporter, or ...

+ " }]\n"
+ " }]\n"
+ "}",
logged.get(0).getMessage(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read this right...the log message will be split across multiple lines? Don't we want to make sure that every log message is only a single line, so it can work with normal logging systems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing! This is a JSON assert so whitespace is ignored. I added additional checks that the message has no newlines and realized I needed to set that.

+ " }\n"
+ " }]\n"
+ " }]\n"
+ "}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about multi-line log message

ext.moduleName = "io.opentelemetry.exporter.otlpjson"

dependencies {
compileOnly project(':sdk:trace')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would "provided" be a semantically more correct dependency declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think provided is "expected to be there", e.g., tomcat, and optional is "add if you want". compileOnly roughly corresponds with optional.

ext.moduleName = "io.opentelemetry.exporter.otlpjson"

dependencies {
compileOnly project(':sdk:trace')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, since the trace SDK is supposed to be stable, I think it would ok to declare this as an api dependency and get that for free, like people would probably expect. Keeping the metrics dependency as provided might be ok, though, since someone has to explicitly opt-in to depending on it.

@codecov
Copy link

codecov bot commented Dec 22, 2020

Codecov Report

Merging #2295 (ec65fe4) into master (6cf957b) will increase coverage by 88.53%.
The diff coverage is 77.77%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master    #2295       +/-   ##
=============================================
+ Coverage          0   88.53%   +88.53%     
- Complexity        0     2576     +2576     
=============================================
  Files             0      293      +293     
  Lines             0     8678     +8678     
  Branches          0      929      +929     
=============================================
+ Hits              0     7683     +7683     
- Misses            0      660      +660     
- Partials          0      335      +335     
Impacted Files Coverage Δ Complexity Δ
...er/logging/otlp/OtlpJsonLoggingMetricExporter.java 65.71% <65.71%> (ø) 6.00 <6.00> (?)
...r/logging/otlp/HexEncodingStringJsonGenerator.java 88.23% <88.23%> (ø) 6.00 <6.00> (?)
...rter/logging/otlp/OtlpJsonLoggingSpanExporter.java 90.00% <90.00%> (ø) 6.00 <6.00> (?)
...a/io/opentelemetry/sdk/logging/data/LogRecord.java 100.00% <0.00%> (ø) 2.00% <0.00%> (?%)
...n/java/io/opentelemetry/sdk/trace/IdGenerator.java 100.00% <0.00%> (ø) 1.00% <0.00%> (?%)
.../io/opentelemetry/opentracingshim/Propagation.java 96.42% <0.00%> (ø) 5.00% <0.00%> (?%)
...opentelemetry/opentracingshim/OpenTracingShim.java 100.00% <0.00%> (ø) 3.00% <0.00%> (?%)
...opentelemetry/sdk/common/export/ConfigBuilder.java 100.00% <0.00%> (ø) 10.00% <0.00%> (?%)
.../java/io/opentelemetry/sdk/resources/Resource.java 92.00% <0.00%> (ø) 15.00% <0.00%> (?%)
...entelemetry/sdk/extension/otproto/SpanAdapter.java 97.91% <0.00%> (ø) 25.00% <0.00%> (?%)
... and 286 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cf957b...ec65fe4. Read the comment docs.

}

description = 'OpenTelemetry Protocol JSON Logging Exporters'
ext.moduleName = "io.opentelemetry.exporter.logging.otlp"
Copy link
Contributor

@jkwatson jkwatson Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only possible quibble is that maybe this should be "io.opentelemetry.exporter.logging-otlp" but I'm not quite sure which is going to be more discoverable by end-users. Maybe the description could be more .. descriptive about exactly what's going on here. Maybe description = 'OpenTelemetry logging exporters with OTLP JSON formatting. Currently supports span exports.' ?

Copy link
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can't wait to try it out!

@jkwatson jkwatson merged commit 6d1bcd9 into open-telemetry:master Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants