Replace jackson OTLP json serialization with handrolled version#8545
Replace jackson OTLP json serialization with handrolled version#8545jack-berg wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8545 +/- ##
============================================
+ Coverage 90.97% 91.02% +0.05%
- Complexity 10206 10256 +50
============================================
Files 1013 1013
Lines 27166 27310 +144
Branches 3182 3200 +18
============================================
+ Hits 24713 24860 +147
+ Misses 1729 1725 -4
- Partials 724 725 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Well... I think we have been working on the same :) |
Ah! Too bad 😅. I checked out your code and added a little more test coverage mine was missing. I like the look of this though.
Not sure declarative config can easily go in this direction. It needs to do a couple of things which are harder than JSON serialization:
It actually doesn't do any serialization at all. So I think the serialization code could actually live in |
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
|
ok. Closing my PRs. |
There was a problem hiding this comment.
I think the current tests cover the main behavior well, but since this is low-level serialization code and it adds a fair amount of custom logic, I’d feel better with a few more edge-case tests before merging.
In particular, I think it would be good to add coverage for:
- buffer flushing once output exceeds the internal 4096-byte buffer
- nesting deep enough to grow the
countsarray past 16 - invalid surrogate handling in
writeQuoted()(lone low surrogate / unmatched high surrogate) - the
close()IOException path
The happy-path coverage looks solid already; I’m mainly asking for the edge cases around the new custom writer.
(generated by claude)
|
There's a long-standing challenge in json marshaling with self-referential objects. Fortunately, this PR doesn't introduce generic object serialization, so you can't just pass any old ProtoFieldInfo fieldInfo = ProtoFieldInfo.create(1, 0, "self");
Marshaler marshaler =
new Marshaler() {
@Override
public int getBinarySerializedSize() {
return 0;
}
@Override
protected void writeTo(Serializer output) throws IOException {
output.serializeMessage(fieldInfo, this);
}
};
marshaler.writeJsonTo(new ByteArrayOutputStream());That will end up throwing a Normally I'd say that this change in behavior is a real problem, but I can't find any genuine production code paths to attain this...so maybe it's not a big deal. I just thought I'd bring it up in case others feel differently. |
| writer.writeEndObject(); | ||
| }, | ||
| "{\"resource\":{\"key\":\"val\"}}")); | ||
| } |
There was a problem hiding this comment.
I'd like to see another test that just passes nulls for each of the types too.
There was a problem hiding this comment.
We've got nullaway protecting against this. If there is some way for null to reach here, I would agree.
| writeByte((byte) '"'); | ||
| } | ||
|
|
||
| void writeString(String value) throws IOException { |
There was a problem hiding this comment.
One small name change could help better convey that this is only called for values, and not for field names or other possible uses. Maybe it's not necessary given the argument name, just an idea.
| void writeString(String value) throws IOException { | |
| void writeStringValue(String value) throws IOException { |
There was a problem hiding this comment.
There are several other methods which write values and do not include the *Value suffix. I think I'd like to skip this one.
|
This is great! I'm basically an approval, will just give a little time for response to comments. |
I did find a way to create one of these situations with |
Tests added for all! |
Related to #8533.
Jackson 3 was released and requires java 17.
We rely on jackson in a variety of places. This PR concerns the serialization functionality we rely on for
opentelemetry-exporter-logging-otlp,opentelemetry-exporter-otlp(officially json is not supproted - see #5833).Rather than try to accommodate different versions of jackson through something like SPI, its simpler to just replace jackson with a hand rolled version, at least for the JSON serialization bits.
We have precedent for hand rolled JSON serialization in JsonEncoding, which is used by Value. However, this operates in very different context than OTLP marshaling and probably shouldn't be merged together.