Files
letta-server/letta/otel/resource.py
Kian Jones fbd89c9360 fix: replace all 'PRODUCTION' references with 'prod' for consistency (#6627)
* fix: replace all 'PRODUCTION' references with 'prod' for consistency

Problem: Codebase had 11 references to 'PRODUCTION' (uppercase) that should
use 'prod' (lowercase) for consistency with the deployment workflows and
environment normalization.

Changes across 8 files:

1. Source files (using settings.environment):
   - letta/functions/function_sets/multi_agent.py
   - letta/services/tool_manager.py
   - letta/services/tool_executor/multi_agent_tool_executor.py
   - letta/services/helpers/agent_manager_helper.py
   All checks changed from: settings.environment == "PRODUCTION"
   To: settings.environment == "prod"

2. OTEL resource configuration:
   - letta/otel/resource.py
     - Updated _normalize_environment_tag() to handle 'prod' directly
     - Removed 'PRODUCTION' -> 'prod' mapping (no longer needed)
     - Updated device.id check from _env != "PRODUCTION" to _env != "prod"

3. Test files:
   - tests/managers/conftest.py
     - Fixture parameter changed from "PRODUCTION" to "prod"
   - tests/managers/test_agent_manager.py (3 occurrences)
   - tests/managers/test_tool_manager.py (2 occurrences)
   All test checks changed to use "prod"

Result: Complete consistency across the codebase:
- All environment checks use "prod" instead of "PRODUCTION"
- Normalization function simplified (no special case for PRODUCTION)
- Tests use correct "prod" value
- Matches deployment workflow configuration from PR #6626

This completes the environment naming standardization effort.

* fix: update settings.py environment description to use 'prod' instead of 'PRODUCTION'

The field description still referenced PRODUCTION as an example value.
Updated to use lowercase 'prod' for consistency with actual usage.

Before: "Application environment (PRODUCTION, DEV, CANARY, etc. - normalized to lowercase for OTEL tags)"
After: "Application environment (prod, dev, canary, etc. - lowercase values used for OTEL tags)"
2025-12-15 12:02:34 -08:00

61 lines
1.8 KiB
Python

import socket
import sys
import uuid
from opentelemetry.sdk.resources import Resource
from letta import __version__ as letta_version
from letta.settings import settings
_resources = {}
def _normalize_environment_tag(env: str) -> str:
"""
Normalize environment value for OTEL deployment.environment tag.
Maps internal environment values to abbreviated lowercase tags for Datadog.
Examples:
DEV -> dev
DEVELOPMENT -> dev
STAGING -> dev
prod -> prod (already normalized)
canary -> canary
local-test -> local-test
"""
if not env:
return "unknown"
env_upper = env.upper()
# Map known values to abbreviated forms
if env_upper == "DEV" or env_upper == "DEVELOPMENT":
return "dev"
elif env_upper == "STAGING":
return "dev" # Staging maps to dev
else:
# For other values (prod, canary, local-test, etc.), use lowercase as-is
return env.lower()
def get_resource(service_name: str) -> Resource:
_env = settings.environment
if (service_name, _env) not in _resources:
resource_dict = {
"service.name": service_name,
"letta.version": letta_version,
"host.name": socket.gethostname(),
}
# Add deployment environment for Datadog APM filtering (normalized to abbreviated lowercase)
if _env:
resource_dict["deployment.environment"] = _normalize_environment_tag(_env)
# Only add device.id in non-production environments (for debugging)
if _env != "prod":
resource_dict["device.id"] = uuid.getnode() # MAC address as unique device identifier,
_resources[(service_name, _env)] = Resource.create(resource_dict)
return _resources[(service_name, _env)]
def is_pytest_environment():
return "pytest" in sys.modules