diff --git a/5_django_backend/.env.example b/5_django_backend/.env.example index f096df1..889345b 100644 --- a/5_django_backend/.env.example +++ b/5_django_backend/.env.example @@ -67,3 +67,5 @@ ABAP_INDEX_URL=http://127.0.0.1:8100 LANGFUSE_HOST= LANGFUSE_PUBLIC_KEY= LANGFUSE_SECRET_KEY= +# 1 이면 FabriX 호출 원문(프롬프트 전체·응답)도 별도 fabrix 트레이스로. 기본 0 — 질문 하나 = 행 하나 유지 +LANGFUSE_TRACE_GATEWAY=0 diff --git a/5_django_backend/apps/gateway/views.py b/5_django_backend/apps/gateway/views.py index 9da7e05..386d456 100644 --- a/5_django_backend/apps/gateway/views.py +++ b/5_django_backend/apps/gateway/views.py @@ -97,7 +97,7 @@ class _Collect: def _observe(model_id: str, body: dict, col: _Collect, started: float, status: int, *, kinds: list[str]) -> None: - if not langfuse.enabled(): + if not langfuse.enabled() or not settings.LANGFUSE.get("gateway"): return u = col.usage or {} tid = str(uuid.uuid4()) diff --git a/5_django_backend/config/settings.py b/5_django_backend/config/settings.py index 76c0be5..0ee4da5 100644 --- a/5_django_backend/config/settings.py +++ b/5_django_backend/config/settings.py @@ -93,6 +93,8 @@ LANGFUSE = { "host": _env("LANGFUSE_HOST"), "public_key": _env("LANGFUSE_PUBLIC_KEY"), "secret_key": _env("LANGFUSE_SECRET_KEY"), + # 게이트웨이(FabriX 호출 원문) 트레이스는 기본 끔 — 켜면 질문 하나에 행이 2개(chat + fabrix) 잡힘 + "gateway": _env_bool("LANGFUSE_TRACE_GATEWAY", False), } # 세션 컨텍스트 하드 한도 — usage.limit 로 프론트 게이지에 감 CONTEXT_LIMIT_TOKENS = int(_env("CONTEXT_LIMIT_TOKENS", "128000") or "128000") diff --git a/5_django_backend/tests/test_gateway.py b/5_django_backend/tests/test_gateway.py index 737cb24..e2bd98d 100644 --- a/5_django_backend/tests/test_gateway.py +++ b/5_django_backend/tests/test_gateway.py @@ -126,7 +126,7 @@ async def test_401_retries_other_auth_shape_and_remembers(upstream): assert len(calls) == n + 1 and calls[-1].headers["x-openapi-token"] == "Bearer tok" -@override_settings(FABRIX_ENV=FULL_ENV, LANGFUSE={"host": "http://lf.test", "public_key": "pk", "secret_key": "sk"}) +@override_settings(FABRIX_ENV=FULL_ENV, LANGFUSE={"host": "http://lf.test", "public_key": "pk", "secret_key": "sk", "gateway": True}) async def test_stream_reports_generation_to_langfuse(upstream, monkeypatch): import asyncio diff --git a/5_django_backend/tests/test_langfuse.py b/5_django_backend/tests/test_langfuse.py index d522f06..6ebd329 100644 --- a/5_django_backend/tests/test_langfuse.py +++ b/5_django_backend/tests/test_langfuse.py @@ -10,7 +10,7 @@ from django.test import override_settings from apps.gateway import langfuse -LF = {"host": "http://lf.test", "public_key": "pk-lf-a", "secret_key": "sk-lf-b"} +LF = {"host": "http://lf.test", "public_key": "pk-lf-a", "secret_key": "sk-lf-b", "gateway": False} @pytest.fixture