Fix OpenTelemetry initialization - remove ENABLE_OPENTELEMETRY dependency

- Always initialize OpenTelemetry in Django settings (instrumentation always enabled)
- Remove ENABLE_OPENTELEMETRY feature flag from config.py
- Simplify views.py OpenTelemetry imports to always use real implementation
- Export control now handled by OTEL_EXPORT_ENABLED environment variable only

This ensures OpenTelemetry is properly initialized during Django startup
and the Prometheus metrics server starts correctly.
This commit is contained in:
Oliver Falk
2025-10-17 14:43:05 +02:00
parent c17b078913
commit 8e61f02702
4 changed files with 87 additions and 48 deletions

View File

@@ -20,6 +20,7 @@ import argparse
import json
import random
import ssl
import subprocess
import sys
import tempfile
import time
@@ -57,6 +58,52 @@ def colored_print(message: str, color: str = Colors.NC) -> None:
print(f"{color}{message}{Colors.NC}")
def get_current_commit_hash() -> Optional[str]:
"""Get the current commit hash from git."""
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except (subprocess.CalledProcessError, FileNotFoundError):
return None
def is_commit_newer_or_equal(commit1: str, commit2: str) -> Optional[bool]:
"""
Check if commit1 is newer than or equal to commit2 in git history.
Returns:
True if commit1 is newer or equal to commit2
False if commit1 is older than commit2
None if comparison fails
"""
try:
# Use git merge-base to check if commit1 is reachable from commit2
# If commit1 is newer or equal, it should be reachable from commit2
subprocess.run(
["git", "merge-base", "--is-ancestor", commit2, commit1],
capture_output=True,
check=True,
)
return True
except subprocess.CalledProcessError:
# If the above fails, try the reverse - check if commit2 is newer
try:
result = subprocess.run(
["git", "merge-base", "--is-ancestor", commit1, commit2],
capture_output=True,
check=True,
)
return False
except subprocess.CalledProcessError:
# If both fail, we can't determine the relationship
return None
def make_request(
url: str,
method: str = "GET",
@@ -289,14 +336,43 @@ def test_deployment(
)
# Display version information
commit_hash = version_info.get("commit_hash", "Unknown")
deployed_commit = version_info.get("commit_hash", "Unknown")
branch = version_info.get("branch", "Unknown")
version = version_info.get("version", "Unknown")
colored_print(f"Deployed commit: {commit_hash}", Colors.BLUE)
colored_print(f"Deployed commit: {deployed_commit}", Colors.BLUE)
colored_print(f"Deployed branch: {branch}", Colors.BLUE)
colored_print(f"Deployed version: {version}", Colors.BLUE)
# Check if we're looking for a specific version and compare
current_commit = get_current_commit_hash()
if current_commit and deployed_commit != "Unknown":
if deployed_commit == current_commit:
colored_print(
"✅ Exact version match - deployment is up to date!",
Colors.GREEN,
)
else:
# Check if deployed version is newer
comparison = is_commit_newer_or_equal(
deployed_commit, current_commit
)
if comparison is True:
colored_print(
" Note: A newer version is already deployed (this is fine!)",
Colors.YELLOW,
)
elif comparison is False:
colored_print(
"⚠️ Warning: Deployed version appears to be older than expected",
Colors.YELLOW,
)
else:
colored_print(
"⚠️ Warning: Could not determine version relationship",
Colors.YELLOW,
)
# Run functionality tests
colored_print("Running basic functionality tests...", Colors.YELLOW)