# Quick Start Guide

        Get your first logs flowing into Trailonix in under 5 minutes! This guide will walk you through creating a tenant, setting up an API key, and sending your first log event.

        ## Step 1: Create a Tenant

        A **tenant** represents your application or environment (e.g., "Production App", "Development", "Staging").

        1. **Navigate to "Tenants"** in the Administration section of your dashboard
        2. **Click the "+ Tenant" button** in the top right
        3. **Enter a descriptive name** for your application (e.g., "Test Tenant", "Production API")
        4. **Click "Save"** to create your tenant

        ![Create Tenant](images/create-tenant-dialog.webp)

        > **💡 Tip:** Use clear names like "Production API", "Mobile App", or "Website Analytics" to easily identify different applications. You can see your active tenant count in the top bar.

        ## Step 2: Create an API Key

        API keys authenticate your application when sending logs to Trailonix.

        1. **Go to "API Keys"** in the Administration section
        2. **Click "+ API Key"** to create a new key
        3. **Fill in the details:**
          - **Name**: Descriptive name (e.g., "New API Key", "Production Logger")
          - **Tenant**: Select your tenant from the dropdown (e.g., "Test Tenant")
          - **Expiration**: Set an expiration date or leave blank for no expiration
        4. **Set Permissions:**
          - **✅ Check "WRITE" under Logs** (required for sending logs)
          - Leave "READ" unchecked unless you need to query logs via API
        5. **Click "Save"**

        ![API Key Creation](images/create-api-key-form.webp)

        After creating the key, you'll see a success message with your API key:

        ![API Key Created](images/api-key-created.webp)

        > **⚠️ Critical:** Copy and save the API key immediately! This is the only time you'll see the full key. Keys are encrypted and cannot be retrieved later, but you can always create a new one if needed.

        ## Important: Privacy & Data Protection

        > **🔒 PII Protection:** Trailonix automatically protects your users' privacy by scrubbing common PII fields from metadata. If you include restricted fields, you'll see `[REDACTED]` in your logs.

        **Never include these types of data in your logs:**
        - Social Security Numbers (SSN)
        - Credit card numbers or payment details
        - Passwords or password hashes
        - Driver's license numbers
        - State or national ID numbers
        - Tax identification numbers
        - Voter registration IDs
        - Full names, addresses, or phone numbers

        **Safe alternatives:**
        - Use **user IDs** instead of names: `"userId": "user_12345"`
        - Use **masked values**: `"email": "john****@example.com"`
        - Use **boolean flags**: `"has_payment_method": true`
        - Use **categories**: `"user_type": "premium"`

        ## Step 3: Send Your First Log

        Now you're ready to start logging! Send a POST request to the Trailonix API.

        > **📖 Complete API Documentation:** For detailed information about request/response formats, error codes, and advanced options, see our [full API documentation](https://trailonix.com/assets/api-documentation.html#/paths/~1api~1v1~1log-events/post).

        ### API Endpoint
        ```
        POST https://trailonix.com/api/v1/logevent
        ```

        ### Headers
        ```bash
        Authorization: YOUR_API_KEY
        Content-Type: application/json
        ```

        ### Request Body Structure

        | Field | Type | Required | Description |
        |-------|------|----------|-------------|
        | `eventType` | string | ✅ | Type of event (**free text, user-defined** - e.g., "user_login", "UserLogin") |
        | `userId` | string | ❌ | ID of the user who performed the action |
        | `resource` | string | ❌ | Resource affected by the action |
        | `metadata` | object | ❌ | Additional context as JSON object |
        | `ipAddress` | string | ❌ | Client IP address |
        | `userAgent` | string | ❌ | User agent of the request |
        | `createdDate` | string | ❌ | Event timestamp (defaults to "UTC NOW") |

        ### Example: User Login Event

        ```bash
        curl -X POST https://trailonix.com/api/v1/logevent \
          -H "Authorization: YOUR_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "eventType": "user_login",
            "userId": "user_12345",
            "resource": "authentication",
            "metadata": {
              "login_method": "email",
              "success": true,
              "mfa_enabled": false,
              "device": "desktop",
              "session_id": "sess_abc123"
            },
            "ipAddress": "192.168.1.100",
            "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
          }'
        ```

        ### Example: Error Event

        ```bash
        curl -X POST https://trailonix.com/api/v1/logevent \
          -H "Authorization: YOUR_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "eventType": "payment_failed",
            "userId": "user_67890",
            "resource": "order_123",
            "metadata": {
              "error_code": "insufficient_funds",
              "amount": 99.99,
              "currency": "USD",
              "payment_method_type": "credit_card",
              "retry_attempt": 1
            }
          }'
        ```

        ### Example: System Event

        ```bash
        curl -X POST https://trailonix.com/api/v1/logevent \
          -H "Authorization: YOUR_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "eventType": "server_restart",
            "resource": "api_server_001",
            "metadata": {
              "reason": "scheduled_maintenance",
              "downtime_seconds": 30,
              "version": "2.1.4"
            }
          }'
        ```

        ## Verify Your Logs

        1. **Go to the Logs section** in your Trailonix dashboard
        2. **Select your tenant** from the dropdown
        3. **You should see your log events** in the list (refresh the page to see new logs)

        ## Common Event Types

        > **Remember:** These are just **examples**! You can create any event type that makes sense for your application. The key is being consistent with your naming.

        Here are some popular patterns to get you started:

        ### Authentication
        - `user_login`, `user_logout`, `password_reset`, `mfa_challenge`

        ### Errors & Exceptions
        - `error_occurred`, `api_timeout`, `database_error`, `validation_failed`

        ### Business Events
        - `order_created`, `payment_processed`, `user_registered`, `subscription_renewed`

        ### System Events
        - `server_started`, `backup_completed`, `deployment_finished`, `cache_cleared`

        ## Best Practices

        ### Event Type Naming
        > **📝 Important:** Event types are **completely free text** - you define them! Trailonix doesn't have predefined event types.

        - **Be consistent!** This is crucial for alerts and filtering
          - ✅ Good: Always use `user_login`
          - ❌ Bad: Mix `user_login`, `userLogin`, `User_Login`
        - **Choose a naming convention** and stick to it:
          - `snake_case`: `user_login`, `payment_failed`
          - `camelCase`: `userLogin`, `paymentFailed`
          - `kebab-case`: `user-login`, `payment-failed`
        - **Be specific but concise**: `user_login` not `user_action`
        - **Group related events** with prefixes: `payment_started`, `payment_completed`, `payment_failed`

        > **💡 Pro Tip:** Consistency in event types is essential for setting up effective alert rules. If you use different variations of the same event, your alerts may miss important occurrences!

        ### Metadata Structure
        - Keep metadata **flat when possible**
        - Use **consistent field names** across events
        - Include **relevant context** for debugging
        - **Avoid PII** - use IDs, categories, and boolean flags instead of personal details

        ### Security & Privacy
        - **Never log PII (Personally Identifiable Information)** - Trailonix automatically scrubs common PII fields
        - **Rotate API keys regularly** for production applications
        - **Use separate tenants** for different environments

        ## What's Next?

        Now that you're logging events, you can:

        - **[Set up alerts](/guides/setting-up-alerts)** to get notified when specific event types occur (this is why consistency matters!)
        - **[Explore the dashboard](/guides/dashboard)** to analyze your log data
        - **[Learn about event type strategies](/guides/event-types)** for organizing your logs effectively
        - **Integrate with your application** [javascript & Node.js](/examples/javascript) **[PHP](/examples/php)** **[Python](/examples/python)** **[C#/.NET](/examples/csharp)**

        ---

        **🎉 Congratulations!** You're now logging with Trailonix. Check out our integration examples for your specific programming language or framework.