If a Java stack trace arrives as a CRI-partial header plus one document per frame, reassemble the CRI envelope first, then group the Java continuations per file and stream.
The log lines and results below are illustrative. They use invented pod names and were produced with Fluent Bit 3.1.9 on a local machine, not against a live stack.
Ask the app team to mark one expected exception. You can then follow that marker from the raw container log to the assembled JSON and see which pod produced each frame.
Contents
- Identify what split the record
- Reassemble the outer record
- Group without mixing sources
- The final document and exceptions
- FAQ
- Why do I still see one document per Java frame?
- Can I use the built-in Java parser?
- Will a longer timeout keep all the frames together?
- Can I order fragments by timestamp to recover the exception?
- What should I check when old documents are still split?
- Can I test the shipping workflow during the Logit.io free trial?
- Next steps
Identify what split the record
Timestamp, stream and P/F flags
To confirm the path, have the application owner emit one known exception with a unique marker on its header. Here that marker is example=java-alpha-01. Save the contiguous rows from that container’s raw CRI log, including the preceding or following entries if they help establish the boundary. A view that already strips runtime metadata can show the Java frames but hide the reason the header was split.
Read the first three space-separated fields as the runtime timestamp, the original stream and the fragment flag. The remainder, including indentation, is application text. A physical row ends at the newline in the file. P means this row carries a partial line. The following F on that stream can complete it. An F with no pending partial stands alone as a complete runtime line, which can still be one frame in a larger Java exception.
Create a scratch directory and run the commands from it. Save the two blocks below as the named files. The directories use the shape of separate Kubernetes pod paths, with made-up namespaces, pod names, identifiers and container names. Keep the four spaces before at in each alpha frame.
mkdir -p pods/payments_payments-api-alpha-alpha/payments-api \
pods/inventory_inventory-worker-beta-beta/inventory-worker
Alpha, payments API, in this file:
pods/payments_payments-api-alpha-alpha/payments-api/0.log
2026-01-10T09:00:01Z stderr P ERROR [example=java-alpha-01] java.lang.IllegalStateException: pay
2026-01-10T09:00:02Z stderr F ment declined
2026-01-10T09:00:03Z stderr F at com.example.payments.ChargeService.charge(ChargeService.java:42)
2026-01-10T09:00:04Z stderr F at com.example.payments.PaymentController.post(PaymentController.java:19)
Beta, inventory worker, in this file:
pods/inventory_inventory-worker-beta-beta/inventory-worker/0.log
2026-01-10T09:00:01.500000000Z stdout F INFO [example=inventory-beta-01] inventory poll completed
Call the alpha rows A1 through A4 and the beta row B1. A1 ends halfway through the word payment. A2 supplies the remaining bytes of the same header, so the first complete application line ends after declined. A3 starts the first Java continuation and A4 starts the second. Both are complete CRI rows. B1’s timestamp falls between A1 and A2, but it lives in its own file. File membership and stream identify where to look for a fragment’s continuation. Sorting all the rows by timestamp would put an unrelated message inside the exception.
Reassemble the outer record
Tail’s CRI multiline parser
Use the built-in cri multiline parser on Tail. It reads the CRI envelope, pairs runtime fragments per file and stream, and joins the payload bytes. For this example that means concatenating pay and ment declined without a separator. Tail exposes the joined payload as a top-level string called log. The two complete Java frames still have separate records and their indentation is intact. Use multiline.parser cri in the input and leave the older Tail parser and multiline options out of this example.
Use a local Fluent Bit 3.1.9 binary in a scratch directory that also holds the two log files. The next section gives the complete fluent-bit.conf and java-multiline.conf. After you have saved those files, the two-pass commands there compare a CRI-only run with the full pipeline. The GNU timeout used on those commands stops each run after eight seconds, giving the local buffers time to flush.
The intermediate table lists the decoded records by source row. Their order on stdout can differ. The time in the table is the retained time field. The JSON output also prints the parsed event timestamp under event_time.
| Source rows | Retained CRI time | Stream | Retained flag | Decoded log text |
|---|---|---|---|---|
| Alpha A1 + A2 | 2026-01-10T09:00:01Z | stderr | P | ERROR [example=java-alpha-01] java.lang.IllegalStateException: payment declined |
| Alpha A3 | 2026-01-10T09:00:03Z | stderr | F | Four leading spaces, then at com. |
| Alpha A4 | 2026-01-10T09:00:04Z | stderr | F | Four leading spaces, then at com. |
| Beta B1 | 2026-01-10T09:00:01.500000000Z | stdout | F | INFO [example=inventory-beta-01] inventory poll completed |
In this 3.1.9 run, the header retained A1’s time and _p fields after A2 completed it. The retained _p: P alone cannot tell you whether the header is missing bytes. Compare the payload with the original rows. If the decoded output still shows the two header fragments separately, fix the CRI step before touching the Java rules. If the header is intact and only the frames are separate, the CRI step has already done its job.
If the decoded record in your pipeline differs from this table, inspect it immediately before the Java filter. An enrichment or parsing step might rename log, replace its string value with an object, or remove stream. Set the content selector to the actual text field at that point and keep the stream available for routing. In this example, routing reads stream and leaves log untouched. Fluent Bit Tail documentation.
Group without mixing sources
One filter per file and stream
Give each tailed file its own tag. Tail expands the asterisk in example.raw.* from the watched file path, using dots in place of path separators. rewrite_tag then adds the CRI stream and retains the whole original tag via $TAG. For alpha’s stderr, the resulting tag is:
example.stream.stderr.example.raw.pods.payments_payments-api-alpha-alpha.payments-api.0.log
Alpha’s stdout changes the stream portion to stdout. Beta has a different file portion, even when it writes to stderr.
Use one multiline filter and make it the first filter that matches the stream-qualified tags. The preceding tag rewrite matches only example.raw.*, so it never matches those routed records. Ordinary records with a valid CRI stream take the same route and pass through the Java stage if they match no rule. The stdout output also catches any unmatched raw-tag records, so an unexpected envelope stays visible in the local run. The displayed source_file comes from Tail’s Path_Key and gives you the file identity even though JSON Lines does not display the internal routing tag.
Save this configuration as fluent-bit.conf. The output is local stdout throughout the example.
[SERVICE]
Flush 1
Log_Level info
Parsers_File java-multiline.conf
[INPUT]
Name tail
Path pods/*/*/*.log
Tag example.raw.*
Path_Key source_file
Read_from_Head On
Refresh_Interval 1
multiline.parser cri
[FILTER]
Name rewrite_tag
Match example.raw.*
Rule $stream ^(stdout|stderr)$ example.stream.$1.$TAG false
Emitter_Name cri_stream_router
[FILTER]
Name multiline
Match example.stream.*
Mode parser
multiline.parser java_example
multiline.key_content log
Buffer On
Flush_MS 2000
Emitter_Name java_example_emitter
Emitter_Storage.type memory
Emitter_Mem_Buf_Limit 10M
[OUTPUT]
Name stdout
Match example.*
Format json_lines
Json_Date_Key event_time
Json_Date_Format iso8601
Fluent Bit 3.1.9’s built-in java parser also matched the baseline header and its two indented frames on the stream-qualified tags. The example uses the custom parser below to make the start condition explicit. It expects an ERROR line with the example marker and a Java exception class followed by a colon. The continuation rule recognises an indented at line with a method name and a parenthesised location. Save it as java-multiline.conf.
[MULTILINE_PARSER]
Name java_example
Type regex
Flush_Timeout 2000
Key_Content log
Rule "start_state" "/^ERROR +\[example=[a-z0-9-]+\] +[A-Za-z0-9_.$]+(?:Exception|Error|Throwable):/" "frames"
Rule "frames" "/^[ \t]+at +[A-Za-z0-9_.$]+\(.*\)/" "frames"
Once those two configuration files and the log files are in the same scratch directory, compare a CRI-only pass with the full pipeline. The first command removes both filter blocks in a temporary config. Both runs tail the same two files from the beginning.
fluent-bit --version
sed '/^\[FILTER\]/,/^\[OUTPUT\]/{ /^\[OUTPUT\]/!d; }' fluent-bit.conf > cri-only.conf
timeout --preserve-status 8s fluent-bit -c cri-only.conf > cri.out 2> cri.err
timeout --preserve-status 8s fluent-bit -c fluent-bit.conf > assembled.out 2> assembled.err
grep '^{' cri.out
grep '^{' assembled.out
The header moves the parser from start_state to frames. Each matching line appends to the pending message with a newline and keeps the parser in frames. The marker identifies the header for verification, while each continuation is assigned by its line shape and its routed tag. An unrelated line on that tag closes the pending exception and is emitted independently if it starts no new trace. A frame on a tag that has never opened a group matches no start rule and passes through by itself. If your logger emits Caused by:, Suppressed: or elided frames, include those forms in your test before adopting a parser for that logger. Fluent Bit multiline parser rules.
The filter reads log via multiline.key_content. Buffer On lets Fluent Bit hold pending Java content across chunks and re-emit it via an internal emitter. This example sets the parser’s Flush_Timeout and the filter’s Flush_MS to 2,000 milliseconds. In this buffered filter the two-second periodic check drives the flush of pending groups. Run the timed append below to see the boundary. The check uses processing time independently of the timestamps written inside the CRI rows. The service’s one-second Flush schedules output delivery, so give stdout additional time. The 10M limit is for the multiline emitter’s memory buffer under backpressure and gives no per-exception byte limit.
Fluent Bit re-emits buffered records at the head of the pipeline with the same stream-qualified tag. The multiline filter checks the input instance and skips records from its own emitter. The rewrite still has no matching tag at that point, so the record can reach stdout without being routed again. A second multiline filter that overlaps the same tags may consume records from the first filter’s emitter and create a loop. Place enrichment for the assembled record after the multiline filter and keep the rewrite match narrow. Fluent Bit 3.1 multiline filter documentation · Fluent Bit 3.1 tag rewrite documentation.
The final document and exceptions
IDs, timestamps and frame order
The baseline local run produced two JSON documents. This array formats them for inspection. The configured output writes one object per line. Compare by marker and source path because beta may appear on stdout before alpha even though alpha’s header began earlier.
[
{
"event_time": "2026-01-10T09:00:01.500000Z",
"time": "2026-01-10T09:00:01.500000000Z",
"stream": "stdout",
"_p": "F",
"log": "INFO [example=inventory-beta-01] inventory poll completed",
"source_file": "pods/inventory_inventory-worker-beta-beta/inventory-worker/0.log"
},
{
"event_time": "2026-01-10T09:00:01.000000Z",
"time": "2026-01-10T09:00:01Z",
"stream": "stderr",
"_p": "P",
"log": "ERROR [example=java-alpha-01] java.lang.IllegalStateException: payment declined\n at com.example.payments.ChargeService.charge(ChargeService.java:42)\n at com.example.payments.PaymentController.post(PaymentController.java:19)",
"source_file": "pods/payments_payments-api-alpha-alpha/payments-api/0.log"
}
]
For alpha, check that the marker occurs once and the log contains the header from A1 and A2, the ChargeService frame from A3, then the PaymentController frame from A4. All three Java lines come from the payments API file on stderr. The timestamp belongs to A1 and the path identifies the alpha pod and container. The two \n sequences encode line breaks inside the JSON string. Beta retains its own marker, event time, inventory worker path and stdout stream. A count of two would still pass if a frame moved to the wrong document, so check the message text as well.
Repeat the test on fresh copies of the example files. Each of the following controls makes an error that a document count alone could miss visible in the output.
Test stdout and stderr in the same file by adding the first row below between A1 and A2 in the alpha file, and the second between A3 and A4 in that same file. Keep beta’s file as it was. In the local run, stdout’s INFO did not break the CRI join on stderr. The stdout frame-shaped line was emitted on its own while alpha’s stderr retained A3 and A4. Both added rows used the alpha path, so this checks stream separation independently of pod separation.
2026-01-10T09:00:01.250000000Z stdout F INFO [example=alpha-stdout-01] sibling stream still active
2026-01-10T09:00:03.500000000Z stdout F at com.example.control.Stdout.only(Stdout.java:7)
To test two active containers on stderr, start with A1 and A2 in alpha and leave B1 in beta. Add the first row below to beta before starting Fluent Bit. With both headers in play, append A3 to alpha, the second row below to beta, and then A4 to alpha in quick succession. The local run returned both exceptions separately. Alpha kept its two payments frames. The beta Java exception contained only Lookup.find, and the original beta INFO remained a separate document. The two exception headers use the same Java class and stream, so the test depends on the file part of the routing tag.
2026-01-10T09:00:02.500000000Z stderr F ERROR [example=inventory-beta-java-01] java.lang.IllegalStateException: item missing
2026-01-10T09:00:03.250000000Z stderr F at com.example.inventory.Lookup.find(Lookup.java:8)
To deliver a frame after the flush boundary, leave A4 out of alpha and start the full config in one terminal. Wait until the alpha document containing the header and A3 appears on stdout. From a second terminal in the same scratch directory, append the original A4 below. The date on A4 can stay unchanged because the pause is in delivery to Fluent Bit.
printf '%s\n' '2026-01-10T09:00:04Z stderr F at com.example.payments.PaymentController.post(PaymentController.java:19)' >> pods/payments_payments-api-alpha-alpha/payments-api/0.log
On 3.1.9 the late A4 came out as the separate document below. The emitted header stayed unchanged. The late payload retained A1’s event timestamp and lacked time, stream, _p and source_file. The pinned multiline implementation can empty the group buffer while retaining its continuation state. The late line matches that state without supplying a new header’s timestamp or source fields. Use the raw row for A4’s original time and source when diagnosing this case.
{
"event_time": "2026-01-10T09:00:01.000000Z",
"log": " at com.example.payments.PaymentController.post(PaymentController.java:19)"
}
Insert an unrelated line on the same stream by placing the following row between A3 and A4 in alpha, then run the same commands again. The new INFO closed the pending Java group in the local test. The INFO emerged with its own source fields. A4 emerged as a separate frame with the same stale timestamp and missing fields as the late append. If two exceptions or threads write within one file and stream, declare ownership ambiguous whenever frame-shaped lines can plausibly belong to either active exception and the frame rows carry no reliable identifier. Contiguous text with a plausible order cannot prove ownership. Have the application emit one structured event per exception or carry an identifier on each independently written line.
2026-01-10T09:00:03.750000000Z stderr F INFO [example=alpha-boundary-01] retry scheduled
To reproduce an incomplete trace caused by a skipped row, add the following three lines to Tail’s [INPUT] block. In alpha, extend A4 on the same physical row with 2,500 lowercase x characters and put the retry INFO row from the previous control after it. The local run logged that it was skipping long lines and read the later INFO. The Java document contained the header and A3. No separate A4 appeared at stdout because Tail skipped its physical row before the Java filter received it.
Buffer_Chunk_Size 1k
Buffer_Max_Size 1k
Skip_Long_Lines On
When a real exception looks truncated, compare the raw file with the CRI-only output first. Check that the relevant file was still being followed and that the selected copy includes the final CRI fragment and all Java lines. If a frame reaches the CRI-only output and then appears on its own after Java grouping, look at its shape, tag and arrival time. If its bytes are absent from the raw rows, changing the Java timeout cannot recover them.
After the local proof, verify the fields your intended OpenSearch Dashboards panel uses for time, namespace, pod, container and severity. The example gives you a path and stream for checking origin. Your shipped records need the field names and types the panel queries. Logit.io’s Kubernetes dashboard guide distinguishes container log documents from Kubernetes Event objects and describes the fields its Filebeat-based packs expect. Kubernetes dashboard field guide.
The walkthrough above uses a local stdout output so you can inspect the assembled documents. When you ship to a Logit.io Logs stack, use the Fluent Bit output from the Fluent Bit integration guide. Copy the host and port from that integration for your stack. The documented output is:
[OUTPUT]
Name http
Match *
Host @logstash.host
Port @logstash.sslPort
tls On
Format json_lines
json_date_format iso8601
json_date_key @timestamp
After shipping, click Launch Logs on the stack to open OpenSearch Dashboards, then open Dev Tools. Search the Logs stack index pattern *-*. The values below are from the example marker used in this article. Replace them with the marker and stream from your own event.
GET *-*/_search
{
"size": 5,
"sort": [ { "@timestamp": "desc" } ],
"query": {
"bool": {
"filter": [
{ "term": { "stream.keyword": "stderr" } },
{ "match_phrase": { "log": "example=java-alpha-01" } }
]
}
}
}
If a term filter returns no hits, check the field mapping in Dev Tools with GET *-*/_mapping. Text fields are analysed, so an exact term query may miss. Retry on the .keyword subfield, or without .keyword if you started there and the value lives on the text field. After shipping, open a known document and use the field names you actually see, in case your pipeline renamed log or stream.
Unlock complete visibility with hosted ELK, Grafana, and Prometheus-backed Observability
FAQ
Why do I still see one document per Java frame?
Start with the CRI-only output. If the header is complete, confirm the Java filter sees the string in log, sees the expected indentation and matches the stream-qualified tag. Try a header from your logger against the chosen start rule, then check which continuation breaks the sequence.
Can I use the built-in Java parser?
Yes, it matched the simple baseline in 3.1.9 when substituted for java_example in the filter. Keep the stream-qualified routing and test the headers, caused-by sections, suppressed exceptions and elided frames that your logger actually writes. The custom parser shown here is specific to the example’s marked header and simple frames.
Will a longer timeout keep all the frames together?
It can help when the right frame reaches the right group after the current flush boundary. Compare a timed append with a run where all rows arrive together. A longer wait also delays output for groups that finish by timeout. Check for a nonmatching line or skipped input before changing the timer.
Can I order fragments by timestamp to recover the exception?
Use file order within the source and stream. Beta’s timestamp sits between the alpha fragments, and buffered output can change the order in which documents appear. A timestamp orders observations in time but carries no information about which same-stream frame belongs to which exception.
What should I check when old documents are still split?
Validate a newly emitted, uniquely marked exception after updating Fluent Bit and compare that document with the raw CRI rows. Treat historical copies separately. Any reconstruction needs surviving source evidence that ties the old frames to the relevant header.
Can I test the shipping workflow during the Logit.io free trial?
The Logit.io free trial includes every feature, including a Logs stack and the Fluent Bit integration. The trial lasts 14 days and requires no credit card. Logit.io getting started guide · Fluent Bit integration for Logit.io.
Next steps
- Once the local document matches the example, ship it with the documented HTTP output:
Name httpwithtls OnandFormat json_lines. Fluent Bit integration for Logit.io. - Use the Logs workflow to find a newly shipped, marked exception and compare its source fields and frame order with your local result. Find your first Fluent Bit logs.
