- 
                Notifications
    
You must be signed in to change notification settings  - Fork 9.8k
 
[AIG] Logpush initial documentation #16798
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 2 commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e286ba5
              
                Logpush initial documentation
              
              
                daisyfaithauma 3b303d0
              
                Update logpush.mdx
              
              
                kathayl 83e34ed
              
                Update logpush.mdx
              
              
                kathayl 569a755
              
                Added limits link
              
              
                daisyfaithauma 698dd62
              
                Updated details
              
              
                daisyfaithauma e15cf05
              
                Add script to run file
              
              
                daisyfaithauma 5c3c2b5
              
                Update logpush.mdx
              
              
                kathayl 1f2ea21
              
                Update src/content/docs/ai-gateway/observability/logpush.mdx
              
              
                daisyfaithauma 0a7318e
              
                Update src/content/docs/ai-gateway/observability/logpush.mdx
              
              
                daisyfaithauma c7b61ef
              
                Update src/content/docs/ai-gateway/observability/logpush.mdx
              
              
                daisyfaithauma 902fe61
              
                Update src/content/docs/ai-gateway/observability/logpush.mdx
              
              
                daisyfaithauma 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --- | ||
| pcx_content_type: reference | ||
| title: Logpush | ||
| sidebar: | ||
| badge: | ||
| text: Beta | ||
| --- | ||
| 
     | 
||
| import { Render } from "~/components"; | ||
| 
     | 
||
| AI Gateway allows you to securely export logs to an external storage location, where you can decrypt and process them. This guide explains how to set up Logpush for AI Gateway, generate an RSA key pair for encryption, and decrypt the logs once they are received. | ||
| Logpush has a limit of 4 jobs. | ||
| 
     | 
||
| <Render file="limits-increase" product="ai-gateway" /> | ||
| 
     | 
||
| ## Setting up Logpush | ||
| 
     | 
||
| To configure Logpush for AI Gateway, follow these steps: | ||
| 
     | 
||
| ## 1. Generate an RSA key pair locally | ||
| 
     | 
||
| You need to generate a key pair to encrypt and decrypt the logs. This script will output your RSA privateKey and publicKey. Keep the private key secure, as it will be used to decrypt the logs. Below is a sample script to generate the keys using Node.js. | ||
| 
     | 
||
| ```js title="JavaScript" | ||
| const crypto = require("crypto"); | ||
| 
     | 
||
| const { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", { | ||
| modulusLength: 4096, | ||
| publicKeyEncoding: { | ||
| type: "spki", | ||
| format: "pem", | ||
| }, | ||
| privateKeyEncoding: { | ||
| type: "pkcs8", | ||
| format: "pem", | ||
| }, | ||
| }); | ||
| 
     | 
||
| console.log(publicKey); | ||
| console.log(privateKey); | ||
| ``` | ||
| 
     | 
||
| ## 2. Upload public key to gateway settings | ||
| 
     | 
||
| Once you have generated the key pair, upload the public key to your AI Gateway settings. This key will be used to encrypt your logs. | ||
| 
     | 
||
| ## 3. Receive encrypted logs | ||
| 
     | 
||
| After configuring Logpush, logs will be sent encrypted using the public key you uploaded. To access the data, you will need to decrypt it using your private key. | ||
| 
     | 
||
| ## 4. Decrypting logs | ||
| 
     | 
||
| To decrypt the encrypted log bodies and metadata from AI Gateway, you can use the following Node.js script: | ||
| 
     | 
||
| ```js title="JavaScript" | ||
| const privateKey = `-----BEGIN RSA PRIVATE KEY----- | ||
| .... | ||
| -----END RSA PRIVATE KEY-----`; | ||
| 
     | 
||
| const crypto = require("crypto"); | ||
| const key = crypto.createPrivateKey(privateKey); | ||
| 
     | 
||
| const fs = require("fs"); | ||
| const zlib = require("zlib"); | ||
| const readline = require("readline"); | ||
| 
     | 
||
| function decryptBase64(key, string) { | ||
| const decryptedData = crypto.privateDecrypt( | ||
| { | ||
| key: key, | ||
| oaepHash: "SHA256", | ||
| }, | ||
| Buffer.from(string, "base64"), | ||
| ); | ||
| 
     | 
||
| return decryptedData.toString(); | ||
| } | ||
| 
     | 
||
| let lineReader = readline.createInterface({ | ||
| input: fs.createReadStream("my_log.log.gz").pipe(zlib.createGunzip()), | ||
| }); | ||
| 
     | 
||
| lineReader.on("line", (line) => { | ||
| line = JSON.parse(line); | ||
| 
     | 
||
| const { Metadata, RequestBody, ResponseBody, ...remaining } = line; | ||
| 
     | 
||
| console.log({ | ||
| ...remaining, | ||
| Metadata: decryptBase64(key, Metadata.data), | ||
| RequestBody: decryptBase64(key, RequestBody.data), | ||
| ResponseBody: decryptBase64(key, ResponseBody.data), | ||
| }); | ||
| console.log("--"); | ||
| }); | ||
| ``` | ||
| 
     | 
||
| ## Script Explanation | ||
| 
     | 
||
| The script reads the encrypted log file `(my_log.log.gz)`, decrypts the metadata, request body, and response body, and prints the decrypted data. | ||
                
      
                  daisyfaithauma marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| Ensure you replace the `privateKey` variable with your actual private RSA key that you generated in step 1. | ||
      
      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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.