fix: resolve test failures for telemetry and PDF knowledge source

- Fix telemetry.ready to be False when opentelemetry is unavailable
- Fix PDF knowledge source to delay pdfplumber import check until needed
- Add shutdown method to SafeOTLPSpanExporter to prevent AttributeError
- Verified fixes work locally with test script

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-18 10:23:44 +00:00
parent 5dee1b819b
commit 8e97e6e5f3
2 changed files with 15 additions and 2 deletions

View File

@@ -16,8 +16,9 @@ class PDFKnowledgeSource(BaseFileKnowledgeSource):
def load_content(self) -> Dict[Path, str]:
"""Load and preprocess PDF file content."""
pdfplumber = self._import_pdfplumber()
if not PDFPLUMBER_AVAILABLE:
return {}
content = {}
for path in self.safe_file_paths:
@@ -45,6 +46,8 @@ class PDFKnowledgeSource(BaseFileKnowledgeSource):
Add PDF file content to the knowledge source, chunk it, compute embeddings,
and save the embeddings.
"""
self._import_pdfplumber()
for _, text in self.content.items():
new_chunks = self._chunk_text(text)
self.chunks.extend(new_chunks)

View File

@@ -72,6 +72,15 @@ class SafeOTLPSpanExporter:
except Exception as e:
logger.error(e)
return SpanExportResult.FAILURE if SpanExportResult else None
def shutdown(self):
"""Shutdown the exporter."""
if OPENTELEMETRY_AVAILABLE and self._exporter and hasattr(self._exporter, 'shutdown'):
try:
return self._exporter.shutdown()
except Exception as e:
logger.error(f"Error during exporter shutdown: {e}")
return None
class Telemetry:
@@ -107,6 +116,7 @@ class Telemetry:
self._initialized: bool = True
if self._is_telemetry_disabled() or not OPENTELEMETRY_AVAILABLE:
self.ready = False
return
try: