Add OpenTelemetry integration

- Add OpenTelemetry dependencies to requirements.txt
- Implement OpenTelemetry configuration with feature flag support
- Add OpenTelemetry middleware for custom metrics and tracing
- Update Django settings to conditionally enable OpenTelemetry
- Add comprehensive test suite for OpenTelemetry functionality
- Create test scripts for running with/without OpenTelemetry
- Add pytest markers for OpenTelemetry test categorization
- Update documentation with OpenTelemetry setup and infrastructure details

Features:
- Feature flag controlled (ENABLE_OPENTELEMETRY) for F/LOSS deployments
- Localhost-only security model
- Custom avatar metrics and tracing
- Graceful fallback when OpenTelemetry is disabled
- Comprehensive test coverage for both enabled/disabled states
This commit is contained in:
Oliver Falk
2025-10-16 14:19:24 +02:00
parent 2c5e7ab90f
commit 7258d911c8
14 changed files with 2227 additions and 4 deletions

View File

@@ -34,6 +34,9 @@ MIDDLEWARE.extend(
"ivatar.middleware.CustomLocaleMiddleware",
]
)
# Add OpenTelemetry middleware only if feature flag is enabled
# Note: This will be checked at runtime, not at import time
MIDDLEWARE.insert(
0,
"ivatar.middleware.MultipleProxyMiddleware",
@@ -309,6 +312,13 @@ ENABLE_MALICIOUS_CONTENT_SCAN = True
# Logging configuration - can be overridden in local config
# Example: LOGS_DIR = "/var/log/ivatar" # For production deployments
# OpenTelemetry feature flag - can be disabled for F/LOSS deployments
ENABLE_OPENTELEMETRY = os.environ.get("ENABLE_OPENTELEMETRY", "false").lower() in (
"true",
"1",
"yes",
)
# This MUST BE THE LAST!
if os.path.isfile(os.path.join(BASE_DIR, "config_local.py")):
from config_local import * # noqa # flake8: noqa # NOQA # pragma: no cover