diff --git a/clearwing/observability/otel.py b/clearwing/observability/otel.py index 25895423..65e21cb6 100644 --- a/clearwing/observability/otel.py +++ b/clearwing/observability/otel.py @@ -101,7 +101,7 @@ def _otlp_exporter() -> SpanExporter: ) if api_key := os.environ.get("PHOENIX_API_KEY"): if not standard_headers_configured: - kwargs["headers"] = {"api_key": api_key} + kwargs["headers"] = {"authorization": f"Bearer {api_key}"} return OTLPSpanExporter(**kwargs) return OTLPSpanExporter() diff --git a/clearwing/sourcehunt/runner.py b/clearwing/sourcehunt/runner.py index 38327844..a45361e3 100644 --- a/clearwing/sourcehunt/runner.py +++ b/clearwing/sourcehunt/runner.py @@ -1233,19 +1233,23 @@ def _finalize_spend_ledger(self, status: str | None = None) -> dict[str, Any]: return summary def run(self) -> SourceHuntResult: + from clearwing.observability.otel import force_flush from clearwing.ui.llm_activity import llm_activity_panel self._ensure_spend_ledger() - with llm_activity_panel( - live=self._live, - budget_usd=self.budget_usd or None, - spend_ledger=self._spend_ledger, - trace_context=lambda: ( - getattr(self, "_otel_trace_id", None), - getattr(self, "_otel_span_id", None), - ), - ): - return asyncio.run(self.arun()) + try: + with llm_activity_panel( + live=self._live, + budget_usd=self.budget_usd or None, + spend_ledger=self._spend_ledger, + trace_context=lambda: ( + getattr(self, "_otel_trace_id", None), + getattr(self, "_otel_span_id", None), + ), + ): + return asyncio.run(self.arun()) + finally: + force_flush() async def _arun_proof_flow(self) -> SourceHuntResult: """Run the proof-carrying engine and adapt its typed output.""" diff --git a/tests/test_otel.py b/tests/test_otel.py index 212771f2..86a6c36a 100644 --- a/tests/test_otel.py +++ b/tests/test_otel.py @@ -108,7 +108,7 @@ def test_standard_and_phoenix_environment_detection(monkeypatch): assert otel.telemetry_configured() is False -def test_phoenix_api_key_becomes_otlp_header(monkeypatch): +def test_phoenix_api_key_becomes_bearer_header(monkeypatch): monkeypatch.delenv("OTEL_EXPORTER_OTLP_ENDPOINT", raising=False) monkeypatch.delenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", raising=False) monkeypatch.delenv("OTEL_EXPORTER_OTLP_HEADERS", raising=False) @@ -123,7 +123,7 @@ def test_phoenix_api_key_becomes_otlp_header(monkeypatch): exporter.assert_called_once_with( endpoint="https://phoenix.example/v1/traces", - headers={"api_key": "secret-key"}, + headers={"authorization": "Bearer secret-key"}, )