From 083eb3987d725d8d9da8f6cbb14ab40ae2ef9c12 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 21:27:09 +0000 Subject: [PATCH] Fix import sorting issues for linter Co-Authored-By: Joe Moura --- .../patches/openinference_agent_wrapper.py | 14 ++++++++----- .../test_openinference_agent_wrapper.py | 20 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/crewai/telemetry/patches/openinference_agent_wrapper.py b/src/crewai/telemetry/patches/openinference_agent_wrapper.py index 80a978f69..43f226db8 100644 --- a/src/crewai/telemetry/patches/openinference_agent_wrapper.py +++ b/src/crewai/telemetry/patches/openinference_agent_wrapper.py @@ -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 diff --git a/tests/telemetry/test_openinference_agent_wrapper.py b/tests/telemetry/test_openinference_agent_wrapper.py index ffd699c89..56b190b9b 100644 --- a/tests/telemetry/test_openinference_agent_wrapper.py +++ b/tests/telemetry/test_openinference_agent_wrapper.py @@ -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