mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
Fix import sorting issues for linter
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -5,8 +5,8 @@ This patch addresses issue #2366 where OpenTelemetry logs only store
|
||||
input.value field for agent calls but no output.value.
|
||||
"""
|
||||
import importlib
|
||||
import sys
|
||||
import logging
|
||||
import sys
|
||||
from typing import Any, Optional
|
||||
|
||||
# Setup logging
|
||||
@@ -30,9 +30,9 @@ def patch_crewai_instrumentor():
|
||||
try:
|
||||
# Try to import OpenInference
|
||||
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
||||
from wrapt import wrap_function_wrapper
|
||||
from opentelemetry import trace as trace_api
|
||||
from opentelemetry import context as context_api
|
||||
from opentelemetry import trace as trace_api
|
||||
from wrapt import wrap_function_wrapper
|
||||
|
||||
# Define the wrapper class
|
||||
class _AgentExecuteTaskWrapper:
|
||||
@@ -55,7 +55,9 @@ def patch_crewai_instrumentor():
|
||||
|
||||
# Get attributes module if available
|
||||
try:
|
||||
from openinference.instrumentation import get_attributes_from_context
|
||||
from openinference.instrumentation import (
|
||||
get_attributes_from_context,
|
||||
)
|
||||
from openinference.semconv.trace import OpenInferenceSpanKindValues
|
||||
has_attributes = True
|
||||
except ImportError:
|
||||
@@ -104,7 +106,9 @@ def patch_crewai_instrumentor():
|
||||
|
||||
# Add additional attributes if available
|
||||
if has_attributes:
|
||||
from openinference.instrumentation import get_attributes_from_context
|
||||
from openinference.instrumentation import (
|
||||
get_attributes_from_context,
|
||||
)
|
||||
span.set_attributes(dict(get_attributes_from_context()))
|
||||
|
||||
return response
|
||||
|
||||
@@ -3,17 +3,21 @@ Test for the OpenInference Agent wrapper patch.
|
||||
|
||||
This test verifies that our patch is properly applied.
|
||||
"""
|
||||
import pytest
|
||||
import sys
|
||||
import importlib
|
||||
from unittest.mock import patch, MagicMock, call
|
||||
import sys
|
||||
from unittest.mock import MagicMock, call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from crewai import Agent, Task
|
||||
from crewai.utilities.events import AgentExecutionCompletedEvent
|
||||
|
||||
|
||||
def test_patch_function_exists():
|
||||
"""Test that the patch function exists and is callable."""
|
||||
from crewai.telemetry.patches.openinference_agent_wrapper import patch_crewai_instrumentor
|
||||
from crewai.telemetry.patches.openinference_agent_wrapper import (
|
||||
patch_crewai_instrumentor,
|
||||
)
|
||||
|
||||
# Verify the patch function exists
|
||||
assert callable(patch_crewai_instrumentor)
|
||||
@@ -22,7 +26,9 @@ def test_patch_function_exists():
|
||||
def test_patch_handles_missing_openinference():
|
||||
"""Test that the patch function handles missing OpenInference gracefully."""
|
||||
# Import the patch module
|
||||
from crewai.telemetry.patches.openinference_agent_wrapper import patch_crewai_instrumentor
|
||||
from crewai.telemetry.patches.openinference_agent_wrapper import (
|
||||
patch_crewai_instrumentor,
|
||||
)
|
||||
|
||||
# Mock sys.modules to simulate OpenInference not being installed
|
||||
original_modules = sys.modules.copy()
|
||||
@@ -57,7 +63,9 @@ def test_agent_execute_task_emits_event():
|
||||
# 4. Verify that the span has both input.value and output.value attributes
|
||||
|
||||
# For now, we'll just verify that our patch exists and is callable
|
||||
from crewai.telemetry.patches.openinference_agent_wrapper import patch_crewai_instrumentor
|
||||
from crewai.telemetry.patches.openinference_agent_wrapper import (
|
||||
patch_crewai_instrumentor,
|
||||
)
|
||||
assert callable(patch_crewai_instrumentor)
|
||||
|
||||
# And that the patch handles missing OpenInference gracefully
|
||||
|
||||
Reference in New Issue
Block a user