fix(logs-forwarder): unwrap OCI Streaming base64 envelope before formatting - #184
Draft
yuhuyoyo wants to merge 1 commit into
Draft
fix(logs-forwarder): unwrap OCI Streaming base64 envelope before formatting#184yuhuyoyo wants to merge 1 commit into
yuhuyoyo wants to merge 1 commit into
Conversation
…atting
When a Service Connector Hub source is OCI Streaming (e.g. cross-tenancy
audit log forwarding via a stream), each message is delivered in a base64
envelope whose "value" field holds the real log JSON. The logs-forwarder
decoded the body as plain log entries without unwrapping, so the fields it
reads (source, time, data, oracle, type) were absent and logs were forwarded
empty (only `{"service":"oci"}`).
Add formatter.UnwrapStreamingMessages, which base64-decodes the "value"
field of streaming envelopes and leaves plain (non-streaming) log entries
untouched, and call it in formatLogs before formatting. This mirrors the
behavior the events-forwarder already has for streaming sources.
Co-Authored-By: Claude Code <noreply@anthropic.com>
There was a problem hiding this comment.
More details
The new decoder unwraps the streaming envelope before formatting. It keeps entries with a top-level data field on the plain-log path.
🤖 Datadog Autotest · Commit fb435ab · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Customers using a cross-tenancy audit log topology — tenancy A audit logs → OCI Streaming → Service Connector Hub → logs-forwarder function in tenancy B — were receiving completely empty log messages in Datadog (only
{"oci":{"service":"oci"}}, no actual log content).Root cause
When a Service Connector Hub (SCH) source is OCI Streaming, SCH delivers each message in a base64 envelope:
{"streamPool":"...","stream":"...","partition":"0","key":"","value":"<base64-encoded log JSON>","offset":"0","timestamp":"..."}The actual log JSON (with
source,time,data,oracle,type) lives base64-encoded insidevalue, not at the top level.The logs-forwarder's
formatLogsdecoded the body as plain log entries and handed each map straight toProcessLogEntry, which reads those top-level fields. Since none of them exist on the streaming envelope,getFieldValuereturned""/ empty maps — producing an empty log with onlyservice: oci(the one always-emitted field).Notably, the events-forwarder already handles this —
events-forwarder/internal/formatter/formatter.gobase64-decodes thevaluefield for streaming sources. The logs-forwarder did not, so the two forwarders behaved inconsistently for the same SCH streaming topology.Fix
Add
formatter.UnwrapStreamingMessages, which:valuefield of streaming envelopes into the real log entry, andvaluestring field AND no top-leveldatafield).Wire it into
formatLogsright after JSON decoding, before formatting. This is backward-compatible — existing Logging-source connectors (novalueenvelope, or entries with adatafield) keep working as before.Files changed
logs-forwarder/internal/formatter/formatter.go— new exportedUnwrapStreamingMessageslogs-forwarder/internal/handler/handler.go— call it informatLogslogs-forwarder/internal/formatter/formatter_test.go— unit tests for unwrap + end-to-end testlogs-forwarder/internal/handler/handler_test.go— streaming-envelope case inTestFormatLogsWhy not avoid the encoding at the source?
The base64 wrapping is inherent to OCI Streaming — there's no SCH setting to deliver stream messages decoded. The stream is the only transport that bridges tenancies A→B (log groups don't cross tenancies), so decoding in the function is the correct fix rather than dropping the stream.
Test plan
go build ./...passesgo test ./...passes (formatter + handler packages)data/oracle/source/typeandddsource: oci.audit🤖 Generated with Claude Code