-
-
Notifications
You must be signed in to change notification settings - Fork 99
feat(audit): log audio endpoint bodies with dashboard playback #364
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6348b30
fix(audit): log audio endpoints as model interactions
SantiagoDePolonia fdfef29
feat(audit): capture audio bodies behind LOGGING_LOG_AUDIO_BODIES wit…
SantiagoDePolonia 720d3bc
docs(audit): document LOGGING_LOG_AUDIO_BODIES and audio body logging
SantiagoDePolonia 88fb970
refactor(audit): gate audio body logging under LOGGING_LOG_BODIES
SantiagoDePolonia 6a43c80
fix(audit): address PR review on audio body logging
SantiagoDePolonia 99dc76c
fix(audit): lower audio body cap for storage headroom; drop CSS fallback
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package auditlog | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "strings" | ||
| ) | ||
|
|
||
| // audioBodyMaxBytes caps how much *raw* audio is embedded as base64 in an audit | ||
| // log entry; larger payloads are recorded as metadata-only placeholders so the | ||
| // audit store does not balloon on long generations. The stored base64 is ~4/3 of | ||
| // this (≈10.7 MB at the cap), deliberately kept well under document-store | ||
| // per-record ceilings (e.g. MongoDB's 16 MB BSON limit) so a near-cap clip plus | ||
| // the rest of the entry (request text, headers, workflow metadata) and encoding | ||
| // overhead cannot push the document over the limit and fail the audit insert. | ||
| const audioBodyMaxBytes = 8 * 1024 * 1024 | ||
|
|
||
| // AudioBodyLog is the audit representation of an audio request/response body. | ||
| // The "__audio__" marker lets the dashboard detect audio payloads and render a | ||
| // player (when Data is present) or a labeled placeholder. When Data is set it | ||
| // holds the base64-encoded audio, suitable for a data: URL of ContentType. | ||
| type AudioBodyLog struct { | ||
| Audio bool `json:"__audio__" bson:"__audio__"` | ||
| ContentType string `json:"content_type,omitempty" bson:"content_type,omitempty"` | ||
| Bytes int `json:"bytes" bson:"bytes"` | ||
| Encoding string `json:"encoding,omitempty" bson:"encoding,omitempty"` | ||
| Data string `json:"data,omitempty" bson:"data,omitempty"` | ||
| Stored bool `json:"stored" bson:"stored"` | ||
| TooLarge bool `json:"too_large,omitempty" bson:"too_large,omitempty"` | ||
| } | ||
|
|
||
| // IsAudioContentType reports whether a Content-Type denotes an audio payload. | ||
| func IsAudioContentType(contentType string) bool { | ||
| mediaType := strings.ToLower(strings.TrimSpace(strings.Split(contentType, ";")[0])) | ||
| return strings.HasPrefix(mediaType, "audio/") | ||
| } | ||
|
|
||
| // BuildAudioResponseBody builds the audit value for a binary audio response. | ||
| // When storeBytes is true and the payload fits within audioBodyMaxBytes the | ||
| // audio is embedded as base64 for playback; otherwise only metadata is kept. | ||
| func BuildAudioResponseBody(contentType string, data []byte, storeBytes bool) AudioBodyLog { | ||
| body := AudioBodyLog{ | ||
| Audio: true, | ||
| ContentType: strings.TrimSpace(contentType), | ||
| Bytes: len(data), | ||
| } | ||
| if !storeBytes || len(data) == 0 { | ||
| return body | ||
| } | ||
| if len(data) > audioBodyMaxBytes { | ||
| body.TooLarge = true | ||
| return body | ||
| } | ||
| body.Encoding = "base64" | ||
| body.Data = base64.StdEncoding.EncodeToString(data) | ||
| body.Stored = true | ||
| return body | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.