- 
                Notifications
    You must be signed in to change notification settings 
- Fork 467
Telemetry update #1071
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
                    Telemetry update #1071
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0a0e221
              
                Credentials -> RC; add RC to settings
              
              
                CalebCourier 59861df
              
                test updates
              
              
                CalebCourier 8e58413
              
                we know it's deprecated; we deprecated it...
              
              
                CalebCourier 27eb0b4
              
                guard execution tracing with isolated context
              
              
                CalebCourier 57fbb04
              
                trace async guard
              
              
                CalebCourier 3d3b31c
              
                runner, validator, and cli updates
              
              
                CalebCourier 5d35331
              
                Merge branch 'main' into telemetry-update
              
              
                CalebCourier ec04a9a
              
                validator usage
              
              
                CalebCourier ec6a564
              
                move hub telemetry to avoid circular dependency in cli
              
              
                CalebCourier 1ba15f2
              
                tests, lint, some type
              
              
                CalebCourier 56882fd
              
                don't type trace wrappers
              
              
                CalebCourier d3faf51
              
                Merge branch 'main' into telemetry-update
              
              
                CalebCourier fdaa0ed
              
                fix context issues
              
              
                CalebCourier 47d74ed
              
                revert endpoint
              
              
                CalebCourier cbcd550
              
                default enabled to rc setting
              
              
                CalebCourier 48c93f4
              
                address PR comments
              
              
                CalebCourier 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
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import logging | ||
| import os | ||
| from dataclasses import dataclass | ||
| from os.path import expanduser | ||
| from typing import Optional | ||
|  | ||
| from guardrails.classes.generic.serializeable import Serializeable | ||
| from guardrails.utils.casting_utils import to_bool | ||
|  | ||
| BOOL_CONFIGS = set(["no_metrics", "enable_metrics", "use_remote_inferencing"]) | ||
|         
                  dtam marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
|  | ||
| @dataclass | ||
| class RC(Serializeable): | ||
| id: Optional[str] = None | ||
| token: Optional[str] = None | ||
| enable_metrics: Optional[bool] = True | ||
| use_remote_inferencing: Optional[bool] = True | ||
|  | ||
| @staticmethod | ||
| def exists() -> bool: | ||
| home = expanduser("~") | ||
| guardrails_rc = os.path.join(home, ".guardrailsrc") | ||
| return os.path.exists(guardrails_rc) | ||
|  | ||
| @classmethod | ||
| def load(cls, logger: Optional[logging.Logger] = None) -> "RC": | ||
| try: | ||
| if not logger: | ||
| logger = logging.getLogger() | ||
| home = expanduser("~") | ||
| guardrails_rc = os.path.join(home, ".guardrailsrc") | ||
| with open(guardrails_rc, encoding="utf-8") as rc_file: | ||
| lines = rc_file.readlines() | ||
| filtered_lines = list(filter(lambda l: l.strip(), lines)) | ||
| config = {} | ||
| for line in filtered_lines: | ||
| line_content = line.split("=", 1) | ||
| if len(line_content) != 2: | ||
| logger.warning( | ||
| """ | ||
| Invalid line found in .guardrailsrc file! | ||
| All lines in this file should follow the format: key=value | ||
| Ignoring line contents... | ||
| """ | ||
| ) | ||
| logger.debug(f".guardrailsrc file location: {guardrails_rc}") | ||
| else: | ||
| key, value = line_content | ||
| key = key.strip() | ||
| value = value.strip() | ||
| if key in BOOL_CONFIGS: | ||
| value = to_bool(value) | ||
|  | ||
| config[key] = value | ||
|  | ||
| rc_file.close() | ||
|  | ||
| # backfill no_metrics, handle defaults | ||
| # We missed this comment in the 0.5.0 release | ||
| # Making it a TODO for 0.6.0 | ||
| # TODO: remove in 0.6.0 | ||
| no_metrics_val = config.pop("no_metrics", None) | ||
| if no_metrics_val is not None and config.get("enable_metrics") is None: | ||
| config["enable_metrics"] = not no_metrics_val | ||
|  | ||
| rc = cls.from_dict(config) | ||
| return rc | ||
|  | ||
| except FileNotFoundError: | ||
| return cls.from_dict({}) # type: ignore | ||
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      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.