|
|
|
""" |
|
Test Comprehensive Langfuse Monitoring Integration |
|
Verify that monitoring is consistently implemented across all critical components |
|
""" |
|
|
|
import os |
|
import sys |
|
import time |
|
from unittest.mock import patch, MagicMock |
|
|
|
def test_monitoring_imports(): |
|
"""Test that monitoring can be imported from all components""" |
|
print("π Testing monitoring imports...") |
|
|
|
try: |
|
|
|
from src.monitoring import monitor |
|
print("β
Core monitoring imported") |
|
|
|
|
|
from src.mcp_a2a_api import monitor as a2a_monitor |
|
print("β
A2A API monitoring imported") |
|
|
|
|
|
from src.fhirflame_mcp_server import monitor as mcp_monitor |
|
print("β
MCP server monitoring imported") |
|
|
|
return True |
|
|
|
except Exception as e: |
|
print(f"β Monitoring import failed: {e}") |
|
return False |
|
|
|
def test_monitoring_methods(): |
|
"""Test that all new monitoring methods are available""" |
|
print("\nπ Testing monitoring methods...") |
|
|
|
try: |
|
from src.monitoring import monitor |
|
|
|
|
|
assert hasattr(monitor, 'log_a2a_api_request'), "Missing log_a2a_api_request" |
|
assert hasattr(monitor, 'log_a2a_api_response'), "Missing log_a2a_api_response" |
|
assert hasattr(monitor, 'log_a2a_authentication'), "Missing log_a2a_authentication" |
|
print("β
A2A API monitoring methods present") |
|
|
|
|
|
assert hasattr(monitor, 'log_modal_function_call'), "Missing log_modal_function_call" |
|
assert hasattr(monitor, 'log_modal_scaling_event'), "Missing log_modal_scaling_event" |
|
assert hasattr(monitor, 'log_modal_deployment'), "Missing log_modal_deployment" |
|
assert hasattr(monitor, 'log_modal_cost_tracking'), "Missing log_modal_cost_tracking" |
|
print("β
Modal scaling monitoring methods present") |
|
|
|
|
|
assert hasattr(monitor, 'log_mcp_server_start'), "Missing log_mcp_server_start" |
|
assert hasattr(monitor, 'log_mcp_authentication'), "Missing log_mcp_authentication" |
|
print("β
MCP monitoring methods present") |
|
|
|
|
|
assert hasattr(monitor, 'log_docker_deployment'), "Missing log_docker_deployment" |
|
assert hasattr(monitor, 'log_docker_service_health'), "Missing log_docker_service_health" |
|
print("β
Docker monitoring methods present") |
|
|
|
|
|
assert hasattr(monitor, 'log_error_event'), "Missing log_error_event" |
|
assert hasattr(monitor, 'log_performance_metrics'), "Missing log_performance_metrics" |
|
print("β
Error/performance monitoring methods present") |
|
|
|
return True |
|
|
|
except Exception as e: |
|
print(f"β Monitoring methods test failed: {e}") |
|
return False |
|
|
|
def test_monitoring_functionality(): |
|
"""Test that monitoring methods work without errors""" |
|
print("\nπ Testing monitoring functionality...") |
|
|
|
try: |
|
from src.monitoring import monitor |
|
|
|
|
|
monitor.log_a2a_api_request( |
|
endpoint="/api/v1/test", |
|
method="POST", |
|
auth_method="bearer_token", |
|
request_size=100, |
|
user_id="test_user" |
|
) |
|
print("β
A2A API request monitoring works") |
|
|
|
|
|
monitor.log_modal_function_call( |
|
function_name="test_function", |
|
gpu_type="L4", |
|
processing_time=1.5, |
|
cost_estimate=0.001, |
|
container_id="test-container-123" |
|
) |
|
print("β
Modal function monitoring works") |
|
|
|
|
|
monitor.log_mcp_tool( |
|
tool_name="process_medical_document", |
|
success=True, |
|
processing_time=2.0, |
|
input_size=500, |
|
entities_found=5 |
|
) |
|
print("β
MCP tool monitoring works") |
|
|
|
|
|
monitor.log_error_event( |
|
error_type="test_error", |
|
error_message="Test error message", |
|
stack_trace="", |
|
component="test_component", |
|
severity="info" |
|
) |
|
print("β
Error monitoring works") |
|
|
|
return True |
|
|
|
except Exception as e: |
|
print(f"β Monitoring functionality test failed: {e}") |
|
return False |
|
|
|
def test_docker_compose_monitoring(): |
|
"""Test Docker Compose monitoring integration""" |
|
print("\nπ Testing Docker Compose monitoring...") |
|
|
|
try: |
|
from src.monitoring import monitor |
|
|
|
|
|
monitor.log_docker_deployment( |
|
compose_file="docker-compose.local.yml", |
|
services_started=3, |
|
success=True, |
|
startup_time=30.0 |
|
) |
|
print("β
Docker deployment monitoring works") |
|
|
|
|
|
monitor.log_docker_service_health( |
|
service_name="fhirflame-a2a-api", |
|
status="healthy", |
|
response_time=0.5, |
|
healthy=True |
|
) |
|
print("β
Docker service health monitoring works") |
|
|
|
return True |
|
|
|
except Exception as e: |
|
print(f"β Docker monitoring test failed: {e}") |
|
return False |
|
|
|
def main(): |
|
"""Run comprehensive monitoring tests""" |
|
print("π Testing Comprehensive Langfuse Monitoring") |
|
print("=" * 50) |
|
|
|
|
|
os.chdir(os.path.dirname(os.path.dirname(__file__))) |
|
|
|
tests = [ |
|
("Monitoring Imports", test_monitoring_imports), |
|
("Monitoring Methods", test_monitoring_methods), |
|
("Monitoring Functionality", test_monitoring_functionality), |
|
("Docker Monitoring", test_docker_compose_monitoring) |
|
] |
|
|
|
results = {} |
|
|
|
for test_name, test_func in tests: |
|
try: |
|
result = test_func() |
|
results[test_name] = result |
|
except Exception as e: |
|
print(f"β {test_name} crashed: {e}") |
|
results[test_name] = False |
|
|
|
|
|
print("\n" + "=" * 50) |
|
print("π Langfuse Monitoring Test Results") |
|
print("=" * 50) |
|
|
|
passed = sum(1 for r in results.values() if r) |
|
total = len(results) |
|
|
|
for test_name, result in results.items(): |
|
status = "β
PASS" if result else "β FAIL" |
|
print(f"{test_name}: {status}") |
|
|
|
print(f"\nOverall: {passed}/{total} tests passed") |
|
|
|
if passed == total: |
|
print("\nπ Comprehensive Langfuse monitoring implemented successfully!") |
|
print("\nπ Monitoring Coverage:") |
|
print("β’ A2A API requests/responses with authentication tracking") |
|
print("β’ Modal L4 GPU function calls and scaling events") |
|
print("β’ MCP tool execution and server events") |
|
print("β’ Docker deployment and service health") |
|
print("β’ Error events and performance metrics") |
|
print("β’ Medical entity extraction and FHIR validation") |
|
else: |
|
print("\nβ οΈ Some monitoring tests failed.") |
|
|
|
return passed == total |
|
|
|
if __name__ == "__main__": |
|
success = main() |
|
sys.exit(0 if success else 1) |