- 
                Notifications
    You must be signed in to change notification settings 
- Fork 429
docs: add Apitally to integrations #601
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
          
     Open
      
      
            itssimon
  wants to merge
  5
  commits into
  elysiajs:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
itssimon:main
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| --- | ||
| title: Apitally - ElysiaJS | ||
| head: | ||
| - - meta | ||
| - property: 'og:title' | ||
| content: Apitally - ElysiaJS | ||
|  | ||
| - - meta | ||
| - name: 'description' | ||
| content: We may use Apitally to capture API metrics and logs. | ||
|  | ||
| - - meta | ||
| - name: 'og:description' | ||
| content: We may use Apitally to capture API metrics and logs. | ||
| --- | ||
|  | ||
| # Apitally | ||
|  | ||
| [Apitally](https://apitally.io/elysia) is a simple API monitoring and analytics tool with an official plugin for Elysia. | ||
|  | ||
| It provides real-time insights into API usage, errors, and performance. It also captures API request logs and application logs, | ||
| which are automatically correlated. | ||
|  | ||
|  | ||
|  | ||
| ## Basic setup | ||
|  | ||
| 1. [Sign up](https://app.apitally.io/?signup) for an account, create a new app, and grab your client ID. | ||
|  | ||
| 2. Install the open-source [Apitally SDK](https://github.com/apitally/apitally-js): | ||
|  | ||
| ```bash | ||
| bun add apitally | ||
| ``` | ||
|  | ||
| 3. Add the plugin to your Elysia instance and pass in your client ID: | ||
|  | ||
| ```typescript | ||
| import { Elysia } from "elysia"; | ||
| import { apitallyPlugin } from "apitally/elysia"; | ||
|  | ||
| const app = new Elysia() | ||
| .use( | ||
| apitallyPlugin({ | ||
| clientId: "your-client-id", | ||
| env: "dev", // or "prod" etc. | ||
| }), | ||
| ) | ||
| .get("/", () => "hello"); | ||
| ``` | ||
|  | ||
| A more detailed [setup guide for Elysia](https://docs.apitally.io/frameworks/elysia) is available in the Apitally docs. | ||
|  | ||
| ## Consumers | ||
|  | ||
| You can associate requests with consumer identifiers, allowing you get insights into API adoption and filter logs and metrics by consumer. | ||
|  | ||
| ```typescript | ||
| app.derive(async ({ apitally, jwt, cookie: { auth } }) => { | ||
| const profile = await jwt.verify(auth); | ||
| apitally.consumer = { | ||
| identifier: profile.id, | ||
| name: profile.name, // optional | ||
| group: profile.role, // optional | ||
| }; | ||
| }); | ||
| ``` | ||
|  | ||
| ## Logs | ||
|  | ||
| Capturing request and applications logs is disabled by default. You can enable it by passing the `requestLogging` option to the plugin and | ||
| configure in detail what's included in the logs. | ||
|  | ||
| ```typescript | ||
| import { Elysia } from "elysia"; | ||
| import { apitallyPlugin } from "apitally/elysia"; | ||
|  | ||
| const app = new Elysia() | ||
| .use( | ||
| apitallyPlugin({ | ||
| clientId: "your-client-id", | ||
| env: "dev", // or "prod" etc. | ||
| requestLogging: { // [!code ++] | ||
| enabled: true, // [!code ++] | ||
| logRequestHeaders: true, // [!code ++] | ||
| logRequestBody: true, // [!code ++] | ||
| logResponseBody: true, // [!code ++] | ||
| captureLogs: true, // application logs // [!code ++] | ||
| }, // [!code ++] | ||
| }), | ||
| ) | ||
| .get("/", () => "hello"); | ||
| ``` | ||
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
  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.