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

View File

@@ -73,6 +73,15 @@ class SafeOTLPSpanExporter:
logger.error(e) logger.error(e)
return SpanExportResult.FAILURE if SpanExportResult else None 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: class Telemetry:
"""A class to handle anonymous telemetry for the crewai package. """A class to handle anonymous telemetry for the crewai package.
@@ -107,6 +116,7 @@ class Telemetry:
self._initialized: bool = True self._initialized: bool = True
if self._is_telemetry_disabled() or not OPENTELEMETRY_AVAILABLE: if self._is_telemetry_disabled() or not OPENTELEMETRY_AVAILABLE:
self.ready = False
return return
try: try: