@@ -3,6 +3,7 @@ defmodule RealtimeWeb.TenantControllerTest do
33 # Also using global otel_simple_processor
44 use RealtimeWeb.ConnCase , async: false
55
6+ import ExUnit.CaptureLog
67 require OpenTelemetry.Tracer , as: Tracer
78
89 alias Realtime.Api.Tenant
@@ -443,6 +444,51 @@ defmodule RealtimeWeb.TenantControllerTest do
443444
444445 assert attributes ( map: % { external_id: ^ external_id } ) = attributes
445446 end
447+
448+ test "logs request when DISABLE_HEALTHCHECK_LOGGING is false" , % { conn: conn , tenant: tenant } do
449+ original_value = Application . get_env ( :realtime , :disable_healthcheck_logging , false )
450+ Application . put_env ( :realtime , :disable_healthcheck_logging , false )
451+ on_exit ( fn -> Application . put_env ( :realtime , :disable_healthcheck_logging , original_value ) end )
452+
453+ log =
454+ capture_log ( fn ->
455+ conn = get ( conn , ~p" /api/tenants/#{ tenant . external_id } /health" )
456+ assert json_response ( conn , 200 )
457+ end )
458+
459+ assert log =~ "GET /api/tenants"
460+ assert log =~ "/health"
461+ end
462+
463+ test "does not log request when DISABLE_HEALTHCHECK_LOGGING is true" , % { conn: conn , tenant: tenant } do
464+ original_value = Application . get_env ( :realtime , :disable_healthcheck_logging , false )
465+ Application . put_env ( :realtime , :disable_healthcheck_logging , true )
466+ on_exit ( fn -> Application . put_env ( :realtime , :disable_healthcheck_logging , original_value ) end )
467+
468+ log =
469+ capture_log ( fn ->
470+ conn = get ( conn , ~p" /api/tenants/#{ tenant . external_id } /health" )
471+ assert json_response ( conn , 200 )
472+ end )
473+
474+ refute log =~ "GET /api/tenants"
475+ refute log =~ "/health"
476+ end
477+
478+ test "logs request when DISABLE_HEALTHCHECK_LOGGING is not set (default)" , % { conn: conn , tenant: tenant } do
479+ original_value = Application . get_env ( :realtime , :disable_healthcheck_logging , false )
480+ Application . delete_env ( :realtime , :disable_healthcheck_logging )
481+ on_exit ( fn -> Application . put_env ( :realtime , :disable_healthcheck_logging , original_value ) end )
482+
483+ log =
484+ capture_log ( fn ->
485+ conn = get ( conn , ~p" /api/tenants/#{ tenant . external_id } /health" )
486+ assert json_response ( conn , 200 )
487+ end )
488+
489+ assert log =~ "GET /api/tenants"
490+ assert log =~ "/health"
491+ end
446492 end
447493
448494 defp default_tenant_attrs ( port ) do
0 commit comments