diff --git a/hindsight-api/hindsight_api/engine/providers/claude_code_llm.py b/hindsight-api/hindsight_api/engine/providers/claude_code_llm.py index 86b1a08f..2eaa8f2b 100644 --- a/hindsight-api/hindsight_api/engine/providers/claude_code_llm.py +++ b/hindsight-api/hindsight_api/engine/providers/claude_code_llm.py @@ -238,21 +238,24 @@ class ClaudeCodeLLM(LLMInterface): ) # Record trace span - from hindsight_api.tracing import get_span_recorder + try: + from hindsight_api.tracing import get_span_recorder - span_recorder = get_span_recorder() - span_recorder.record_llm_call( - provider=self.provider, - model=self.model, - scope=scope, - messages=messages, - response_content=result if isinstance(result, str) else json.dumps(result), - input_tokens=estimated_input, - output_tokens=estimated_output, - duration=duration, - finish_reason=None, - error=None, - ) + span_recorder = get_span_recorder() + span_recorder.record_llm_call( + provider=self.provider, + model=self.model, + scope=scope, + messages=messages, + response_content=result if isinstance(result, str) else result.model_dump_json(), + input_tokens=estimated_input, + output_tokens=estimated_output, + duration=duration, + finish_reason=None, + error=None, + ) + except Exception: + pass # logging failure must never affect the operation # Log slow calls if duration > 10.0: diff --git a/hindsight-api/tests/test_llm_provider.py b/hindsight-api/tests/test_llm_provider.py index fbf2c108..491cc00b 100644 --- a/hindsight-api/tests/test_llm_provider.py +++ b/hindsight-api/tests/test_llm_provider.py @@ -332,8 +332,8 @@ async def test_llm_provider_consolidation(memory_no_llm_verify, request_context, test_bank_id = f"llm_test_consolidation_{provider}_{model}_{datetime.now().timestamp()}" # Enable observations for this bank - from hindsight_api.config import get_config - config = get_config() + from hindsight_api.config import _get_raw_config + config = _get_raw_config() original_value = config.enable_observations config.enable_observations = True