File size: 1,544 Bytes
95db528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Configuration module for gesture detection system.
Handles environment variables and logfire token configuration.
"""

import os
from pathlib import Path
from typing import Optional


def get_logfire_token() -> Optional[str]:
    """
    Get the logfire token from environment variables or local configuration.
    
    Priority order:
    1. LOGFIRE_TOKEN environment variable (for production/deployment)
    2. .env file in project root (for local development)
    3. None (monitoring disabled)
    
    Returns
    -------
    Optional[str]
        The logfire token if found, None otherwise
    """
    # First check environment variable (for production)
    token = os.getenv("LOGFIRE_TOKEN")
    if token:
        return token
    
    # Check for .env file in project root (for local development)
    env_file = Path(__file__).parent.parent.parent / ".env"
    if env_file.exists():
        try:
            with open(env_file, "r") as f:
                for line in f:
                    line = line.strip()
                    if line.startswith("LOGFIRE_TOKEN="):
                        return line.split("=", 1)[1].strip('"\'')
        except Exception:
            # If we can't read the .env file, continue without token
            pass
    
    return None


def is_monitoring_enabled() -> bool:
    """
    Check if monitoring is enabled by checking if we have a logfire token.
    
    Returns
    -------
    bool
        True if monitoring is enabled, False otherwise
    """
    return get_logfire_token() is not None